Changeset: 3c13e3174d47 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=3c13e3174d47 Modified Files: gdk/gdk_system.h Branch: Apr2019 Log Message:
Don't attempt spinlock (probably won't work with optimizing compilers). Use the fact that we turn a 1 ms sleep into a 1 usec sleep and just use short sleeps to wait for a lock. diffs (78 lines): diff --git a/gdk/gdk_system.h b/gdk/gdk_system.h --- a/gdk/gdk_system.h +++ b/gdk/gdk_system.h @@ -199,12 +199,7 @@ gdk_export int MT_join_thread(MT_Id t); (void) ATOMIC_INC(&(l)->contention); \ } while (0) -#define _DBG_LOCK_SLEEP(l) \ - do { \ - if (_spincnt == 1024) \ - (void) ATOMIC_INC(&GDKlocksleepcnt); \ - (void) ATOMIC_INC(&(l)->sleep); \ - } while (0) +#define _DBG_LOCK_SLEEP(l) ((void) ATOMIC_INC(&(l)->sleep)) #define _DBG_LOCK_COUNT_2(l) \ do { \ @@ -328,9 +323,10 @@ MT_lock_try(MT_Lock *l) if (!MT_lock_try(l)) { \ _DBG_LOCK_CONTENTION(l); \ MT_thread_setlockwait(l); \ + do \ + _DBG_LOCK_SLEEP(l); \ while (WaitForSingleObject( \ - (l)->lock, INFINITE) != WAIT_OBJECT_0) \ - ; \ + (l)->lock, INFINITE) != WAIT_OBJECT_0); \ MT_thread_setlockwait(NULL); \ } \ _DBG_LOCK_LOCKER(l); \ @@ -389,8 +385,9 @@ typedef struct MT_Lock { if (!MT_lock_try(l)) { \ _DBG_LOCK_CONTENTION(l); \ MT_thread_setlockwait(l); \ - while (pthread_mutex_lock(&(l)->lock) != 0) \ - ; \ + do \ + _DBG_LOCK_SLEEP(l); \ + while (pthread_mutex_lock(&(l)->lock) != 0); \ MT_thread_setlockwait(NULL); \ } \ _DBG_LOCK_LOCKER(l); \ @@ -441,15 +438,12 @@ typedef struct MT_Lock { _DBG_LOCK_COUNT_0(l); \ if (!MT_lock_try(l)) { \ /* we didn't get the lock */ \ - int _spincnt = GDKnr_threads > 1 ? 0 : 1023; \ _DBG_LOCK_CONTENTION(l); \ MT_thread_setlockwait(l); \ do { \ - if (++_spincnt >= 1024) { \ - _DBG_LOCK_SLEEP(l); \ - MT_sleep_ms(1); \ - } \ - } while (ATOMIC_TAS(&(l)->lock) != 0); \ + _DBG_LOCK_SLEEP(l); \ + MT_sleep_ms(1); \ + } while (!MT_lock_try(l)); \ MT_thread_setlockwait(NULL); \ } \ _DBG_LOCK_LOCKER(l); \ @@ -464,10 +458,12 @@ typedef struct MT_Lock { _DBG_LOCK_INIT(l); \ } while (0) -#define MT_lock_unset(l) \ - do { \ - _DBG_LOCK_UNLOCKER(l); \ - ATOMIC_CLEAR(&(l)->lock); \ +#define MT_lock_unset(l) \ + do { \ + /* lock should be locked */ \ + assert(ATOMIC_TAS(&(l)->lock) != 0); \ + _DBG_LOCK_UNLOCKER(l); \ + ATOMIC_CLEAR(&(l)->lock); \ } while (0) #define MT_lock_destroy(l) _DBG_LOCK_DESTROY(l) _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list