*** empty log message ***
[deliverable/binutils-gdb.git] / gold / gold-threads.h
CommitLineData
bae7f79e
ILT
1// gold-threads.h -- thread support for gold -*- C++ -*-
2
6cb15b7f
ILT
3// Copyright 2006, 2007 Free Software Foundation, Inc.
4// Written by Ian Lance Taylor <iant@google.com>.
5
6// This file is part of gold.
7
8// This program is free software; you can redistribute it and/or modify
9// it under the terms of the GNU General Public License as published by
10// the Free Software Foundation; either version 3 of the License, or
11// (at your option) any later version.
12
13// This program is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16// GNU General Public License for more details.
17
18// You should have received a copy of the GNU General Public License
19// along with this program; if not, write to the Free Software
20// Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21// MA 02110-1301, USA.
22
bae7f79e
ILT
23// gold can be configured to support threads. If threads are
24// supported, the user can specify at runtime whether or not to
25// support them. This provides an interface to manage locking
26// accordingly.
27
28// Lock
29// A simple lock class.
30
31#ifndef GOLD_THREADS_H
32#define GOLD_THREADS_H
33
34namespace gold
35{
36
37class Lock_impl;
38class Condvar;
39
40// A simple lock class.
41
42class Lock
43{
44 public:
45 Lock();
46 ~Lock();
47
48 // Acquire the lock.
49 void
50 acquire();
51
52 // Release the lock.
53 void
54 release();
55
56 private:
57 // This class can not be copied.
58 Lock(const Lock&);
59 Lock& operator=(const Lock&);
60
61 friend class Condvar;
62 Lock_impl*
63 get_impl() const
64 { return this->lock_; }
65
66 Lock_impl* lock_;
67};
68
69// RAII for Lock.
70
71class Hold_lock
72{
73 public:
74 Hold_lock(Lock& lock)
75 : lock_(lock)
76 { this->lock_.acquire(); }
77
78 ~Hold_lock()
79 { this->lock_.release(); }
80
81 private:
82 // This class can not be copied.
83 Hold_lock(const Hold_lock&);
84 Hold_lock& operator=(const Hold_lock&);
85
86 Lock& lock_;
87};
88
89class Condvar_impl;
90
91// A simple condition variable class. It is always associated with a
92// specific lock.
93
94class Condvar
95{
96 public:
97 Condvar(Lock& lock);
98 ~Condvar();
99
100 // Wait for the condition variable to be signalled. This should
101 // only be called when the lock is held.
102 void
103 wait();
104
105 // Signal the condition variable. This should only be called when
106 // the lock is held.
107 void
108 signal();
109
110 private:
111 // This class can not be copied.
112 Condvar(const Condvar&);
113 Condvar& operator=(const Condvar&);
114
115 Lock& lock_;
116 Condvar_impl* condvar_;
117};
118
119} // End namespace gold.
120
121#endif // !defined(GOLD_THREADS_H)
This page took 0.072161 seconds and 4 git commands to generate.