| 81 | } |
| 82 | |
| 83 | bool mutex::scoped_lock::internal_try_acquire( mutex& m ) { |
| 84 | #if _WIN32||_WIN64 |
| 85 | switch( m.state ) { |
| 86 | case INITIALIZED: |
| 87 | case HELD: |
| 88 | break; |
| 89 | case DESTROYED: |
| 90 | __TBB_ASSERT(false,"mutex::scoped_lock: mutex already destroyed"); |
| 91 | break; |
| 92 | default: |
| 93 | __TBB_ASSERT(false,"mutex::scoped_lock: illegal mutex state"); |
| 94 | break; |
| 95 | } |
| 96 | #endif /* _WIN32||_WIN64 */ |
| 97 | |
| 98 | bool result; |
| 99 | #if _WIN32||_WIN64 |
| 100 | result = TryEnterCriticalSection(&m.impl)!=0; |
| 101 | if( result ) { |
| 102 | __TBB_ASSERT(m.state!=HELD, "mutex::scoped_lock: deadlock caused by attempt to reacquire held mutex"); |
| 103 | m.state = HELD; |
| 104 | } |
| 105 | #else |
| 106 | result = pthread_mutex_trylock(&m.impl)==0; |
| 107 | #endif /* _WIN32||_WIN64 */ |
| 108 | if( result ) |
| 109 | my_mutex = &m; |
| 110 | return result; |
| 111 | } |
| 112 | |
| 113 | void mutex::internal_construct() { |
| 114 | #if _WIN32||_WIN64 |