hrev51310 adds 1 changeset to branch 'master'
old head: b34aa933ed8963354d98a4e96c7b2faad5ca6e88
new head: 6c9e01265b8fe7f392ee55ff51b3bdc1c09b5b9b
overview:
http://cgit.haiku-os.org/haiku/log/?qt=range&q=6c9e01265b8f+%5Eb34aa933ed89
----------------------------------------------------------------------------
6c9e01265b8f: pthread_rwlock: use a mutex for process-private locks.
* instead of a benaphore.
* define PTHREAD_RWLOCK_INITIALIZER.
* adjust Init(), Destroy(), StructureLock() and StructureUnlock().
[ Jérôme Duval <jerome.duval@xxxxxxxxx> ]
----------------------------------------------------------------------------
Revision: hrev51310
Commit: 6c9e01265b8fe7f392ee55ff51b3bdc1c09b5b9b
URL: http://cgit.haiku-os.org/haiku/commit/?id=6c9e01265b8f
Author: Jérôme Duval <jerome.duval@xxxxxxxxx>
Date: Mon Jul 24 19:09:55 2017 UTC
----------------------------------------------------------------------------
3 files changed, 34 insertions(+), 18 deletions(-)
headers/posix/pthread.h | 2 +
headers/posix/sys/types.h | 10 ++---
.../libroot/posix/pthread/pthread_rwlock.cpp | 40 +++++++++++++-------
----------------------------------------------------------------------------
diff --git a/headers/posix/pthread.h b/headers/posix/pthread.h
index 489aace..feaf8e3 100644
--- a/headers/posix/pthread.h
+++ b/headers/posix/pthread.h
@@ -80,6 +80,8 @@ extern "C" {
{ PTHREAD_MUTEX_RECURSIVE, 0, -42, -1, 0 }
#define PTHREAD_COND_INITIALIZER \
{ 0, -42, NULL, 0, 0 }
+#define PTHREAD_RWLOCK_INITIALIZER \
+ { 0, -1, {{0}} }
/* mutex functions */
extern int pthread_mutex_destroy(pthread_mutex_t *mutex);
diff --git a/headers/posix/sys/types.h b/headers/posix/sys/types.h
index b09aba5..64d497e 100644
--- a/headers/posix/sys/types.h
+++ b/headers/posix/sys/types.h
@@ -105,15 +105,15 @@ struct _pthread_rwlock {
__haiku_std_int32 owner;
union {
struct {
- __haiku_std_int32 sem;
- } shared;
- struct {
- __haiku_std_int32 lock_sem;
- __haiku_std_int32 lock_count;
+ __haiku_std_int32 mutex;
+ __haiku_std_int32 unused;
__haiku_std_int32 reader_count;
__haiku_std_int32 writer_count;
void* waiters[2];
} local;
+ struct {
+ __haiku_std_int32 sem;
+ } shared;
} u;
};
diff --git a/src/system/libroot/posix/pthread/pthread_rwlock.cpp
b/src/system/libroot/posix/pthread/pthread_rwlock.cpp
index 65e83be..b2470ae 100644
--- a/src/system/libroot/posix/pthread/pthread_rwlock.cpp
+++ b/src/system/libroot/posix/pthread/pthread_rwlock.cpp
@@ -12,12 +12,12 @@
#include <AutoLocker.h>
#include <libroot_lock.h>
#include <syscalls.h>
+#include <user_mutex_defs.h>
#include <user_thread.h>
#include <util/DoublyLinkedList.h>
#include "pthread_private.h"
-
#define MAX_READER_COUNT 1000000
#define RWLOCK_FLAG_SHARED 0x01
@@ -93,8 +93,8 @@ struct SharedRWLock {
struct LocalRWLock {
uint32_t flags;
int32_t owner;
- int32_t lock_sem;
- int32_t lock_count;
+ int32_t mutex;
+ int32_t unused;
int32_t reader_count;
int32_t writer_count;
// Note, that reader_count and writer_count are not used the
same way.
@@ -106,33 +106,47 @@ struct LocalRWLock {
{
flags = 0;
owner = -1;
- lock_sem = create_sem(0, "pthread rwlock");
- lock_count = 1;
+ mutex = 0;
reader_count = 0;
writer_count = 0;
new(&waiters) WaiterList;
- return lock_sem >= 0 ? B_OK : EAGAIN;
+ return B_OK;
}
status_t Destroy()
{
- if (lock_sem < 0)
- return B_BAD_VALUE;
- return delete_sem(lock_sem) == B_OK ? B_OK : B_BAD_VALUE;
+ Locker locker(this);
+ if (reader_count > 0 || waiters.Head() != NULL || writer_count
0)+ return EBUSY;