While the AutoLocker is not public at least make BAutolock a bit more useful by

also providing Lock() and Unlock(). Applied public header style.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33367 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Michael Lotz 2009-09-30 01:00:23 +00:00
parent 290c903985
commit ace6934d79

View File

@ -1,5 +1,5 @@
/*
* Copyright 2001-2007, Haiku, Inc. All Rights Reserved.
* Copyright 2001-2009, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _SUPPORT_AUTOLOCK_H
@ -11,38 +11,50 @@
class BAutolock {
public:
inline BAutolock(BLooper *looper);
inline BAutolock(BLocker *locker);
inline BAutolock(BLocker &locker);
inline ~BAutolock();
public:
inline BAutolock(BLooper* looper);
inline BAutolock(BLocker* locker);
inline BAutolock(BLocker& locker);
inline ~BAutolock();
inline bool IsLocked(void);
inline bool IsLocked();
private:
BLocker *fLocker;
BLooper *fLooper;
bool fIsLocked;
inline bool Lock();
inline void Unlock();
private:
BLocker* fLocker;
BLooper* fLooper;
bool fIsLocked;
};
inline
BAutolock::BAutolock(BLooper *looper)
: fLocker(NULL), fLooper(looper), fIsLocked(looper->Lock())
:
fLocker(NULL),
fLooper(looper),
fIsLocked(looper->Lock())
{
}
inline
BAutolock::BAutolock(BLocker *locker)
: fLocker(locker), fLooper(NULL), fIsLocked(locker->Lock())
:
fLocker(locker),
fLooper(NULL),
fIsLocked(locker->Lock())
{
}
inline
BAutolock::BAutolock(BLocker &locker)
: fLocker(&locker), fLooper(NULL), fIsLocked(locker.Lock())
:
fLocker(&locker),
fLooper(NULL),
fIsLocked(locker.Lock())
{
}
@ -50,12 +62,7 @@ BAutolock::BAutolock(BLocker &locker)
inline
BAutolock::~BAutolock()
{
if (fIsLocked) {
if (fLooper != NULL)
fLooper->Unlock();
else
fLocker->Unlock();
}
Unlock();
}
@ -65,4 +72,33 @@ BAutolock::IsLocked()
return fIsLocked;
}
inline bool
BAutolock::Lock()
{
if (fIsLocked)
return true;
if (fLooper != NULL)
fIsLocked = fLooper->Lock();
else
fIsLocked = fLocker->Lock();
return fIsLocked;
}
inline void
BAutolock::Unlock()
{
if (!fIsLocked)
return;
fIsLocked = false;
if (fLooper != NULL)
fLooper->Unlock();
else
fLocker->Unlock();
}
#endif // _SUPPORT_AUTOLOCK_H