more new libthread
This commit is contained in:
parent
1544f90960
commit
619085f0b4
7 changed files with 800 additions and 0 deletions
27
src/libthread/ref.c
Normal file
27
src/libthread/ref.c
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
#include "u.h"
|
||||
#include "libc.h"
|
||||
#include "thread.h"
|
||||
|
||||
static long
|
||||
refadd(Ref *r, long a)
|
||||
{
|
||||
long ref;
|
||||
|
||||
lock(&r->lock);
|
||||
r->ref += a;
|
||||
ref = r->ref;
|
||||
unlock(&r->lock);
|
||||
return ref;
|
||||
}
|
||||
|
||||
long
|
||||
incref(Ref *r)
|
||||
{
|
||||
return refadd(r, 1);
|
||||
}
|
||||
|
||||
long
|
||||
decref(Ref *r)
|
||||
{
|
||||
return refadd(r, -1);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue