]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/ipc/ipc_pset.c
xnu-792.6.56.tar.gz
[apple/xnu.git] / osfmk / ipc / ipc_pset.c
index 01a4cfa55d7238801f644a0d27d60b721407bf0f..4cd4ae0ca2ba7efddfb28efccbc1352a9a65f9d3 100644 (file)
@@ -1,21 +1,22 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  * 
- * The contents of this file constitute Original Code as defined in and
- * are subject to the Apple Public Source License Version 1.1 (the
- * "License").  You may not use this file except in compliance with the
- * License.  Please obtain a copy of the License at
- * http://www.apple.com/publicsource and read it before using this file.
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
  * 
- * This Original Code and all software distributed under the License are
- * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
- * License for the specific language governing rights and limitations
- * under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
  * 
  * @APPLE_LICENSE_HEADER_END@
  */
@@ -67,8 +68,9 @@
 #include <ipc/ipc_space.h>
 #include <ipc/ipc_port.h>
 #include <ipc/ipc_print.h>
-#include <kern/thread_pool.h>
 
+#include <kern/kern_types.h>
+#include <kern/spl.h>
 /*
  *     Routine:        ipc_pset_alloc
  *     Purpose:
@@ -101,9 +103,7 @@ ipc_pset_alloc(
        /* pset is locked */
 
        pset->ips_local_name = name;
-       pset->ips_pset_self = pset;
        ipc_mqueue_init(&pset->ips_messages, TRUE /* set */);
-       thread_pool_init(&pset->ips_thread_pool);
 
        *namep = name;
        *psetp = pset;
@@ -142,9 +142,7 @@ ipc_pset_alloc_name(
        /* pset is locked */
 
        pset->ips_local_name = name;
-       pset->ips_pset_self = pset;
        ipc_mqueue_init(&pset->ips_messages, TRUE /* set */);
-       thread_pool_init(&pset->ips_thread_pool);
 
        *psetp = pset;
        return KERN_SUCCESS;
@@ -173,7 +171,6 @@ ipc_pset_member(
  *     Routine:        ipc_pset_add
  *     Purpose:
  *             Puts a port into a port set.
- *             The port set gains a reference.
  *     Conditions:
  *             Both port and port set are locked and active.
  *             The owner of the port set is also receiver for the port.
@@ -184,18 +181,17 @@ ipc_pset_add(
        ipc_pset_t      pset,
        ipc_port_t      port)
 {
+       kern_return_t kr;
+
        assert(ips_active(pset));
        assert(ip_active(port));
        
-       if (ipc_pset_member(pset, port))
-               return KERN_ALREADY_IN_SET;
-
-       ips_reference(pset);
-       port->ip_pset_count++;
+       kr = ipc_mqueue_add(&port->ip_messages, &pset->ips_messages);
 
-       ipc_mqueue_add(&port->ip_messages, &pset->ips_messages);
+       if (kr == KERN_SUCCESS)
+               port->ip_pset_count++;
 
-       return KERN_SUCCESS;
+       return kr;
 }
 
 
@@ -215,58 +211,43 @@ ipc_pset_remove(
        ipc_pset_t      pset,
        ipc_port_t      port)
 {
-       mach_msg_return_t mr;
+       kern_return_t kr;
 
        assert(ip_active(port));
        
        if (port->ip_pset_count == 0)
                return KERN_NOT_IN_SET;
 
-       mr = ipc_mqueue_remove(&port->ip_messages, &pset->ips_messages);
+       kr = ipc_mqueue_remove(&port->ip_messages, &pset->ips_messages);
 
-       if (mr == MACH_MSG_SUCCESS) {
+       if (kr == KERN_SUCCESS)
                port->ip_pset_count--;
-               ips_release(pset);
-       }
-       return mr;
+
+       return kr;
 }
 
 /*
- *     Routine:        ipc_pset_remove_all
+ *     Routine:        ipc_pset_remove_from_all
  *     Purpose:
  *             Removes a port from all it's port sets.
- *             Each port set loses a reference.
  *     Conditions:
  *             port is locked and active.
  */
 
 kern_return_t
-ipc_pset_remove_all(
+ipc_pset_remove_from_all(
        ipc_port_t      port)
 {
-       ipc_pset_mqueue_t pset_mqueue;
-       ipc_pset_t pset;
-
        assert(ip_active(port));
        
        if (port->ip_pset_count == 0)
                return KERN_NOT_IN_SET;
 
        /* 
-        * Remove each port set's mqueue from the port's (one at a time).
+        * Remove the port's mqueue from all sets
         */
-       while (port->ip_pset_count > 0) {
-               ipc_mqueue_remove_one(&port->ip_messages,
-                                     (ipc_mqueue_t)&pset_mqueue);
-               assert(pset_mqueue != (ipc_pset_mqueue_t)0);
-               port->ip_pset_count--;
-
-               pset = pset_mqueue->ipsm_pset;
-               ipc_pset_release(pset); /* locks and unlocks pset */
-
-       }
-
-       assert(port->ip_pset_count == 0);
+       ipc_mqueue_remove_from_all(&port->ip_messages);
+       port->ip_pset_count = 0;
        return KERN_SUCCESS;
 }
 
@@ -275,9 +256,6 @@ ipc_pset_remove_all(
  *     Routine:        ipc_pset_destroy
  *     Purpose:
  *             Destroys a port_set.
- *
- *             Doesn't remove members from the port set;
- *             that happens lazily.
  *     Conditions:
  *             The port_set is locked and alive.
  *             The caller has a reference, which is consumed.
@@ -294,6 +272,11 @@ ipc_pset_destroy(
 
        pset->ips_object.io_bits &= ~IO_BITS_ACTIVE;
 
+       /*
+        * remove all the member message queues
+        */
+       ipc_mqueue_remove_all(&pset->ips_messages);
+       
        s = splsched();
        imq_lock(&pset->ips_messages);
        ipc_mqueue_changed(&pset->ips_messages);
@@ -337,13 +320,10 @@ ipc_list_count(
  *     Purpose:
  *             Pretty-print a port set for kdb.
  */
-
 void
 ipc_pset_print(
        ipc_pset_t      pset)
 {
-       extern int db_indent;
-
        printf("pset 0x%x\n", pset);
 
        db_indent += 2;