MCPcopy Create free account
hub / github.com/dmtcp/dmtcp / DmtcpMutexTryLock

Function DmtcpMutexTryLock

src/mutex.cpp:76–104  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

74
75
76extern "C" int
77DmtcpMutexTryLock(DmtcpMutex *mutex)
78{
79 pid_t owner = 1;
80
81 if (mutex->type != DMTCP_MUTEX_LLL) {
82 owner = gettid();
83
84 if ((pid_t)(mutex->owner) == owner) {
85 if (mutex->type == DMTCP_MUTEX_RECURSIVE) {
86 JASSERT(mutex->count + 1 != 0);
87 mutex->count++;
88 return 0;
89 }
90 return EDEADLK;
91 }
92 }
93
94 if (__sync_val_compare_and_swap(&mutex->futex,
95 LOCK_FREE,
96 LOCK_ACQUIRED) == LOCK_FREE) {
97 // We successfully acquired the lock.
98 mutex->owner = (mutex_owner_t)owner;
99 mutex->count = 1;
100 return 0;
101 }
102
103 return EAGAIN;
104}
105
106
107/* Set mutex->futex to 0 (LOCK_FREE), releasing the lock. If mutex->futex was

Callers 1

DmtcpMutexLockFunction · 0.85

Calls 1

gettidFunction · 0.70

Tested by

no test coverage detected