2 .\" Copyright (c) 2005, Sun Microsystems, Inc. All Rights Reserved.
3 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
4 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
5 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
6 .TH DOOR_BIND 3C "Mar 22, 2005"
8 door_bind, door_unbind \- bind or unbind the current thread with the door
13 \fBcc\fR \fB-mt\fR [ \fIflag\fR... ] \fIfile\fR... [ \fIlibrary\fR... ]
16 \fBint\fR \fBdoor_bind\fR(\fBint\fR \fIdid\fR);
21 \fBint\fR \fBdoor_unbind\fR(\fBvoid\fR);
26 The \fBdoor_bind()\fR function associates the current thread with a door server
27 pool. A door server pool is a private pool of server threads that is available
28 to serve door invocations associated with the door \fIdid\fR.
31 The \fBdoor_unbind()\fR function breaks the association of \fBdoor_bind()\fR by
32 removing any private door pool binding that is associated with the current
36 Normally, door server threads are placed in a global pool of available threads
37 that invocations on any door can use to dispatch a door invocation. A door that
38 has been created with \fBDOOR_PRIVATE\fR only uses server threads that have
39 been associated with the door by \fBdoor_bind()\fR. It is therefore necessary
40 to bind at least one server thread to doors created with \fBDOOR_PRIVATE\fR.
43 The server thread create function, \fBdoor_server_create()\fR, is initially
44 called by the system during a \fBdoor_create()\fR operation. See
45 \fBdoor_server_create\fR(3C) and \fBdoor_create\fR(3C).
48 The current thread is added to the private pool of server threads associated
49 with a door during the next \fBdoor_return()\fR (that has been issued by the
50 current thread after an associated \fBdoor_bind()\fR). See
51 \fBdoor_return\fR(3C). A server thread performing a \fBdoor_bind()\fR on a
52 door that is already bound to a different door performs an implicit
53 \fBdoor_unbind()\fR of the previous door.
56 If a process containing threads that have been bound to a door calls
57 \fBfork\fR(2), the threads in the child process will be bound to an invalid
58 door, and any calls to \fBdoor_return\fR(3C) will result in an error.
61 Upon successful completion, a \fB0\fR is returned. Otherwise, \fB\(mi1\fR is
62 returned and \fBerrno\fR is set to indicate the error.
65 The \fBdoor_bind()\fR and \fBdoor_unbind()\fR functions fail if:
72 The \fIdid\fR argument is not a valid door.
81 The \fBdoor_unbind()\fR function was called by a thread that is currently not
91 \fIdid\fR was not created with the \fBDOOR_PRIVATE\fR attribute.
96 \fBExample 1 \fRUse \fBdoor_bind()\fR to create private server pools for two
100 The following example shows the use of \fBdoor_bind()\fR to create private
101 server pools for two doors, \fBd1\fR and \fBd2\fR. Function \fBmy_create()\fR
102 is called when a new server thread is needed; it creates a thread running
103 function, \fBmy_server_create()\fR, which binds itself to one of the two doors.
111 thread_key_t door_key;
114 cond_t cv; /* statically initialized to zero */
115 mutex_t lock; /* statically initialized to zero */
117 extern void foo(void *, char *, size_t, door_desc_t *, uint_t);
118 extern void bar(void *, char *, size_t, door_desc_t *, uint_t);
121 my_server_create(void *arg)
123 /* wait for d1 & d2 to be initialized */
125 while (d1 == -1 || d2 == -1)
126 cond_wait(&cv, &lock);
129 if (arg == (void *)foo){
130 /* bind thread with pool associated with d1 */
131 thr_setspecific(door_key, (void *)foo);
132 if (door_bind(d1) < 0) {
133 perror("door_bind"); exit (-1);
135 } else if (arg == (void *)bar) {
136 /* bind thread with pool associated with d2 */
137 thr_setspecific(door_key, (void *)bar);
138 if (door_bind(d2) < 0) {
139 /* bind thread to d2 thread pool */
140 perror("door_bind"); exit (-1);
143 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
144 door_return(NULL, 0, NULL, 0); /* Wait for door invocation */
148 my_create(door_info_t *dip)
150 /* Pass the door identity information to create function */
151 thr_create(NULL, 0, my_server_create, (void *)dip->di_proc,
152 THR_BOUND | THR_DETACHED, NULL);
157 (void) door_server_create(my_create);
158 if (thr_keycreate(&door_key, NULL) != 0) {
159 perror("thr_keycreate");
163 d1 = door_create(foo, NULL, DOOR_PRIVATE); /* Private pool */
164 d2 = door_create(bar, NULL, DOOR_PRIVATE); /* Private pool */
175 See \fBattributes\fR(5) for descriptions of the following attributes:
183 ATTRIBUTE TYPE ATTRIBUTE VALUE
187 Interface Stability Stable
194 \fBfork\fR(2), \fBdoor_create\fR(3C), \fBdoor_return\fR(3C),
195 \fBdoor_server_create\fR(3C), \fBattributes\fR(5)