Replaces snoopers with an atomic
authorBarret Rhoden <brho@cs.berkeley.edu>
Fri, 17 Jan 2014 22:00:27 +0000 (14:00 -0800)
committerBarret Rhoden <brho@cs.berkeley.edu>
Fri, 17 Jan 2014 22:00:27 +0000 (14:00 -0800)
Instead of a kref.  We shouldn't use a kref, since we don't expect to do
anything when we put the final reference back.  Also, you'll panic when
you kref_get something with a ref == 0.

kern/include/ip.h
kern/src/net/devip.c
kern/src/net/pktmedium.c

index 83fe892..390d05e 100644 (file)
@@ -80,7 +80,7 @@ struct conv
        struct queue*   wq;                     /* queued data waiting to be written */
        struct queue*   eq;                     /* returned error packets */
        struct queue*   sq;                     /* snooping queue */
-       struct kref     snoopers;               /* number of processes with snoop open */
+       atomic_t        snoopers;               /* number of processes with snoop open */
 
        struct rendez   cr;
        char    cerr[ERRMAX];
index 5fd11bc..933c00c 100644 (file)
@@ -415,7 +415,7 @@ ipopen(struct chan* c, int omode)
                cv = p->conv[CONV(c->qid)];
                if(strcmp(ATTACHER(c), cv->owner) != 0 && !iseve())
                        error(Eperm);
-               kref_get(&cv->snoopers, 1);
+               atomic_inc(&cv->snoopers);
                break;
        case Qclone:
                p = f->p[PROTO(c->qid)];
@@ -617,7 +617,7 @@ ipclose(struct chan* c)
                break;
        case Qsnoop:
                if(c->flag & COPEN)
-                       kref_put(&f->p[PROTO(c->qid)]->conv[CONV(c->qid)]->snoopers);
+                       atomic_dec(&f->p[PROTO(c->qid)]->conv[CONV(c->qid)]->snoopers);
                break;
        }
        kfree(((struct IPaux*)c->aux)->owner);
index 4613460..b9a1e55 100644 (file)
@@ -57,7 +57,7 @@ pktbwrite(struct Ipifc *ifc, struct block *bp, int unused_int, uint8_t *unused_u
 {
        /* enqueue onto the conversation's rq */
        bp = concatblock(bp);
-       if(kref_refcnt(&ifc->conv->snoopers) > 0)
+       if (atomic_read(&ifc->conv->snoopers) > 0)
                qpass(ifc->conv->sq, copyblock(bp, BLEN(bp)));
        qpass(ifc->conv->rq, bp);
 }
@@ -71,7 +71,7 @@ pktin(struct Fs *f, struct Ipifc *ifc, struct block *bp)
        if(ifc->lifc == NULL)
                freeb(bp);
        else {
-               if(kref_refcnt(&ifc->conv->snoopers) > 0)
+               if (atomic_read(&ifc->conv->snoopers) > 0)
                        qpass(ifc->conv->sq, copyblock(bp, BLEN(bp)));
                ipiput4(f, ifc, bp);
        }