]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/netat/atp_open.c
xnu-792.17.14.tar.gz
[apple/xnu.git] / bsd / netat / atp_open.c
index 9b9373f2dbad0c43eab35e6e999eb68d40b01cd0..d77532757c6b52b0c7fef8e75d333c5d8968934a 100644 (file)
@@ -1,31 +1,29 @@
 /*
  * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
  *
- * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  * 
- * 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 
+ * 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@
+ * 
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
  */
 /*
  *     Copyright (c) 1996-1998 Apple Computer, Inc.
@@ -66,6 +64,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];
@@ -135,7 +136,7 @@ int atp_open(gref, flag)
        int flag;
 {
        register struct atp_state *atp;
-       register int i;
+       register int s, i;
        vm_offset_t     temp;
        
        /*
@@ -175,14 +176,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
@@ -196,10 +201,13 @@ int atp_open(gref, flag)
        atp->atp_timeout = HZ/8;
        atp->atp_rcb_waiting = NULL;
        atp->atp_rcb.head = NULL;       
+       atp->atp_attached.head = NULL;  
        atp->atp_flags = T_MPSAFE;
        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;
@@ -209,9 +217,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);
 }
@@ -229,6 +239,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;
 
@@ -240,6 +251,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)
@@ -260,6 +272,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);
@@ -267,9 +280,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];