2 Copyright (C) 2009 Red Hat, Inc.
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, see <http://www.gnu.org/licenses/>.
22 #include "atomic_count.h"
26 typedef void* (*thread_main_t)(void*);
28 Thread(thread_main_t thread_main, void* opaque);
47 pthread_mutex_t* get() {return &_mutex;}
50 pthread_mutex_t _mutex;
59 pthread_mutex_lock(_mutex.get());
62 Lock(Mutex& mutex, uint64_t timout_nano)
65 if (!pthread_mutex_trylock(_mutex.get())) {
69 timed_lock(timout_nano);
80 pthread_mutex_unlock(_mutex.get());
85 bool is_locked() { return _locked;}
88 friend class Condition;
89 pthread_mutex_t* get() {return _mutex.get();}
90 void timed_lock(uint64_t timout_nano);
97 class RecurciveMutex: public Mutex {
99 RecurciveMutex() : Mutex(Mutex::RECURSIVE) {}
102 typedef Lock RecurciveLock;
109 pthread_cond_destroy(&_condition);
114 pthread_cond_signal(&_condition);
119 pthread_cond_broadcast(&_condition);
122 void wait(Lock& lock)
124 pthread_cond_wait(&_condition, lock.get());
127 bool timed_wait(Lock& lock, uint64_t nano);
130 pthread_cond_t _condition;