/[hurd]/hurd-l4/libhurd-cap/cap-user.c
ViewVC logotype

Diff of /hurd-l4/libhurd-cap/cap-user.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.7 by marcus, Thu Aug 28 00:13:27 2003 UTC revision 1.8 by marcus, Mon Sep 15 18:09:45 2003 UTC
# Line 19  Line 19 
19     Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA     Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20     02111-1307 USA.  */     02111-1307 USA.  */
21    
22    #if HAVE_CONFIG_H
23    #include <config.h>
24    #endif
25    
26  #include <stdlib.h>  #include <stdlib.h>
27  #include <pthread.h>  #include <pthread.h>
28  #include <assert.h>  #include <assert.h>
29  #include <errno.h>  #include <errno.h>
30    #include <stdint.h>
31    
32  #include <hurd/cap.h>  #include <hurd/cap.h>
33    
# Line 69  _hurd_cap_sconn_dealloc (hurd_cap_sconn_ Line 74  _hurd_cap_sconn_dealloc (hurd_cap_sconn_
74      }      }
75    
76    /* Now we can remove the object.  */    /* Now we can remove the object.  */
77    hurd_ihash_remove (&server_to_sconn, sconn->server_thread);    hurd_ihash_remove (&server_to_sconn, sconn->server_thread.raw);
78    pthread_mutex_unlock (&server_to_sconn_lock);    pthread_mutex_unlock (&server_to_sconn_lock);
79    
80    /* Finally, we can destroy it.  */    /* Finally, we can destroy it.  */
81    pthread_mutex_unlock (&sconn->lock);    pthread_mutex_unlock (&sconn->lock);
82    pthread_mutex_destroy (&sconn->lock);    pthread_mutex_destroy (&sconn->lock);
83    hurd_ihash_destroy (&sconn->id_to_cap);    hurd_ihash_destroy (&sconn->id_to_cap);
84    if (sconn->server_task_id)    if (sconn->server_task_info)
85      hurd_cap_deallocate (sconn->server_task_id);      hurd_cap_deallocate (sconn->server_task_info);
86    free (sconn);    free (sconn);
87  }  }
88    
# Line 86  _hurd_cap_sconn_dealloc (hurd_cap_sconn_ Line 91  _hurd_cap_sconn_dealloc (hurd_cap_sconn_
91     connection SCONN.  SCONN is locked.  Afterwards, SCONN is     connection SCONN.  SCONN is locked.  Afterwards, SCONN is
92     unlocked.  */     unlocked.  */
93  void  void
94  _hurd_cap_sconn_remove (sconn, scid)  _hurd_cap_sconn_remove (hurd_cap_sconn_t sconn, l4_word_t scid)
95  {  {
96    /* Remove the capability object pointer, which is now invalid.  */    /* Remove the capability object pointer, which is now invalid.  */
97    hurd_ihash_remove (&sconn->id_to_cap, scid);    hurd_ihash_remove (&sconn->id_to_cap, scid);
98    
99    /* FIXME: The following should be some low level RPC to deallocate    /* FIXME: The following should be some low level RPC to deallocate
100       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
101       do at this point?  */       do at this point?  */
# Line 100  _hurd_cap_sconn_remove (sconn, scid) Line 106  _hurd_cap_sconn_remove (sconn, scid)
106    
107    
108  /* Enter a new send capability provided by the server SERVER_THREAD  /* Enter a new send capability provided by the server SERVER_THREAD
109     (with the task ID reference SERVER_TASK_ID) and the cap ID SCID.     (with the task ID reference SERVER_TASK_INFO) and the cap ID SCID.
110     SCONN is the server connection for SERVER_THREAD, if known.  It     SCONN is the server connection for SERVER_THREAD, if known.  It
111     should be unlocked.  If SCONN is NULL, then SERVER_TASK_INFO should     should be unlocked.  If SCONN is NULL, then SERVER_TASK_INFO should
112     be the task info capability for the server SERVER_THREAD, otherwise     be the task info capability for the server SERVER_THREAD, otherwise
# Line 118  _hurd_cap_sconn_enter (hurd_cap_sconn_t Line 124  _hurd_cap_sconn_enter (hurd_cap_sconn_t
124    int sconn_created = 0;    int sconn_created = 0;
125    
126    if (sconn)    if (sconn)
127      assert (sconn->server_thread == server_thread);      assert (l4_is_thread_equal (sconn->server_thread, server_thread));
128    else    else
129      {      {
130        /* It might have become available by now.  */        /* It might have become available by now.  */
131        pthread_mutex_lock (&server_to_sconn_lock);        pthread_mutex_lock (&server_to_sconn_lock);
132        sconn = hurd_ihash_find (&server_to_sconn, server_thread);        sconn = hurd_ihash_find (&server_to_sconn, server_thread.raw);
133        if (sconn)        if (sconn)
134          hurd_cap_deallocate (server_task_info);          hurd_cap_deallocate (server_task_info);
135        else        else
# Line 146  _hurd_cap_sconn_enter (hurd_cap_sconn_t Line 152  _hurd_cap_sconn_enter (hurd_cap_sconn_t
152                return errno;                return errno;
153              }              }
154    
155            hurd_ihash_init (&sconn->id_to_cap);            hurd_ihash_init (&sconn->id_to_cap, HURD_IHASH_NO_LOCP);
156            sconn->server_thread = server_thread;            sconn->server_thread = server_thread;
157            sconn->server_task_id = server_task_info;            sconn->server_task_info = server_task_info;
158            sconn->refs = 0;            sconn->refs = 0;
159    
160            /* Enter the new server connection object.  */            /* Enter the new server connection object.  */
161            err = hurd_ihash_add (&server_to_sconn, server_thread, sconn);            err = hurd_ihash_add (&server_to_sconn, server_thread.raw, sconn);
162            if (err)            if (err)
163              {              {
164                pthread_mutex_destroy (&sconn->lock);                pthread_mutex_destroy (&sconn->lock);
165                hurd_ihash_destroy (&sconn->id_to_cap);                hurd_ihash_destroy (&sconn->id_to_cap);
166                free (sconn);                free (sconn);
167                pthread_mutex_unlock (&server_to_sconn_lock);                pthread_mutex_unlock (&server_to_sconn_lock);
168                hurd_cap_deallocate (server_task_id);                hurd_cap_deallocate (server_task_info);
169                return errno;                return errno;
170              }              }
171          }          }
# Line 167  _hurd_cap_sconn_enter (hurd_cap_sconn_t Line 173  _hurd_cap_sconn_enter (hurd_cap_sconn_t
173    pthread_mutex_lock (&sconn->lock);    pthread_mutex_lock (&sconn->lock);
174    pthread_mutex_unlock (&server_to_sconn_lock);    pthread_mutex_unlock (&server_to_sconn_lock);
175    
176    cap = hurd_ihash_find (&sconn->id_to_cap, scid);    (*cap) = hurd_ihash_find (&sconn->id_to_cap, scid);
177    if (!cap)    if (!cap)
178      {      {
179        error_t err = hurd_slab_alloc (cap_space, &cap);        error_t err = hurd_slab_alloc (cap_space, cap);
180        if (err)        if (err)
181          {          {
182            _hurd_cap_sconn_dealloc (sconn);            _hurd_cap_sconn_dealloc (sconn);
183            return err;            return err;
184          }          }
185    
186        cap->sconn = sconn;        (*cap)->sconn = sconn;
187        cap->scid = scid;        (*cap)->scid = scid;
188        cap->dead_cb = NULL;  #if 0
189          (*cap)->dead_cb = NULL;
190    #endif
191    
192        err = hurd_ihash_add (&sconn->id_to_cap, scid, cap);        err = hurd_ihash_add (&sconn->id_to_cap, scid, *cap);
193        if (err)        if (err)
194          {          {
195            _hurd_cap_sconn_dealloc (sconn);            _hurd_cap_sconn_dealloc (sconn);
196            hurd_slab_dealloc (cap_space, cap);            hurd_slab_dealloc (cap_space, *cap);
197            return err;            return err;
198          }          }
199      }      }
200    pthread_mutex_lock (&cap->lock);    pthread_mutex_lock (&(*cap)->lock);
201    cap->srefs++;    (*cap)->srefs++;
202    /* We have to add a reference for the capability we have added,    /* We have to add a reference for the capability we have added,
203       unless we are consuming the reference that was provided.  */       unless we are consuming the reference that was provided.  */
204    if (!sconn_provided)    if (!sconn_provided)

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.8

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26