static void WaitForCriticalSection() { time_t now = time(NULL), then = FindLockTime("CF_CRITICAL_SECTION"); /* Another agent has been waiting more than a minute, it means there is likely crash detritus to clear up... After a minute we take our chances ... */ while ((then != -1) && (now - then < 60)) { sleep(1); now = time(NULL); then = FindLockTime("CF_CRITICAL_SECTION"); } WriteLock("CF_CRITICAL_SECTION"); }
static void test_lock_invalidate(void **state) { bool result; time_t lock_time; char *lock_id = "testlock2"; result = AcquireLockByID(lock_id, 1); assert_true(result); lock_time = FindLockTime(lock_id); assert_true(lock_time > 0); result = InvalidateLockTime(lock_id); assert_true(result); lock_time = FindLockTime(lock_id); assert_int_equal(lock_time, 0); result = AcquireLockByID(lock_id, 1); assert_true(result); lock_time = FindLockTime(lock_id); assert_true(lock_time > 0); }
static time_t FindLock(char *last) { time_t mtime; if ((mtime = FindLockTime(last)) == -1) { /* Do this to prevent deadlock loops from surviving if IfElapsed > T_sched */ if (WriteLock(last) == -1) { CfOut(OUTPUT_LEVEL_ERROR, "", "Unable to lock %s\n", last); return 0; } return 0; } else { return mtime; } }