Changeset 1:e3d42f26a8cf in rrlib_thread


Ignore:
Timestamp:
06.07.2012 16:10:37 (7 years ago)
Author:
Max Reichardt <mreichardt@…>
Branch:
default
Phase:
public
Message:

Fixed lock and lock stack class so that we actually see an error message if someone attempts to lock plain mutex twice.

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • internal/tLockStack.cpp

    r0 r1  
    128128    if (l->locked_ordered) 
    129129    { 
    130       RRLIB_LOG_PRINTF(eLL_USER, "  LockOrderMutex %p ('%s', primary %d, secondary %d)", l->locked_ordered, l->locked_ordered->GetDescription(), l->locked_ordered->GetPrimary(), l->locked_ordered->GetSecondary()); 
     130      RRLIB_LOG_PRINTF(eLL_USER, "  %s %p ('%s', primary %d, secondary %d)", l->locked_simple ? "OrderedMutex" : "RecursiveMutex", l->locked_ordered, l->locked_ordered->GetDescription(), l->locked_ordered->GetPrimary(), l->locked_ordered->GetSecondary()); 
    131131    } 
    132132    else 
     
    180180      } 
    181181    } 
     182    else if (lock->locked_ordered && lock->locked_simple) 
     183    { 
     184      bool found = false; 
     185      for (auto it = s->entries.begin(); it < s->entries.end(); it++) 
     186      { 
     187        if (lock->locked_ordered == (*it)->locked_ordered) 
     188        { 
     189          RRLIB_LOG_PRINTF(eLL_ERROR, "Attempt failed to lock ordered mutex %p ('%s', primary %d, secondary %d). Only recursive mutexes may be locked twice.", lock->locked_ordered, lock->locked_ordered->GetDescription(), lock->locked_ordered->GetPrimary(), lock->locked_ordered->GetSecondary()); 
     190          DumpStack(); 
     191          abort(); 
     192        } 
     193      } 
     194    } 
    182195  } 
    183196 
  • tLock.h

    r0 r1  
    8989 
    9090  explicit tLock(const tMutex& mutex) : 
    91     simple_lock(mutex.wrapped), 
     91    simple_lock(), 
    9292    recursive_lock(), 
    9393    locked_ordered(NULL), 
     
    9797    internal::tLockStack::Push(this); 
    9898#endif 
     99    simple_lock = std::unique_lock<std::mutex>(mutex.wrapped); 
    99100  } 
    100101 
     
    108109 
    109110  explicit tLock(const tOrderedMutex& mutex) : 
    110     simple_lock(mutex.wrapped), 
     111    simple_lock(), 
    111112    recursive_lock(), 
    112113    locked_ordered(&mutex), 
     
    116117    internal::tLockStack::Push(this); 
    117118#endif 
     119    simple_lock = std::unique_lock<std::mutex>(mutex.wrapped); 
    118120  } 
    119121 
    120122  explicit tLock(const tRecursiveMutex& mutex) : 
    121123    simple_lock(), 
    122     recursive_lock(mutex.wrapped), 
     124    recursive_lock(), 
    123125    locked_ordered(&mutex), 
    124126    locked_simple() 
     
    127129    internal::tLockStack::Push(this); 
    128130#endif 
     131    recursive_lock = std::unique_lock<std::recursive_mutex>(mutex.wrapped); 
    129132  } 
    130133 
Note: See TracChangeset for help on using the changeset viewer.