* Added bool to the AutoLocker constructor indicating that the object
has already been locked. Defaults to false, of course. * `Abused' the AutoLocker for partition registration/unregistration (PartitionRegistrar). git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3631 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
966528dcbc
commit
b8777f30dc
@ -88,18 +88,20 @@ class AutoLocker {
|
||||
private:
|
||||
typedef AutoLocker<Lockable, Locking> ThisClass;
|
||||
public:
|
||||
inline AutoLocker(Lockable *lockable)
|
||||
inline AutoLocker(Lockable *lockable, bool alreadyLocked = false)
|
||||
: fLockable(lockable),
|
||||
fLocked(false)
|
||||
fLocked(fLockable && alreadyLocked)
|
||||
{
|
||||
_Lock();
|
||||
if (!fLocked)
|
||||
_Lock();
|
||||
}
|
||||
|
||||
inline AutoLocker(Lockable &lockable)
|
||||
inline AutoLocker(Lockable &lockable, bool alreadyLocked = false)
|
||||
: fLockable(&lockable),
|
||||
fLocked(false)
|
||||
fLocked(fLockable && alreadyLocked)
|
||||
{
|
||||
_Lock();
|
||||
if (!fLocked)
|
||||
_Lock();
|
||||
}
|
||||
|
||||
inline ~AutoLocker()
|
||||
@ -149,6 +151,7 @@ private:
|
||||
// instantiations
|
||||
class KDiskDevice;
|
||||
class KDiskDeviceManager;
|
||||
class KPartition;
|
||||
|
||||
typedef AutoLocker<KDiskDevice, AutoLockerReadLocking<KDiskDevice> >
|
||||
DeviceReadLocker;
|
||||
@ -156,6 +159,25 @@ typedef AutoLocker<KDiskDevice, AutoLockerWriteLocking<KDiskDevice> >
|
||||
DeviceWriteLocker;
|
||||
typedef AutoLocker<KDiskDeviceManager > ManagerLocker;
|
||||
|
||||
// AutoLockerPartitionRegistration
|
||||
template<const int dummy = 0>
|
||||
class AutoLockerPartitionRegistration {
|
||||
public:
|
||||
inline bool Lock(KPartition *partition)
|
||||
{
|
||||
partition->Register();
|
||||
return true;
|
||||
}
|
||||
|
||||
inline void Unlock(KPartition *partition)
|
||||
{
|
||||
partition->Unregister();
|
||||
}
|
||||
};
|
||||
|
||||
typedef AutoLocker<KPartition, AutoLockerPartitionRegistration<> >
|
||||
PartitionRegistrar;
|
||||
|
||||
} // namespace DiskDevice
|
||||
} // namespace BPrivate
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user