X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/5d5c5d0d5b79ade9a973d55186ffda2638ba2b6e..8f6c56a50524aa785f7e596d52dddfb331e18961:/bsd/netat/adsp_Close.c?ds=sidebyside diff --git a/bsd/netat/adsp_Close.c b/bsd/netat/adsp_Close.c index 80e93de9f..9bdeb69d6 100644 --- a/bsd/netat/adsp_Close.c +++ b/bsd/netat/adsp_Close.c @@ -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) 1990, 1995-1998 Apple Computer, Inc. @@ -64,6 +62,7 @@ #include #include +extern atlock_t adspall_lock; static void qRemove(CCBPtr, CCBPtr); @@ -129,6 +128,7 @@ int CompleteQueue(qhead, code) /* (DSPPBPtr FPTR qhead, OSErr code) */ register gref_t *gref; register int total = 0; CCBPtr sp = 0; + int s; n = *qhead; /* Get first item */ *qhead = 0; /* Zero out the queue */ @@ -137,6 +137,7 @@ int CompleteQueue(qhead, code) /* (DSPPBPtr FPTR qhead, OSErr code) */ if (gref->info) { sp = (CCBPtr)gbuf_rptr(((gbuf_t *)gref->info)); atalk_flush(sp->gref); + ATDISABLE(s, sp->lock); } } @@ -149,6 +150,8 @@ int CompleteQueue(qhead, code) /* (DSPPBPtr FPTR qhead, OSErr code) */ } else gbuf_freem(p->mp); } /* while */ + if (sp) + ATENABLE(s, sp->lock); return(total); } @@ -355,6 +358,7 @@ int adspClose(sp, pb) /* (DSPPBPtr pb) */ register CCBPtr sp; register struct adspcmd *pb; { + int s; register gbuf_t *mp; /* Must execute nearly all of this with ints off because user could @@ -406,8 +410,10 @@ int adspClose(sp, pb) /* (DSPPBPtr pb) */ * is still pending. */ if (pb->csCode == (short)dspClose) { + ATDISABLE(s, sp->lock); if ((sp->state == (short)sPassive) || (sp->state == (short)sOpening)) { sp->state = sClosed; + ATENABLE(s, sp->lock); DoClose(sp, errAborted, 0); pb->ioResult = 0; adspioc_ack(0, pb->ioc, pb->gref); @@ -415,19 +421,23 @@ int adspClose(sp, pb) /* (DSPPBPtr pb) */ } if (sp->state == (word)sClosed) { /* Ok to close a closed connection */ + ATENABLE(s, sp->lock); pb->ioResult = 0; adspioc_ack(0, pb->ioc, pb->gref); return 0; } if ((sp->state != (word)sOpen) && (sp->state != (word)sClosing)) { + ATENABLE(s, sp->lock); pb->ioResult = errState; return EINVAL; } sp->state = sClosing; /* No matter what, we're closing */ + ATENABLE(s, sp->lock); } /* dspClose */ else { /* dspRemove */ + ATDISABLE(s, sp->lock); sp->removing = 1; /* Prevent allowing another dspClose. */ /* Tells completion routine of close */ /* packet to remove us. */ @@ -435,10 +445,13 @@ int adspClose(sp, pb) /* (DSPPBPtr pb) */ if (sp->state == sPassive || sp->state == sClosed || sp->state == sOpening) { sp->state = sClosed; + ATENABLE(s, sp->lock); DoClose(sp, errAborted, 0); /* Will remove CCB! */ return 0; - } else /* sClosing & sOpen */ + } else { /* sClosing & sOpen */ sp->state = sClosing; + ATENABLE(s, sp->lock); + } } /* dspRemove */ @@ -454,7 +467,9 @@ int adspClose(sp, pb) /* (DSPPBPtr pb) */ pb = (struct adspcmd *)gbuf_rptr(mp); /* get new parameter block */ pb->ioc = 0; pb->mp = mp; + ATDISABLE(s, sp->lock); qAddToEnd(&sp->opb, pb); /* and save it */ + ATENABLE(s, sp->lock); } else { pb->ioResult = 0; adspioc_ack(0, pb->ioc, pb->gref); /* release user, and keep no copy @@ -470,15 +485,19 @@ static void qRemove(qptr, elem) register CCBPtr qptr; register CCBPtr elem; { + int s; + ATDISABLE(s, adspall_lock); while(qptr->ccbLink) { if ((DSPPBPtr)(qptr->ccbLink) == (DSPPBPtr)elem) { qptr->ccbLink = elem->ccbLink; elem->ccbLink = 0; + ATENABLE(s, adspall_lock); return; } qptr = qptr->ccbLink; } + ATENABLE(s, adspall_lock); } int RxClose(sp) @@ -486,11 +505,17 @@ int RxClose(sp) { register gbuf_t *mp; register struct adspcmd *pb; + int s, l; - if ((sp->state == sClosing) || (sp->state == sClosed)) + ATDISABLE(l, sp->lockClose); + ATDISABLE(s, sp->lock); + if ((sp->state == sClosing) || (sp->state == sClosed)) { + ATENABLE(s, sp->lock); + ATENABLE(l, sp->lockClose); return 0; - + } sp->state = sClosed; + ATENABLE(s, sp->lock); CheckReadQueue(sp); /* try to deliver all remaining data */ if ( (mp = gbuf_alloc(sizeof(struct adspcmd), PRI_HI)) ) { @@ -507,5 +532,6 @@ int RxClose(sp) if ((sp->userFlags & eClosed) == 0) DoClose(sp, errAborted, -1); /* abort send requests and timers */ + ATENABLE(l, sp->lockClose); return 0; }