![cinap_lenrek](/assets/img/avatar_default.png)
semaphore locks have much higher overhead than initially presented in the "Semaphores in Plan9" paper. until the reason for it has been found out i will revert the changes.
27 lines
255 B
C
27 lines
255 B
C
#define _LOCK_EXTENSION
|
|
#include "../plan9/sys9.h"
|
|
#include <lock.h>
|
|
|
|
int tas(int*);
|
|
|
|
void
|
|
lock(Lock *lk)
|
|
{
|
|
while(tas(&lk->val))
|
|
_SLEEP(0);
|
|
}
|
|
|
|
int
|
|
canlock(Lock *lk)
|
|
{
|
|
if(tas(&lk->val))
|
|
return 0;
|
|
return 1;
|
|
}
|
|
|
|
void
|
|
unlock(Lock *lk)
|
|
{
|
|
lk->val = 0;
|
|
}
|