1 // gold-threads.h -- thread support for gold -*- C++ -*-
3 // Copyright 2006, 2007, 2008 Free Software Foundation, Inc.
4 // Written by Ian Lance Taylor <iant@google.com>.
6 // This file is part of gold.
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.
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.
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.
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
29 // A simple lock class.
31 #ifndef GOLD_THREADS_H
32 #define GOLD_THREADS_H
39 // The interface for the implementation of a Lock.
58 // A simple lock class.
70 { this->lock_->acquire(); }
75 { this->lock_->release(); }
78 // This class can not be copied.
80 Lock& operator=(const Lock&);
85 { return this->lock_; }
97 { this->lock_.acquire(); }
100 { this->lock_.release(); }
103 // This class can not be copied.
104 Hold_lock(const Hold_lock&);
105 Hold_lock& operator=(const Hold_lock&);
110 class Hold_optional_lock
113 Hold_optional_lock(Lock* lock)
116 if (this->lock_ != NULL)
117 this->lock_->acquire();
120 ~Hold_optional_lock()
122 if (this->lock_ != NULL)
123 this->lock_->release();
127 Hold_optional_lock(const Hold_optional_lock&);
128 Hold_optional_lock& operator=(const Hold_optional_lock&);
133 // The interface for the implementation of a condition variable.
146 wait(Lock_impl*) = 0;
155 // A simple condition variable class. It is always associated with a
164 // Wait for the condition variable to be signalled. This should
165 // only be called when the lock is held.
168 { this->condvar_->wait(this->lock_.get_impl()); }
170 // Signal the condition variable--wake up at least one thread
171 // waiting on the condition variable. This should only be called
172 // when the lock is held.
175 { this->condvar_->signal(); }
177 // Broadcast the condition variable--wake up all threads waiting on
178 // the condition variable. This should only be called when the lock
182 { this->condvar_->broadcast(); }
185 // This class can not be copied.
186 Condvar(const Condvar&);
187 Condvar& operator=(const Condvar&);
190 Condvar_impl* condvar_;
193 } // End namespace gold.
195 #endif // !defined(GOLD_THREADS_H)