1*1e8a3588SAugustin Cavalier /* 2*1e8a3588SAugustin Cavalier * Copyright 2001-2010 Haiku, Inc. All rights reserved. 3*1e8a3588SAugustin Cavalier * Distributed under the terms of the MIT License. 4*1e8a3588SAugustin Cavalier */ 5*1e8a3588SAugustin Cavalier #ifndef _LOCKER_H 6*1e8a3588SAugustin Cavalier #define _LOCKER_H 7*1e8a3588SAugustin Cavalier 8*1e8a3588SAugustin Cavalier 9*1e8a3588SAugustin Cavalier #include <OS.h> 10*1e8a3588SAugustin Cavalier 11*1e8a3588SAugustin Cavalier 12*1e8a3588SAugustin Cavalier class BLocker { 13*1e8a3588SAugustin Cavalier public: 14*1e8a3588SAugustin Cavalier BLocker(); 15*1e8a3588SAugustin Cavalier BLocker(const char* name); 16*1e8a3588SAugustin Cavalier BLocker(bool benaphoreStyle); 17*1e8a3588SAugustin Cavalier BLocker(const char* name, bool benaphoreStyle); 18*1e8a3588SAugustin Cavalier virtual ~BLocker(); 19*1e8a3588SAugustin Cavalier 20*1e8a3588SAugustin Cavalier status_t InitCheck() const; 21*1e8a3588SAugustin Cavalier 22*1e8a3588SAugustin Cavalier bool Lock(); 23*1e8a3588SAugustin Cavalier status_t LockWithTimeout(bigtime_t timeout); 24*1e8a3588SAugustin Cavalier void Unlock(); 25*1e8a3588SAugustin Cavalier 26*1e8a3588SAugustin Cavalier thread_id LockingThread() const; 27*1e8a3588SAugustin Cavalier bool IsLocked() const; 28*1e8a3588SAugustin Cavalier int32 CountLocks() const; 29*1e8a3588SAugustin Cavalier int32 CountLockRequests() const; 30*1e8a3588SAugustin Cavalier sem_id Sem() const; 31*1e8a3588SAugustin Cavalier 32*1e8a3588SAugustin Cavalier private: 33*1e8a3588SAugustin Cavalier BLocker(const char* name, bool benaphoreStyle, 34*1e8a3588SAugustin Cavalier bool _ignored); 35*1e8a3588SAugustin Cavalier BLocker(const BLocker&); 36*1e8a3588SAugustin Cavalier BLocker& operator=(const BLocker&); 37*1e8a3588SAugustin Cavalier void InitLocker(const char* name, 38*1e8a3588SAugustin Cavalier bool benaphoreStyle); 39*1e8a3588SAugustin Cavalier bool AcquireLock(bigtime_t timeout, status_t* error); 40*1e8a3588SAugustin Cavalier 41*1e8a3588SAugustin Cavalier int32 fBenaphoreCount; 42*1e8a3588SAugustin Cavalier sem_id fSemaphoreID; 43*1e8a3588SAugustin Cavalier thread_id fLockOwner; 44*1e8a3588SAugustin Cavalier int32 fRecursiveCount; 45*1e8a3588SAugustin Cavalier 46*1e8a3588SAugustin Cavalier int32 _reserved[4]; 47*1e8a3588SAugustin Cavalier }; 48*1e8a3588SAugustin Cavalier 49*1e8a3588SAugustin Cavalier 50*1e8a3588SAugustin Cavalier #endif // _LOCKER_H 51