Skip to content

Instantly share code, notes, and snippets.

@jessicah
Created June 4, 2023 11:57
Show Gist options
  • Save jessicah/49ce38312ea20462165233a876f12e17 to your computer and use it in GitHub Desktop.
Save jessicah/49ce38312ea20462165233a876f12e17 to your computer and use it in GitHub Desktop.
/* Always check the result of lock and unlock. */
#define OS_ACQUIRE_LOCK(mutex) \
LOCK_DEBUG_BELCH("begin ACQUIRE_LOCK...", mutex); \
{ int __result = pthread_mutex_lock(mutex); \
LOCK_DEBUG_BELCH("end ACQUIRE_LOCK...", mutex); \
if (__result == EDEADLK) { \
barf("multiple ACQUIRE_LOCK: %s %d", __FILE__,__LINE__); \
} \
}
#define OS_RELEASE_LOCK(mutex) \
LOCK_DEBUG_BELCH("RELEASE_LOCK", mutex); \
if (pthread_mutex_unlock(mutex) != 0) { \
barf("RELEASE_LOCK: I do not own this lock: %s %d", __FILE__,__LINE__); \
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment