X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/5d5c5d0d5b79ade9a973d55186ffda2638ba2b6e..935ed37a5c468c8a1c07408573c08b8b7ef80e8b:/osfmk/kern/wait_queue.c diff --git a/osfmk/kern/wait_queue.c b/osfmk/kern/wait_queue.c index 4000577a5..187ac8b13 100644 --- a/osfmk/kern/wait_queue.c +++ b/osfmk/kern/wait_queue.c @@ -1,31 +1,29 @@ /* - * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2007 Apple 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@ */ /* * @OSF_FREE_COPYRIGHT@ @@ -480,13 +478,13 @@ wait_queue_link( wait_queue_link_t wql; kern_return_t ret; - wql = (wait_queue_link_t) kalloc(sizeof(struct wait_queue_link)); + wql = (wait_queue_link_t) kalloc(sizeof(struct _wait_queue_link)); if (wql == WAIT_QUEUE_LINK_NULL) return KERN_RESOURCE_SHORTAGE; ret = wait_queue_link_noalloc(wq, wq_set, wql); if (ret != KERN_SUCCESS) - kfree(wql, sizeof(struct wait_queue_link)); + kfree(wql, sizeof(struct _wait_queue_link)); return ret; } @@ -553,7 +551,7 @@ wait_queue_unlink( wqs_unlock(wq_set); wait_queue_unlock(wq); splx(s); - kfree(wql, sizeof(struct wait_queue_link)); + kfree(wql, sizeof(struct _wait_queue_link)); return KERN_SUCCESS; } } @@ -673,7 +671,7 @@ wait_queue_unlink_all( while(!queue_empty(links)) { wql = (wait_queue_link_t) dequeue(links); - kfree(wql, sizeof(struct wait_queue_link)); + kfree(wql, sizeof(struct _wait_queue_link)); } return(KERN_SUCCESS); @@ -790,7 +788,7 @@ retry: while (!queue_empty (links)) { wql = (wait_queue_link_t) dequeue(links); - kfree(wql, sizeof(struct wait_queue_link)); + kfree(wql, sizeof(struct _wait_queue_link)); } return(KERN_SUCCESS); } @@ -829,7 +827,7 @@ wait_queue_unlink_one( wqs_unlock(wq_set); wait_queue_unlock(wq); splx(s); - kfree(wql,sizeof(struct wait_queue_link)); + kfree(wql,sizeof(struct _wait_queue_link)); *wq_setp = wq_set; return; } @@ -1068,9 +1066,9 @@ wait_queue_wakeup64_all_locked( kern_return_t res; // assert(wait_queue_held(wq)); - if(!wq->wq_interlock.lock_data) { /* (BRINGUP */ - panic("wait_queue_wakeup64_all_locked: lock not held on %08X\n", wq); /* (BRINGUP) */ - } +// if(!wq->wq_interlock.lock_data) { /* (BRINGUP */ +// panic("wait_queue_wakeup64_all_locked: lock not held on %p\n", wq); /* (BRINGUP) */ +// } queue_init(q); @@ -1123,9 +1121,9 @@ wait_queue_wakeup_all( s = splsched(); wait_queue_lock(wq); - if(!wq->wq_interlock.lock_data) { /* (BRINGUP */ - panic("wait_queue_wakeup_all: we did not get the lock on %08X\n", wq); /* (BRINGUP) */ - } +// if(!wq->wq_interlock.lock_data) { /* (BRINGUP */ +// panic("wait_queue_wakeup_all: we did not get the lock on %p\n", wq); /* (BRINGUP) */ +// } ret = wait_queue_wakeup64_all_locked( wq, (event64_t)((uint32_t)event), result, TRUE); @@ -1243,94 +1241,12 @@ _wait_queue_select64_one( return THREAD_NULL; } -/* - * Routine: wait_queue_peek64_locked - * Purpose: - * Select the best thread from a wait queue that meet the - * supplied criteria, but leave it on the queue it was - * found on. The thread, and the actual wait_queue the - * thread was found on are identified. - * Conditions: - * at splsched - * wait queue locked - * possibly recursive - * Returns: - * a locked thread - if one found - * a locked waitq - the one the thread was found on - * Note: - * Both the waitq the thread was actually found on, and - * the supplied wait queue, are locked after this. - */ -__private_extern__ void -wait_queue_peek64_locked( - wait_queue_t wq, - event64_t event, - thread_t *tp, - wait_queue_t *wqp) -{ - wait_queue_element_t wq_element; - wait_queue_element_t wqe_next; - queue_t q; - - assert(wq->wq_fifo); - - *tp = THREAD_NULL; - - q = &wq->wq_queue; - - wq_element = (wait_queue_element_t) queue_first(q); - while (!queue_end(q, (queue_entry_t)wq_element)) { - WAIT_QUEUE_ELEMENT_CHECK(wq, wq_element); - wqe_next = (wait_queue_element_t) - queue_next((queue_t) wq_element); - - /* - * We may have to recurse if this is a compound wait queue. - */ - if (wq_element->wqe_type == WAIT_QUEUE_LINK) { - wait_queue_link_t wql = (wait_queue_link_t)wq_element; - wait_queue_t set_queue; - - /* - * We have to check the set wait queue. - */ - set_queue = (wait_queue_t)wql->wql_setqueue; - wait_queue_lock(set_queue); - if (! wait_queue_empty(set_queue)) { - wait_queue_peek64_locked(set_queue, event, tp, wqp); - } - if (*tp != THREAD_NULL) { - if (*wqp != set_queue) - wait_queue_unlock(set_queue); - return; /* thread and its waitq locked */ - } - - wait_queue_unlock(set_queue); - } else { - - /* - * Otherwise, its a thread. If it is waiting on - * the event we are posting to this queue, return - * it locked, but leave it on the queue. - */ - thread_t t = (thread_t)wq_element; - - if (t->wait_event == event) { - thread_lock(t); - *tp = t; - *wqp = wq; - return; - } - } - wq_element = wqe_next; - } -} /* * Routine: wait_queue_pull_thread_locked * Purpose: - * Pull a thread that was previously "peeked" off the wait - * queue and (possibly) unlock the waitq. + * Pull a thread off its wait queue and (possibly) unlock + * the waitq. * Conditions: * at splsched * wait queue locked @@ -1449,7 +1365,6 @@ wait_queue_wakeup64_identity_locked( assert(wait_queue_held(wq)); - thread = _wait_queue_select64_one(wq, event); if (unlock) wait_queue_unlock(wq);