087882c26e
feel free to change that ;-) * Cleaned up existing headers. * Coding style guide update to BBufferIO (renamed m_* members to f*). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19972 a95241bf-73f2-0310-859d-f6bbb57e9c96
69 lines
1.0 KiB
C++
69 lines
1.0 KiB
C++
/*
|
|
* Copyright 2001-2007, Haiku, Inc. All Rights Reserved.
|
|
* Distributed under the terms of the MIT License.
|
|
*/
|
|
#ifndef _SUPPORT_AUTOLOCK_H
|
|
#define _SUPPORT_AUTOLOCK_H
|
|
|
|
|
|
#include <Locker.h>
|
|
#include <Looper.h>
|
|
|
|
|
|
class BAutolock {
|
|
public:
|
|
inline BAutolock(BLooper *looper);
|
|
inline BAutolock(BLocker *locker);
|
|
inline BAutolock(BLocker &locker);
|
|
inline ~BAutolock();
|
|
|
|
inline bool IsLocked(void);
|
|
|
|
private:
|
|
BLocker *fLocker;
|
|
BLooper *fLooper;
|
|
bool fIsLocked;
|
|
};
|
|
|
|
|
|
inline
|
|
BAutolock::BAutolock(BLooper *looper)
|
|
: fLocker(NULL), fLooper(looper), fIsLocked(looper->Lock())
|
|
{
|
|
}
|
|
|
|
|
|
inline
|
|
BAutolock::BAutolock(BLocker *locker)
|
|
: fLocker(locker), fLooper(NULL), fIsLocked(locker->Lock())
|
|
{
|
|
}
|
|
|
|
|
|
inline
|
|
BAutolock::BAutolock(BLocker &locker)
|
|
: fLocker(&locker), fLooper(NULL), fIsLocked(locker.Lock())
|
|
{
|
|
}
|
|
|
|
|
|
inline
|
|
BAutolock::~BAutolock()
|
|
{
|
|
if (fIsLocked) {
|
|
if (fLooper != NULL)
|
|
fLooper->Unlock();
|
|
else
|
|
fLocker->Unlock();
|
|
}
|
|
}
|
|
|
|
|
|
inline bool
|
|
BAutolock::IsLocked()
|
|
{
|
|
return fIsLocked;
|
|
}
|
|
|
|
#endif // _SUPPORT_AUTOLOCK_H
|