2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
24 * Mach Operating System
25 * Copyright (c) 1989 Carnegie-Mellon University
26 * All rights reserved. The CMU software License Agreement specifies
27 * the terms and conditions for use and redistribution.
30 * mig_support.c - by Mary Thompson
32 * Routines to set and deallocate the mig reply port for the current thread.
33 * Called from mig-generated interfaces.
35 #include <mach/mach.h>
36 #include <pthread_internals.h>
40 #include "cthread_internals.h"
42 pthread_lock_t reply_port_lock
;
43 extern mach_port_t
_pthread_reply_port(pthread_t
);
44 static mach_port_t _task_reply_port
= MACH_PORT_NULL
;
47 * called in new child...
48 * clear lock to cover case where the parent had
49 * a thread holding this lock while another thread
54 UNLOCK(reply_port_lock
);
58 * Called by mach_init with 0 before cthread_init is
59 * called and again with 1 at the end of cthread_init.
66 LOCK_INIT(reply_port_lock
);
67 _task_reply_port
= mach_reply_port();
72 * Called by mig interface code whenever a reply port is needed.
73 * Tracing is masked during this call; otherwise, a call to printf()
74 * can result in a call to malloc() which eventually reenters
75 * mig_get_reply_port() and deadlocks.
77 mach_port_t
_mig_get_reply_port()
81 pself
= pthread_self();
82 if ((pself
!= (pthread_t
)NULL
) && (pself
->sig
== _PTHREAD_SIG
)) {
83 return pself
->reply_port
;
85 return MACH_PORT_NULL
;
88 void _mig_set_reply_port(mach_port_t port
)
91 pself
= pthread_self();
93 if ((pself
!= (pthread_t
)NULL
) && (pself
->sig
== _PTHREAD_SIG
)) {
94 pself
->reply_port
= port
;