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