# # old_revision [ed6817ca2956872b0fe2eb840c87d95a8393a5b9] # # patch "lib/compiler/dmd/monitor.c" # from [90ec06244f9084ef690bfe607b57f5701b97e62c] # to [b06d4efe3b7bc6dea02d238bf9c661252b8ea99f] # ============================================================ --- lib/compiler/dmd/monitor.c 90ec06244f9084ef690bfe607b57f5701b97e62c +++ lib/compiler/dmd/monitor.c b06d4efe3b7bc6dea02d238bf9c661252b8ea99f @@ -100,6 +100,29 @@ void _d_monitorexit(Object *h) LeaveCriticalSection(MONPTR(h)); } +void *_d_monitorget(Object *h) +{ + if (!h->monitor) + { + Monitor *cs; + + cs = (Monitor *)calloc(sizeof(Monitor), 1); + assert(cs); + EnterCriticalSection(&_monitor_critsec); + if (!h->monitor) // if, in the meantime, another thread didn't set it + { + h->monitor = (void *)cs; + InitializeCriticalSection(&cs->mon); + cs = NULL; + } + LeaveCriticalSection(&_monitor_critsec); + if (cs) // if we didn't use it + free(cs); + } + + return ((void *) MONPTR(h)); +} + /*************************************** * Called by garbage collector when Object is free'd. */ @@ -182,6 +205,28 @@ void _d_monitorexit(Object *h) //printf("-_d_monitorexit(%p)\n", h); } +void *_d_monitorget(Object *h) +{ + if (!h->monitor) + { + Monitor *cs; + + cs = (Monitor *)calloc(sizeof(Monitor), 1); + assert(cs); + pthread_mutex_lock(&_monitor_critsec); + if (!h->monitor) // if, in the meantime, another thread didn't set it + { + h->monitor = (void *)cs; + pthread_mutex_init(&cs->mon, & _monitors_attr); + cs = NULL; + } + pthread_mutex_unlock(&_monitor_critsec); + if (cs) // if we didn't use it + free(cs); + } + return ((void *) MONPTR(h)); +} + /*************************************** * Called by garbage collector when Object is free'd. */