plan9port

fork of plan9port with libvec, libstr and libsdb
Log | Files | Refs | README | LICENSE

ref.c (278B)


      1 #include "u.h"
      2 #include "libc.h"
      3 #include "thread.h"
      4 
      5 static long
      6 refadd(Ref *r, long a)
      7 {
      8 	long ref;
      9 
     10 	lock(&r->lock);
     11 	r->ref += a;
     12 	ref = r->ref;
     13 	unlock(&r->lock);
     14 	return ref;
     15 }
     16 
     17 long
     18 incref(Ref *r)
     19 {
     20 	return refadd(r, 1);
     21 }
     22 
     23 long
     24 decref(Ref *r)
     25 {
     26 	return refadd(r, -1);
     27 }