lock.h
来自「be文件系统实现的源码」· C头文件 代码 · 共 29 行
H
29 行
#ifndef _LOCK_H#define _LOCK_Htypedef struct lock lock;typedef struct mlock mlock;struct lock { sem_id s; long c;};struct mlock { sem_id s;};extern int new_lock(lock *l, const char *name);extern int free_lock(lock *l);#define LOCK(l) if (atomic_add(&l.c, -1) <= 0) acquire_sem(l.s);#define UNLOCK(l) if (atomic_add(&l.c, 1) < 0) release_sem(l.s);extern int new_mlock(mlock *l, long c, const char *name);extern int free_mlock(mlock *l);#define LOCKM(l,cnt) acquire_sem_etc(l.s, cnt, 0, 0.0)#define UNLOCKM(l,cnt) release_sem_etc(l.s, cnt, 0)#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?