1door_bind(3C)            Standard C Library Functions            door_bind(3C)
2
3
4

NAME

6       door_bind,  door_unbind  -  bind  or unbind the current thread with the
7       door server pool
8

SYNOPSIS

10       cc -mt [ flag... ] file... [ library... ]
11       #include <door.h>
12
13       int door_bind(int did);
14
15
16       int door_unbind(void);
17
18

DESCRIPTION

20       The door_bind() function associates the  current  thread  with  a  door
21       server  pool.  A  door  server pool is a private pool of server threads
22       that is available to serve door invocations associated  with  the  door
23       did.
24
25
26       The  door_unbind()  function  breaks  the association of door_bind() by
27       removing any private door pool binding that is associated with the cur‐
28       rent thread.
29
30
31       Normally,  door server threads are placed in a global pool of available
32       threads that invocations on any door can use to dispatch a door invoca‐
33       tion.  A  door that has been created with DOOR_PRIVATE only uses server
34       threads that have been associated with the door by door_bind().  It  is
35       therefore  necessary  to bind at least one server thread  to doors cre‐
36       ated with DOOR_PRIVATE.
37
38
39       The server thread create function, door_server_create(),  is  initially
40       called   by   the   system   during   a  door_create()  operation.  See
41       door_server_create(3C) and  door_create(3C).
42
43
44       The current thread is added to the  private  pool  of  server   threads
45       associated  with  a  door  during the next door_return() (that has been
46       issued by the current thread after  an  associated   door_bind()).  See
47       door_return(3C).  A  server  thread performing a  door_bind() on a door
48       that is  already  bound  to  a  different  door  performs  an  implicit
49       door_unbind() of the previous door.
50
51
52       If  a  process  containing threads that have been bound to a door calls
53       fork(2), the threads in the child process will be bound to  an  invalid
54       door, and any calls to door_return(3C) will result in an error.
55

RETURN VALUES

57       Upon  successful completion, a 0 is returned. Otherwise, −1 is returned
58       and errno is set to indicate the error.
59

ERRORS

61       The  door_bind() and  door_unbind() functions fail if:
62
63       EBADF     The did argument is not a valid door.
64
65
66       EBADF     The door_unbind() function was called by  a  thread  that  is
67                 currently not bound.
68
69
70       EINVAL    did was not created with the DOOR_PRIVATE attribute.
71
72

EXAMPLES

74       Example 1 Use door_bind() to create private server pools for two doors.
75
76
77       The  following  example  shows the use of door_bind() to create private
78       server pools for two doors, d1 and d2. Function my_create()  is  called
79       when  a  new server thread is needed; it creates a thread running func‐
80       tion, my_server_create(), which binds itself to one of the two doors.
81
82
83         #include <door.h>
84         #include <thread.h>
85         #include <pthread.h>
86         thread_key_t door_key;
87         int d1 = -1;
88         int d2 = -1;
89         cond_t cv;       /* statically initialized to zero */
90         mutex_t lock;    /* statically initialized to zero */
91
92         extern void foo(void *, char *, size_t, door_desc_t *, uint_t);
93         extern void bar(void *, char *, size_t, door_desc_t *, uint_t);
94
95         static void *
96         my_server_create(void *arg)
97         {
98                 /* wait for d1 & d2 to be initialized */
99                 mutex_lock(&lock);
100                 while (d1 == -1 || d2 == -1)
101                         cond_wait(&cv, &lock);
102                 mutex_unlock(&lock);
103
104                 if (arg == (void *)foo){
105                         /* bind thread with pool associated with d1 */
106                         thr_setspecific(door_key, (void *)foo);
107                         if (door_bind(d1) < 0) {
108                                 perror("door_bind"); exit (-1);
109                         }
110                 } else if (arg == (void *)bar) {
111                         /* bind thread with pool associated with d2 */
112                         thr_setspecific(door_key, (void *)bar);
113                         if (door_bind(d2) < 0) {
114                         /* bind thread to d2 thread pool */
115                                 perror("door_bind"); exit (-1);
116                         }
117                 }
118                 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
119                 door_return(NULL, 0, NULL, 0);  /* Wait for door invocation */
120         }
121
122         static void
123         my_create(door_info_t *dip)
124         {
125                 /* Pass the door identity information to create function */
126                 thr_create(NULL, 0, my_server_create, (void *)dip->di_proc,
127                         THR_BOUND | THR_DETACHED, NULL);
128         }
129
130         main()
131         {
132                 (void) door_server_create(my_create);
133                 if (thr_keycreate(&door_key, NULL) != 0) {
134                         perror("thr_keycreate");
135                         exit(1);
136                 }
137                 mutex_lock(&lock);
138                 d1 = door_create(foo, NULL, DOOR_PRIVATE); /* Private pool */
139                 d2 = door_create(bar, NULL, DOOR_PRIVATE); /* Private pool */
140                 cond_signal(&cv);
141                 mutex_unlock(&lock);
142                 while (1)
143                         pause();
144         }
145
146

ATTRIBUTES

148       See attributes(5) for descriptions of the following attributes:
149
150
151
152
153       ┌─────────────────────────────┬─────────────────────────────┐
154       │      ATTRIBUTE TYPE         │      ATTRIBUTE VALUE        │
155       ├─────────────────────────────┼─────────────────────────────┤
156       │Architecture                 │all                          │
157       ├─────────────────────────────┼─────────────────────────────┤
158       │Availability                 │SUNWcsu                      │
159       ├─────────────────────────────┼─────────────────────────────┤
160       │Interface Stability          │Stable                       │
161       ├─────────────────────────────┼─────────────────────────────┤
162       │MT-Level                     │Safe                         │
163       └─────────────────────────────┴─────────────────────────────┘
164

SEE ALSO

166       fork(2),door_create(3C),    door_return(3C),    door_server_create(3C),
167       attributes(5)
168
169
170
171SunOS 5.11                        22 Mar 2005                    door_bind(3C)
Impressum