9os

Experimental kernel using plan9 ideas for embedded device
git clone git://git.simple-cc.org/9os
Log | Files | Refs | README | LICENSE

ref.c (243B)


      1 #include <os9/os9.h>
      2 
      3 void
      4 initref(Ref *rp)
      5 {
      6 	rp->m = 0;
      7 	rp->cnt = 1;
      8 }
      9 
     10 void
     11 incref(Ref *rp)
     12 {
     13 	lock(&rp->m);
     14 	rp->cnt++;
     15 	unlock(&rp->m);
     16 }
     17 
     18 int
     19 decref(Ref *rp)
     20 {
     21 	int r;
     22 
     23 	lock(&rp->m);
     24 	r = --rp->cnt == 0;
     25 	unlock(&rp->m);
     26 
     27 	return r;
     28 }