From 190de95f6fcf37572be7cf2ff0543d74d190a989 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 22 Feb 2008 22:32:34 +0200 Subject: Locking for read and write made waiting for each other (with loose scheme for the same thread locking). include/my_pthread.h: Added variable for lock diffirentiation. include/wqueue.h: New release call. mysys/wqueue.c: New release call in case of read/write lock. storage/maria/ma_pagecache.c: Locking for read and write made waitimg for each other. storage/maria/unittest/Makefile.am: New test added. storage/maria/unittest/ma_pagecache_consist.c: Fixed thread initialization in the test. storage/maria/unittest/ma_pagecache_rwconsist.c: New BitKeeper file ``storage/maria/unittest/ma_pagecache_rwconsist.c'' --- mysys/wqueue.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'mysys/wqueue.c') diff --git a/mysys/wqueue.c b/mysys/wqueue.c index bfe9cba1235..0766e13a4e4 100644 --- a/mysys/wqueue.c +++ b/mysys/wqueue.c @@ -136,6 +136,49 @@ void wqueue_release_queue(WQUEUE *wqueue) } +/** + @brief Removes all threads waiting for read or first one waiting for write. + + @param wqueue pointer to the queue structure + @apram thread pointer to the thread to be added to the queue +*/ + +void wqueue_release_one_locktype_from_queue(WQUEUE *wqueue) +{ + struct st_my_thread_var *last= wqueue->last_thread; + struct st_my_thread_var *next= last->next; + struct st_my_thread_var **prev= &wqueue->last_thread; + struct st_my_thread_var *thread; + uint first_type= next->lock_type; + if (first_type == MY_PTHREAD_LOCK_WRITE) + { + /* release first waiting for write lock */ + thread= next; + pthread_cond_signal(&thread->suspend); + wqueue->last_thread= next; + thread->next= NULL; + return; + } + do + { + thread= next; + next= thread->next; + if (thread->lock_type == MY_PTHREAD_LOCK_WRITE) + { + /* skip waiting for write lock */ + *prev= thread; + prev= &thread->next; + } + else + { + /* release waiting for read lock */ + pthread_cond_signal(&thread->suspend); + thread->next= NULL; + } + } while (thread != last); + *prev= NULL; +} + /* Add thread and wait -- cgit v1.2.1