Fixed a big stupid bug that can cause lots of trouble: all locks created
weren't moved to the kernel (as owner), so they would be deleted after the team which almost randomly created them died. Benaphores are now only used if USE_BENAPHORES is defined - I have renamed the Benaphore class to Semaphore to take the changed behaviour into account. Added a Status() method to the Locker class. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1885 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
ce088d7b5c
commit
dab62fa391
@ -47,7 +47,7 @@ class BlockAllocator {
|
||||
static status_t initialize(BlockAllocator *);
|
||||
|
||||
Volume *fVolume;
|
||||
Benaphore fLock;
|
||||
Semaphore fLock;
|
||||
AllocationGroup *fGroups;
|
||||
int32 fNumGroups, fBlocksPerGroup;
|
||||
uint32 *fCheckBitmap;
|
||||
|
@ -20,6 +20,11 @@ BufferPool::BufferPool()
|
||||
{
|
||||
fLock = create_sem(1, "buffer lock");
|
||||
fFreeBuffers = create_sem(0, "free buffers");
|
||||
|
||||
#ifndef USER
|
||||
set_sem_owner(fLock, B_SYSTEM_TEAM);
|
||||
set_sem_owner(fFreeBuffers, B_SYSTEM_TEAM);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
@ -69,7 +69,7 @@ class Journal {
|
||||
status_t TransactionDone(bool success);
|
||||
|
||||
Volume *fVolume;
|
||||
Benaphore fLock;
|
||||
Semaphore fLock;
|
||||
Transaction *fOwner;
|
||||
thread_id fOwningThread;
|
||||
BlockArray fArray;
|
||||
|
@ -1,6 +1,6 @@
|
||||
#ifndef LOCK_H
|
||||
#define LOCK_H
|
||||
/* Lock - benaphores, read/write lock implementation
|
||||
/* Lock - simple semaphores, read/write lock implementation
|
||||
**
|
||||
** Initial version by Axel Dörfler, axeld@pinc-software.de
|
||||
** Roughly based on a Be sample code written by Nathan Schrenk.
|
||||
@ -12,16 +12,27 @@
|
||||
#include <KernelExport.h>
|
||||
|
||||
|
||||
class Benaphore {
|
||||
// configure here if and when real benaphores should be used
|
||||
#ifdef USER
|
||||
# define USE_BENAPHORE 1
|
||||
#endif
|
||||
|
||||
|
||||
class Semaphore {
|
||||
public:
|
||||
Benaphore(const char *name = "bfs benaphore")
|
||||
Semaphore(const char *name = "bfs sem")
|
||||
:
|
||||
fSemaphore(create_sem(0, name)),
|
||||
fCount(1)
|
||||
fSemaphore(create_sem(0, name))
|
||||
#ifdef USE_BENAPHORE
|
||||
, fCount(1)
|
||||
#endif
|
||||
{
|
||||
#ifndef USER
|
||||
set_sem_owner(fSemaphore, B_SYSTEM_TEAM);
|
||||
#endif
|
||||
}
|
||||
|
||||
~Benaphore()
|
||||
~Semaphore()
|
||||
{
|
||||
delete_sem(fSemaphore);
|
||||
}
|
||||
@ -36,28 +47,38 @@ class Benaphore {
|
||||
|
||||
status_t Lock()
|
||||
{
|
||||
#ifdef USE_BENAPHORE
|
||||
if (atomic_add(&fCount, -1) <= 0)
|
||||
#endif
|
||||
return acquire_sem(fSemaphore);
|
||||
|
||||
#ifdef USE_BENAPHORE
|
||||
return B_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
void Unlock()
|
||||
status_t Unlock()
|
||||
{
|
||||
#ifdef USE_BENAPHORE
|
||||
if (atomic_add(&fCount, 1) < 0)
|
||||
release_sem(fSemaphore);
|
||||
#endif
|
||||
return release_sem(fSemaphore);
|
||||
#ifdef USE_BENAPHORE
|
||||
return B_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
private:
|
||||
sem_id fSemaphore;
|
||||
#ifdef USE_BENAPHORE
|
||||
vint32 fCount;
|
||||
#endif
|
||||
};
|
||||
|
||||
// a convenience class to lock the benaphore
|
||||
|
||||
class Locker {
|
||||
public:
|
||||
Locker(Benaphore &lock)
|
||||
Locker(Semaphore &lock)
|
||||
: fLock(lock)
|
||||
{
|
||||
fStatus = lock.Lock();
|
||||
@ -68,9 +89,14 @@ class Locker {
|
||||
if (fStatus == B_OK)
|
||||
fLock.Unlock();
|
||||
}
|
||||
|
||||
|
||||
status_t Status() const
|
||||
{
|
||||
return fStatus;
|
||||
}
|
||||
|
||||
private:
|
||||
Benaphore &fLock;
|
||||
Semaphore &fLock;
|
||||
status_t fStatus;
|
||||
};
|
||||
|
||||
@ -118,6 +144,9 @@ class ReadWriteLock {
|
||||
fCount(MAX_READERS),
|
||||
fWriteLock()
|
||||
{
|
||||
#ifndef USER
|
||||
set_sem_owner(fSemaphore, B_SYSTEM_TEAM);
|
||||
#endif
|
||||
}
|
||||
|
||||
~ReadWriteLock()
|
||||
@ -181,7 +210,7 @@ class ReadWriteLock {
|
||||
|
||||
sem_id fSemaphore;
|
||||
vint32 fCount;
|
||||
Benaphore fWriteLock;
|
||||
Semaphore fWriteLock;
|
||||
};
|
||||
#else // FAST_LOCK
|
||||
class ReadWriteLock {
|
||||
@ -190,6 +219,9 @@ class ReadWriteLock {
|
||||
:
|
||||
fSemaphore(create_sem(MAX_READERS, name))
|
||||
{
|
||||
#ifndef USER
|
||||
set_sem_owner(fSemaphore, B_SYSTEM_TEAM);
|
||||
#endif
|
||||
}
|
||||
|
||||
~ReadWriteLock()
|
||||
|
@ -43,7 +43,7 @@ class Volume {
|
||||
bool IsValidSuperBlock();
|
||||
bool IsReadOnly() const;
|
||||
void Panic();
|
||||
Benaphore &Lock();
|
||||
Semaphore &Lock();
|
||||
|
||||
block_run Root() const { return fSuperBlock.root_dir; }
|
||||
Inode *RootNode() const { return fRootNode; }
|
||||
@ -114,7 +114,7 @@ class Volume {
|
||||
int fDevice;
|
||||
disk_super_block fSuperBlock;
|
||||
BlockAllocator fBlockAllocator;
|
||||
Benaphore fLock;
|
||||
Semaphore fLock;
|
||||
Journal *fJournal;
|
||||
vint32 fLogStart, fLogEnd;
|
||||
|
||||
@ -142,7 +142,7 @@ Volume::IsReadOnly() const
|
||||
}
|
||||
|
||||
|
||||
inline Benaphore &
|
||||
inline Semaphore &
|
||||
Volume::Lock()
|
||||
{
|
||||
return fLock;
|
||||
|
Loading…
x
Reference in New Issue
Block a user