00001 /****************************************************************************** 00002 / 00003 / File: Autolock.h 00004 / 00005 / Description: BAutolock is a stack-based locking mechanism. 00006 / 00007 / Copyright 1993-98, Be Incorporated 00008 / 00009 ******************************************************************************/ 00010 00011 #ifndef _SUPPORT_AUTOLOCK_H 00012 #define _SUPPORT_AUTOLOCK_H 00013 00014 #include <BeBuild.h> 00015 #include <Locker.h> 00016 #include <Looper.h> 00017 00018 namespace B { 00019 namespace Support { 00020 00021 /*-----------------------------------------------------------------*/ 00022 /*----- BAutolock class -------------------------------------------*/ 00023 00024 class BAutolock { 00025 public: 00026 BAutolock(const lock_status_t& status); 00027 ~BAutolock(); 00028 00029 // Deprecated constructors. 00030 BAutolock(BLocker *lock); 00031 BAutolock(BLocker &lock); 00032 BAutolock(BLooper *looper); 00033 00034 bool IsLocked(); 00035 00036 /*----- Private or reserved ---------------*/ 00037 private: 00038 lock_status_t fStatus; 00039 bool _reserved; 00040 }; 00041 00042 /*-------------------------------------------------------------*/ 00043 /*----- inline implementations --------------------------------*/ 00044 00045 inline BAutolock::BAutolock(const lock_status_t& status) 00046 : fStatus(status), _reserved(false) 00047 { 00048 } 00049 00050 inline BAutolock::BAutolock(BLooper *looper) 00051 : fStatus(looper->LockWithStatus()), _reserved(false) 00052 { 00053 } 00054 00055 inline BAutolock::BAutolock(BLocker *target) 00056 : fStatus(target->LockWithStatus()), _reserved(false) 00057 { 00058 } 00059 00060 inline BAutolock::BAutolock(BLocker &target) 00061 : fStatus(target.LockWithStatus()), _reserved(false) 00062 { 00063 } 00064 00065 inline BAutolock::~BAutolock() 00066 { 00067 fStatus.unlock(); 00068 } 00069 00070 inline bool BAutolock::IsLocked() 00071 { 00072 return fStatus.is_locked(); 00073 } 00074 00075 /*-------------------------------------------------------------*/ 00076 /*-------------------------------------------------------------*/ 00077 00078 } } // namespace B::Support 00079 00080 #endif /* _SUPPORT_AUTOLOCK_H */