1 /* Copyright (C) 1994,1995,1996,1997,2005 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 #include <hurd/threadvar.h>
23 mach_port_t *portloc = \
24 (mach_port_t *) __hurd_threadvar_location (_HURD_THREADVAR_MIG_REPLY)
25 #define reply_port (*(use_threadvar ? portloc : &global_reply_port))
27 static int use_threadvar
;
28 static mach_port_t global_reply_port
;
30 /* These functions are called by MiG-generated code. */
32 /* Called by MiG to get a reply port. */
34 __mig_get_reply_port (void)
38 if (reply_port
== MACH_PORT_NULL
)
39 reply_port
= __mach_reply_port ();
43 weak_alias (__mig_get_reply_port
, mig_get_reply_port
)
45 /* Called by MiG to deallocate the reply port. */
47 __mig_dealloc_reply_port (mach_port_t arg
)
54 reply_port
= MACH_PORT_NULL
; /* So the mod_refs RPC won't use it. */
56 if (MACH_PORT_VALID (port
))
57 __mach_port_mod_refs (__mach_task_self (), port
,
58 MACH_PORT_RIGHT_RECEIVE
, -1);
60 weak_alias (__mig_dealloc_reply_port
, mig_dealloc_reply_port
)
62 /* Called by mig interfaces when done with a port. Used to provide the
63 same interface as needed when a custom allocator is used. */
65 __mig_put_reply_port(mach_port_t port
)
69 weak_alias (__mig_put_reply_port
, mig_put_reply_port
)
71 /* Called at startup with STACK == NULL. When per-thread variables are set
72 up, this is called again with STACK set to the new stack being switched
73 to, where per-thread variables should be set up. */
75 __mig_init (void *stack
)
77 use_threadvar
= stack
!= 0;
81 /* Recycle the reply port used before multithreading was enabled. */
82 mach_port_t
*portloc
= (mach_port_t
*)
83 __hurd_threadvar_location_from_sp (_HURD_THREADVAR_MIG_REPLY
, stack
);
84 *portloc
= global_reply_port
;
85 global_reply_port
= MACH_PORT_NULL
;
88 weak_alias (__mig_init
, mig_init
)