1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
/*
* Mach Operating System
* Copyright (c) 1991,1990,1989 Carnegie Mellon University
* All Rights Reserved.
*
* Permission to use, copy, modify and distribute this software and its
* documentation is hereby granted, provided that both the copyright
* notice and this permission notice appear in all copies of the
* software, derivative works or modified versions, and any portions
* thereof, and that both notices appear in supporting documentation.
*
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
* ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
*
* Carnegie Mellon requests users of this software to return to
*
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
* School of Computer Science
* Carnegie Mellon University
* Pittsburgh PA 15213-3890
*
* any improvements or extensions that they make and grant Carnegie Mellon
* the rights to redistribute these changes.
*/
/*
* HISTORY
* $Log: mig_support.c,v $
* Revision 2.6 91/05/14 17:57:41 mrt
* Correcting copyright
*
* Revision 2.5 91/02/14 14:20:30 mrt
* Added new Mach copyright
* [91/02/13 12:41:26 mrt]
*
* Revision 2.4 90/08/07 14:31:41 rpd
* Removed RCS keyword nonsense.
*
* Revision 2.3 90/08/07 14:27:48 rpd
* When we recycle the global reply port by giving it to the first
* cthread, clear the global reply port. This will take care of
* someone accidently calling this twice.
* [90/08/07 rwd]
*
* Revision 2.2 90/06/02 15:14:04 rpd
* Converted to new IPC.
* [90/03/20 20:56:50 rpd]
*
* Revision 2.1 89/08/03 17:09:50 rwd
* Created.
*
* 18-Jan-89 David Golub (dbg) at Carnegie-Mellon University
* Replaced task_data() by thread_reply().
*
*
* 27-Aug-87 Eric Cooper (ecc) at Carnegie Mellon University
* Changed mig_support.c to avoid deadlock that can occur
* if tracing is turned on during calls to mig_get_reply_port().
*
* 10-Aug-87 Eric Cooper (ecc) at Carnegie Mellon University
* Changed mig_support.c to use MACH_CALL.
* Changed "is_init" to "multithreaded" and reversed its sense.
*
* 30-Jul-87 Mary Thompson (mrt) at Carnegie Mellon University
* Created.
*/
/*
* File: mig_support.c
* Author: Mary R. Thompson, Carnegie Mellon University
* Date: July, 1987
*
* Routines to set and deallocate the mig reply port for the current thread.
* Called from mig-generated interfaces.
*
*/
#include <mach/mach.h>
#include <cthreads.h>
#include "cthread_internals.h"
private boolean_t multithreaded = FALSE;
/* use a global reply port before becoming multi-threaded */
private mach_port_t mig_reply_port = MACH_PORT_NULL;
/*
* Called by mach_init with 0 before cthread_init is
* called and again with initial cproc at end of cthread_init.
*/
void
mig_init(initial)
register cproc_t initial;
{
if (initial == NO_CPROC) {
/* called from mach_init before cthread_init,
possibly after a fork. clear global reply port. */
multithreaded = FALSE;
mig_reply_port = MACH_PORT_NULL;
} else {
/* recycle global reply port as this cthread's reply port */
multithreaded = TRUE;
initial->reply_port = mig_reply_port;
mig_reply_port = MACH_PORT_NULL;
}
}
/*
* Called by mig interface code whenever a reply port is needed.
*/
mach_port_t
mig_get_reply_port()
{
register mach_port_t reply_port;
if (multithreaded) {
register cproc_t self;
self = cproc_self();
ASSERT(self != NO_CPROC);
if ((reply_port = self->reply_port) == MACH_PORT_NULL)
self->reply_port = reply_port = mach_reply_port();
} else {
if ((reply_port = mig_reply_port) == MACH_PORT_NULL)
mig_reply_port = reply_port = mach_reply_port();
}
return reply_port;
}
/*
* Called by mig interface code after a timeout on the reply port.
* May also be called by user.
*/
void
mig_dealloc_reply_port()
{
register mach_port_t reply_port;
if (multithreaded) {
register cproc_t self;
self = cproc_self();
ASSERT(self != NO_CPROC);
reply_port = self->reply_port;
self->reply_port = MACH_PORT_NULL;
} else {
reply_port = mig_reply_port;
mig_reply_port = MACH_PORT_NULL;
}
(void) mach_port_mod_refs(mach_task_self(), reply_port,
MACH_PORT_RIGHT_RECEIVE, -1);
}
|