Fixed an initialization problem of the ReadWriteLock pointed out by geist, also added a comment on how the ownership is used when doing read locking. Thanks!

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21314 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2007-06-03 21:52:11 +00:00
parent 4fc538a920
commit 564c60d830
+12 -3
View File
@@ -1,12 +1,15 @@
/* Lock - simple semaphores, read/write lock implementation /*
* Roughly based on a Be sample code written by Nathan Schrenk.
* *
* Copyright 2001-2006, Axel Dörfler, [email protected]. * Copyright 2001-2007, Axel Dörfler, [email protected].
* This file may be used under the terms of the MIT License. * This file may be used under the terms of the MIT License.
*/ */
#ifndef LOCK_H #ifndef LOCK_H
#define LOCK_H #define LOCK_H
/*! Simple semaphores, read/write lock implementation
Roughly based on a Be sample code written by Nathan Schrenk.
*/
#include "system_dependencies.h" #include "system_dependencies.h"
#include "Utility.h" #include "Utility.h"
@@ -333,11 +336,16 @@ class ReadWriteLock {
class ReadWriteLock { class ReadWriteLock {
public: public:
ReadWriteLock(const char *name) ReadWriteLock(const char *name)
:
fOwner(-1)
{ {
Initialize(name); Initialize(name);
} }
ReadWriteLock() ReadWriteLock()
:
fSemaphore(-1),
fOwner(-1)
{ {
} }
@@ -362,6 +370,7 @@ class ReadWriteLock {
status_t Lock() status_t Lock()
{ {
// This allows nested locking when holding a write lock
thread_id currentThread = find_thread(NULL); thread_id currentThread = find_thread(NULL);
if (currentThread == fOwner) { if (currentThread == fOwner) {
fOwnerCount++; fOwnerCount++;