Initial CVS checkin of gold
[deliverable/binutils-gdb.git] / gold / gold-threads.h
CommitLineData
bae7f79e
ILT
1// gold-threads.h -- thread support for gold -*- C++ -*-
2
3// gold can be configured to support threads. If threads are
4// supported, the user can specify at runtime whether or not to
5// support them. This provides an interface to manage locking
6// accordingly.
7
8// Lock
9// A simple lock class.
10
11#ifndef GOLD_THREADS_H
12#define GOLD_THREADS_H
13
14namespace gold
15{
16
17class Lock_impl;
18class Condvar;
19
20// A simple lock class.
21
22class Lock
23{
24 public:
25 Lock();
26 ~Lock();
27
28 // Acquire the lock.
29 void
30 acquire();
31
32 // Release the lock.
33 void
34 release();
35
36 private:
37 // This class can not be copied.
38 Lock(const Lock&);
39 Lock& operator=(const Lock&);
40
41 friend class Condvar;
42 Lock_impl*
43 get_impl() const
44 { return this->lock_; }
45
46 Lock_impl* lock_;
47};
48
49// RAII for Lock.
50
51class Hold_lock
52{
53 public:
54 Hold_lock(Lock& lock)
55 : lock_(lock)
56 { this->lock_.acquire(); }
57
58 ~Hold_lock()
59 { this->lock_.release(); }
60
61 private:
62 // This class can not be copied.
63 Hold_lock(const Hold_lock&);
64 Hold_lock& operator=(const Hold_lock&);
65
66 Lock& lock_;
67};
68
69class Condvar_impl;
70
71// A simple condition variable class. It is always associated with a
72// specific lock.
73
74class Condvar
75{
76 public:
77 Condvar(Lock& lock);
78 ~Condvar();
79
80 // Wait for the condition variable to be signalled. This should
81 // only be called when the lock is held.
82 void
83 wait();
84
85 // Signal the condition variable. This should only be called when
86 // the lock is held.
87 void
88 signal();
89
90 private:
91 // This class can not be copied.
92 Condvar(const Condvar&);
93 Condvar& operator=(const Condvar&);
94
95 Lock& lock_;
96 Condvar_impl* condvar_;
97};
98
99} // End namespace gold.
100
101#endif // !defined(GOLD_THREADS_H)
This page took 0.02729 seconds and 4 git commands to generate.