]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/netat/atp_open.c
xnu-792.12.6.tar.gz
[apple/xnu.git] / bsd / netat / atp_open.c
index 16f2a8eb08c2ad298745aca99533fa7b2b94caf9..524a3b7f6257d625e2dd36ced37c78e96ec519b4 100644 (file)
@@ -1,23 +1,31 @@
 /*
- * Copyright (c) 2000 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.
+ * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved.
  * 
- * This 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.
+ * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
  * 
- * @APPLE_LICENSE_HEADER_END@
+ * 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.  The rights granted to you under the 
+ * License may not be used to create, or enable the creation or 
+ * redistribution of, unlawful or unlicensed copies of an Apple operating 
+ * system, or to circumvent, violate, or enable the circumvention or 
+ * violation of, any terms of an Apple operating system software license 
+ * agreement.
+ *
+ * Please obtain a copy of the License at 
+ * http://www.opensource.apple.com/apsl/ and read it before using this 
+ * file.
+ *
+ * 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, QUIET ENJOYMENT OR NON-INFRINGEMENT. 
+ * Please see the License for the specific language governing rights and 
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
  */
 /*
  *     Copyright (c) 1996-1998 Apple Computer, Inc.
@@ -58,6 +66,9 @@
 
 int atp_inited = 0;
 struct atp_rcb_qhead atp_need_rel;
+atlock_t atpall_lock;
+atlock_t atptmo_lock;
+atlock_t atpgen_lock;
 
 /**********/
 int atp_pidM[256];
@@ -127,7 +138,7 @@ int atp_open(gref, flag)
        int flag;
 {
        register struct atp_state *atp;
-       register int i;
+       register int s, i;
        vm_offset_t     temp;
        
        /*
@@ -167,14 +178,18 @@ int atp_open(gref, flag)
         *      If no atp structure available return failure
         */
 
-       if ((atp = atp_free_list) == NULL)
+       ATDISABLE(s, atpall_lock);
+       if ((atp = atp_free_list) == NULL) {
+               ATENABLE(s, atpall_lock);
                return(EAGAIN);
+       }
 
        /*
         *      Update free list
         */
 
        atp_free_list = atp->atp_trans_waiting;
+       ATENABLE(s, atpall_lock);
 
        /*
         *      Initialize the data structure
@@ -192,6 +207,8 @@ int atp_open(gref, flag)
        atp->atp_socket_no = -1;
        atp->atp_pid = gref->pid;
        atp->atp_msgq = 0;
+       ATLOCKINIT(atp->atp_lock);
+       ATLOCKINIT(atp->atp_delay_lock);
        ATEVENTINIT(atp->atp_event);
        ATEVENTINIT(atp->atp_delay_event);
        gref->info = (void *)atp;
@@ -201,9 +218,11 @@ int atp_open(gref, flag)
         */
 
        if (flag) {
+               ATDISABLE(s, atpall_lock);
                if ((atp->atp_trans_waiting = atp_used_list) != 0)
                        atp->atp_trans_waiting->atp_rcb_waiting = atp;
                atp_used_list = atp;
+               ATENABLE(s, atpall_lock);
        }
        return(0);
 }
@@ -221,6 +240,7 @@ int atp_close(gref, flag)
        register struct atp_state *atp;
        register struct atp_trans *trp;
        register struct atp_rcb *rcbp;
+       register int s;
        int socket;
        pid_t pid;
 
@@ -232,6 +252,7 @@ int atp_close(gref, flag)
                atp->atp_msgq = 0;
        }
 
+       ATDISABLE(s, atp->atp_lock);
        atp->atp_flags |= ATP_CLOSING;
        socket = atp->atp_socket_no;
        if (socket != -1)
@@ -252,6 +273,7 @@ int atp_close(gref, flag)
                atp_rcb_free(rcbp);
        while ((rcbp = atp->atp_attached.head))
                atp_rcb_free(rcbp);
+       ATENABLE(s, atp->atp_lock);
 
        if (flag && (socket == -1))
                atp_dequeue_atp(atp);
@@ -259,9 +281,11 @@ int atp_close(gref, flag)
        /*
         *      free the state variable
         */
+       ATDISABLE(s, atpall_lock);
        atp->atp_socket_no = -1;
        atp->atp_trans_waiting = atp_free_list;
        atp_free_list = atp;
+       ATENABLE(s, atpall_lock);
 
        if (socket != -1) {
                pid = (pid_t)atp_pidM[socket];