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:
@@ -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++;
|
||||||
|
|||||||
Reference in New Issue
Block a user