mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-27 13:30:31 +02:00
Factor out locking utils to separate header
This commit is contained in:
parent
691c777e7b
commit
3955d2ad96
3 changed files with 126 additions and 106 deletions
24
src/gc-lock.h
Normal file
24
src/gc-lock.h
Normal file
|
@ -0,0 +1,24 @@
|
|||
#ifndef GC_LOCK_H
|
||||
#define GC_LOCK_H
|
||||
|
||||
#include <pthread.h>
|
||||
#include "gc-assert.h"
|
||||
|
||||
struct gc_lock {
|
||||
pthread_mutex_t *lock;
|
||||
};
|
||||
|
||||
static struct gc_lock
|
||||
gc_lock_acquire(pthread_mutex_t *lock) {
|
||||
pthread_mutex_lock(lock);
|
||||
return (struct gc_lock){ lock };
|
||||
}
|
||||
|
||||
static void
|
||||
gc_lock_release(struct gc_lock *lock) {
|
||||
GC_ASSERT(lock->lock);
|
||||
pthread_mutex_unlock(lock->lock);
|
||||
lock->lock = NULL;
|
||||
}
|
||||
|
||||
#endif // GC_LOCK_H
|
Loading…
Add table
Add a link
Reference in a new issue