2013-09-21 17:55:52 +00:00
|
|
|
#define _LOCK_EXTENSION
|
2013-09-26 20:24:31 +00:00
|
|
|
#include "../plan9/sys9.h"
|
2011-03-30 12:46:40 +00:00
|
|
|
#include <lock.h>
|
|
|
|
|
2013-09-26 20:24:31 +00:00
|
|
|
int tas(int*);
|
|
|
|
|
2011-03-30 12:46:40 +00:00
|
|
|
void
|
2013-09-26 20:24:31 +00:00
|
|
|
lock(Lock *lk)
|
2011-03-30 12:46:40 +00:00
|
|
|
{
|
2013-09-26 20:24:31 +00:00
|
|
|
while(tas(&lk->val))
|
|
|
|
_SLEEP(0);
|
2011-03-30 12:46:40 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 20:24:31 +00:00
|
|
|
int
|
|
|
|
canlock(Lock *lk)
|
2011-03-30 12:46:40 +00:00
|
|
|
{
|
2013-09-26 20:24:31 +00:00
|
|
|
if(tas(&lk->val))
|
|
|
|
return 0;
|
|
|
|
return 1;
|
2011-03-30 12:46:40 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 20:24:31 +00:00
|
|
|
void
|
|
|
|
unlock(Lock *lk)
|
2011-03-30 12:46:40 +00:00
|
|
|
{
|
2013-09-26 20:24:31 +00:00
|
|
|
lk->val = 0;
|
2011-03-30 12:46:40 +00:00
|
|
|
}
|