Changeset: 164dee1f60ee for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/164dee1f60ee
Modified Files:
gdk/gdk_system.h
Branch: Jun2023
Log Message:
Fixed condition variable variant of semaphores implementation.
diffs (41 lines):
diff --git a/gdk/gdk_system.h b/gdk/gdk_system.h
--- a/gdk/gdk_system.h
+++ b/gdk/gdk_system.h
@@ -673,7 +673,7 @@ typedef struct {
/* simulate semaphores using mutex and condition variable */
typedef struct {
- int cnt;
+ int cnt, wakeups;
pthread_mutex_t mutex;
pthread_cond_t cond;
char name[MT_NAME_LEN];
@@ -683,6 +683,7 @@ typedef struct {
do { \
strcpy_len((s)->name, (n), sizeof((s)->name)); \
(s)->cnt = (nr); \
+ (s)->wakeups = 0; \
pthread_mutex_init(&(s)->mutex, 0); \
pthread_cond_init(&(s)->cond, 0); \
} while (0)
@@ -696,7 +697,8 @@ typedef struct {
#define MT_sema_up(s) \
do { \
pthread_mutex_lock(&(s)->mutex); \
- if ((s)->cnt++ < 0) { \
+ if (++(s)->cnt <= 0) { \
+ (s)->wakeups++; \
pthread_cond_signal(&(s)->cond); \
} \
pthread_mutex_unlock(&(s)->mutex); \
@@ -711,8 +713,9 @@ typedef struct {
do { \
pthread_cond_wait(&(s)->cond, \
&(s)->mutex); \
- } while ((s)->cnt < 0); \
+ } while ((s)->wakeups < 1); \
MT_thread_setsemawait(NULL); \
+ (s)->wakeups--; \
pthread_mutex_unlock(&(s)->mutex); \
} \
TRC_DEBUG(TEM, "Sema %s down complete\n", (s)->name); \
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]