📄 lock.c
字号:
#include "../plan9/lib.h"#include "../plan9/sys9.h"#define _LOCK_EXTENSION#include <lock.h>int tas(int*);voidlock(Lock *lk){ int i; /* once fast */ if(!tas(&lk->val)) return; /* a thousand times pretty fast */ for(i=0; i<1000; i++){ if(!tas(&lk->val)) return; _SLEEP(0); } /* now nice and slow */ for(i=0; i<1000; i++){ if(!tas(&lk->val)) return; _SLEEP(100); } /* take your time */ while(tas(&lk->val)) _SLEEP(1000);}intcanlock(Lock *lk){ if(tas(&lk->val)) return 0; return 1;}voidunlock(Lock *lk){ lk->val = 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -