Changeset 783

Show
Ignore:
Timestamp:
07/04/08 22:23:48 (2 months ago)
Author:
Bartosz
Message:

encapsulated lock escalation

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/phobos/internal/monitor.d

    r781 r783  
    176176} 
    177177 
     178void escalateLock(Object obj) 
     179{ 
     180    __monitor_mutex.lock; 
     181    if (GetFatLock(obj) is null) 
     182         SetFatLock(obj, conStruct!(FatLock)); 
     183    __monitor_mutex.unlock; 
     184} 
     185 
    178186/** Called only once by a single thread during startup */ 
    179187extern(C) void _STI_monitor_staticctor() 
     
    198206    // Warning: data race 
    199207    if (GetFatLock(obj) is null) 
    200     { 
    201     __monitor_mutex.lock; 
    202         if (GetFatLock(obj) is null) // if, in the meantime, another thread didn't set it 
    203         { 
    204         SetFatLock(obj, conStruct!(FatLock)); 
    205         } 
    206     __monitor_mutex.unlock; 
    207     } 
     208        escalateLock(obj); 
     209 
    208210    GetFatLock(obj).lock; 
    209211} 
  • trunk/phobos/internal/object.d

    r781 r783  
    141141    { 
    142142        //printf("notifyRegister(dg = %llx, o = %p)\n", dg, this); 
     143        if (!GetFatLock(this)) 
     144            escalateLock(this); // Fat lock stores delegates 
    143145        synchronized (this) 
    144146        { 
    145             // Important: Monitor is guaranteed to be initialized 
    146             // as the side-effect of the synchronized clause above 
    147147            FatLock * fatLock = GetFatLock(this); 
    148148            assert(fatLock);