commit-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gnumach/oskit ds_routines.c


From: Roland McGrath
Subject: gnumach/oskit ds_routines.c
Date: Sat, 09 Nov 2002 20:54:52 -0500

CVSROOT:        /cvsroot/hurd
Module name:    gnumach
Changes by:     Roland McGrath <address@hidden> 02/11/09 20:54:52

Modified files:
        oskit          : ds_routines.c 

Log message:
        2002-11-09  Roland McGrath  <address@hidden>
        
        * oskit/ds_routines.c (ds_notify): Deallocate two refs, not one.
        (dev_open_com): Bump the ref_count on a new device to account for
        the reference held in the hash table as well as the one returned.

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnumach/gnumach/oskit/ds_routines.c.diff?tr1=1.7&tr2=1.8&r1=text&r2=text

Patches:
Index: gnumach/oskit/ds_routines.c
diff -u gnumach/oskit/ds_routines.c:1.7 gnumach/oskit/ds_routines.c:1.8
--- gnumach/oskit/ds_routines.c:1.7     Mon Oct 21 05:32:14 2002
+++ gnumach/oskit/ds_routines.c Sat Nov  9 20:54:52 2002
@@ -245,7 +245,9 @@
       dev = dev_port_lookup ((ipc_port_t) ns->not_header.msgh_remote_port);
       assert (dev);
 
-      /* Extant send rights held one ref on the device object.  */
+      /* Extant send rights held one ref on the device object,
+        and we just got another one from dev_port_lookup.  */
+      device_deallocate (dev);
       device_deallocate (dev);
 
       return TRUE;
@@ -359,6 +361,8 @@
   dev = dev_hash_lookup (com_device, mode);
   if (dev != DEVICE_NULL)
     {
+      /* Acquire a reference on the device, as by device_reference.
+        We don't just call that because of the locking here.  */
       device_lock (dev);
       ++dev->ref_count;
       simple_unlock (&dev_hash_lock);
@@ -392,6 +396,11 @@
   dev->mode = mode;
   dev->ops = 0;
 
+  /* The newly allocated device has one reference on it.  The slot hash
+     table will hold one reference, and we will consume another below.  */
+  assert (dev->ref_count == 1);
+  dev->ref_count == 2;
+
   /* Put the device in the hash table under its COM device.
      After this point we need to use device_lock.  */
   simple_lock (&dev_hash_lock);
@@ -598,7 +607,7 @@
        }
     }
 
-  *devp = dev;
+  *devp = dev;                 /* Caller consumes the reference.  */
   return D_SUCCESS;
 }
 
@@ -623,9 +632,12 @@
       dev->com.mem.recsize = recsize;
       dev->ops = &mem_device_ops;
       *loc = dev;
+
+      /* The *LOC value (in a global variable) holds a reference that
+        is never released.  */
     }
 
-  device_reference (*loc);
+  device_reference (*loc);  /* This reference is consumed by the caller.  */
   *out_dev = *loc;
   return D_SUCCESS;
 }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]