28 |
#include "cap-intern.h" |
#include "cap-intern.h" |
29 |
|
|
30 |
|
|
31 |
static hurd_ihash_t server_to_sconn; |
static struct hurd_ihash server_to_sconn = HURD_IHASH_INITIALIZER; |
32 |
static pthread_mutex_t server_to_sconn_lock = PTHREAD_MUTEX_INITIALIZER; |
static pthread_mutex_t server_to_sconn_lock = PTHREAD_MUTEX_INITIALIZER; |
33 |
|
|
34 |
|
|
63 |
} |
} |
64 |
|
|
65 |
/* Now we can remove the object. */ |
/* Now we can remove the object. */ |
66 |
hurd_ihash_remove (server_to_sconn, sconn->server_thread); |
hurd_ihash_remove (&server_to_sconn, sconn->server_thread); |
67 |
pthread_mutex_unlock (&server_to_sconn_lock); |
pthread_mutex_unlock (&server_to_sconn_lock); |
68 |
|
|
69 |
/* Finally, we can destroy it. */ |
/* Finally, we can destroy it. */ |
70 |
pthread_mutex_unlock (&sconn->lock); |
pthread_mutex_unlock (&sconn->lock); |
71 |
pthread_mutex_destroy (&sconn->lock); |
pthread_mutex_destroy (&sconn->lock); |
72 |
hurd_ihash_destroy (sconn->id_to_cap); |
hurd_ihash_destroy (&sconn->id_to_cap); |
73 |
hurd_cap_deallocate (sconn->server_task_id); |
hurd_cap_deallocate (sconn->server_task_id); |
74 |
free (sconn); |
free (sconn); |
75 |
} |
} |
82 |
_hurd_cap_sconn_remove (sconn, scid) |
_hurd_cap_sconn_remove (sconn, scid) |
83 |
{ |
{ |
84 |
/* Remove the capability object pointer, which is now invalid. */ |
/* Remove the capability object pointer, which is now invalid. */ |
85 |
hurd_ihash_remove (sconn->id_to_cap, scid); |
hurd_ihash_remove (&sconn->id_to_cap, scid); |
86 |
/* FIXME: The following should be some low level RPC to deallocate |
/* FIXME: The following should be some low level RPC to deallocate |
87 |
the capability on the server side. If it fails, then what can we |
the capability on the server side. If it fails, then what can we |
88 |
do at this point? */ |
do at this point? */ |
106 |
int sconn_created = 0; |
int sconn_created = 0; |
107 |
|
|
108 |
pthread_mutex_lock (&server_to_sconn_lock); |
pthread_mutex_lock (&server_to_sconn_lock); |
109 |
sconn = hurd_ihash_lookup (server_to_sconn, server_thread); |
sconn = hurd_ihash_find (&server_to_sconn, server_thread); |
110 |
if (!sconn) |
if (!sconn) |
111 |
{ |
{ |
112 |
error_t err; |
error_t err; |
117 |
pthread_mutex_unlock (&server_to_sconn_lock); |
pthread_mutex_unlock (&server_to_sconn_lock); |
118 |
return errno; |
return errno; |
119 |
} |
} |
|
err = hurd_ihash_create (&sconn->id_to_cap); |
|
|
if (err) |
|
|
{ |
|
|
free (sconn); |
|
|
pthread_mutex_unlock (&server_to_sconn_lock); |
|
|
return errno; |
|
|
} |
|
120 |
err = pthread_mutex_init (&sconn->lock, NULL); |
err = pthread_mutex_init (&sconn->lock, NULL); |
121 |
if (err) |
if (err) |
122 |
{ |
{ |
|
hurd_ihash_destroy (sconn->id_to_cap); |
|
123 |
free (sconn); |
free (sconn); |
124 |
pthread_mutex_unlock (&server_to_sconn_lock); |
pthread_mutex_unlock (&server_to_sconn_lock); |
125 |
return errno; |
return errno; |
126 |
} |
} |
127 |
|
hurd_ihash_init (&sconn->id_to_cap); |
128 |
|
|
129 |
sconn->server_thread = server_thread; |
sconn->server_thread = server_thread; |
130 |
sconn->server_task_id = server_task_id; |
sconn->server_task_id = server_task_id; |
131 |
sconn->refs = 0; |
sconn->refs = 0; |
132 |
|
|
133 |
/* Enter the new server connection object. */ |
/* Enter the new server connection object. */ |
134 |
err = hurd_ihash_enter (server_to_sconn, server_thread, sconn); |
err = hurd_ihash_add (&server_to_sconn, server_thread, sconn, NULL); |
135 |
if (err) |
if (err) |
136 |
{ |
{ |
137 |
pthread_mutex_destroy (&sconn->lock); |
pthread_mutex_destroy (&sconn->lock); |
138 |
hurd_ihash_destroy (sconn->id_to_cap); |
hurd_ihash_destroy (&sconn->id_to_cap); |
139 |
free (sconn); |
free (sconn); |
140 |
pthread_mutex_unlock (&server_to_sconn_lock); |
pthread_mutex_unlock (&server_to_sconn_lock); |
141 |
return errno; |
return errno; |
148 |
sconn->refs++; |
sconn->refs++; |
149 |
pthread_mutex_unlock (&server_to_sconn_lock); |
pthread_mutex_unlock (&server_to_sconn_lock); |
150 |
|
|
151 |
cap = hurd_ihash_lookup (sconn->id_to_cap, scid); |
cap = hurd_ihash_find (&sconn->id_to_cap, scid); |
152 |
if (!cap) |
if (!cap) |
153 |
{ |
{ |
154 |
error_t err = hurd_slab_alloc (cap_space, &cap); |
error_t err = hurd_slab_alloc (cap_space, &cap); |
162 |
cap->scid = scid; |
cap->scid = scid; |
163 |
cap->dead_cb = NULL; |
cap->dead_cb = NULL; |
164 |
|
|
165 |
err = hurd_ihash_enter (sconn->id_to_cap, scid, cap); |
err = hurd_ihash_add (&sconn->id_to_cap, scid, cap, 0); |
166 |
if (err) |
if (err) |
167 |
{ |
{ |
168 |
_hurd_cap_sconn_dealloc (sconn); |
_hurd_cap_sconn_dealloc (sconn); |