(_hurd_msgport_receive): Unlock self sigstate lock after getting it.
[kopensolaris-gnu/glibc.git] / hurd / hurdports.c
index 43c38c1..5b7dfd8 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991 Free Software Foundation, Inc.
+/* Copyright (C) 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
 This file is part of the GNU C Library.
 
 The GNU C Library is free software; you can redistribute it and/or
@@ -17,43 +17,36 @@ not, write to the Free Software Foundation, Inc., 675 Mass Ave,
 Cambridge, MA 02139, USA.  */
 
 #include <hurd.h>
+#include <hurd/port.h>
 
-#define GET(type, what)                                                              \
-type get##what (void)                                                        \
-{                                                                            \
-  __mach_port_mod_refs (__mach_task_self (), _hurd_##what,                   \
-                       MACH_PORT_RIGHT_SEND, 1);                             \
-  return _hurd_##what;                                                       \
-}
 
-#define SET(lock, type, what)                                                \
-int                                                                          \
-set##what (type new)                                                         \
-{                                                                            \
-  error_t err;                                                               \
-  type old;                                                                  \
-  if (err = __mach_port_mod_refs (__mach_task_self (), new,                  \
-                                 MACH_PORT_RIGHT_SEND, 1))                   \
-    {                                                                        \
-      errno = EINVAL;                                                        \
-      return -1;                                                             \
-    }                                                                        \
-  __mutex_lock (&_hurd_##lock);                                                      \
-  old = _hurd_##what;                                                        \
-  _hurd_##what = new;                                                        \
-  __mutex_unlock (&_hurd_##lock);                                            \
-  __mach_port_deallocate (__mach_task_self (), old);                         \
-  return 0;                                                                  \
-}
+static inline mach_port_t
+get (const int idx)
+{
+  mach_port_t result;
+  error_t err = _hurd_ports_get (idx, &result);
 
-#define        GETSET(lock, type, what)        GET (type, what) SET (lock, type, what)
+  if (err)
+    return __hurd_fail (err), MACH_PORT_NULL;
+  return result;
+}
+#define        GET(type, what, idx) \
+  type get##what (void) { return get (INIT_PORT_##idx); }
+
+static inline int
+set (const int idx, mach_port_t new)
+{
+  error_t err = _hurd_ports_set (idx, new);
+  return err ? __hurd_fail (err) : 0;
+}
+#define SET(type, what, idx) \
+  int set##what (type new) { return set (INIT_PORT_##idx, new); }
 
-GETSET (lock, process_t, proc)
-GETSET (lock, file_t, ccdir)
-GETSET (lock, file_t, cwdir)
-GETSET (lock, file_t, crdir)
-GET (lock, auth_t, auth)
+#define        GETSET(type, what, idx) \
+  GET (type, what, idx) SET (type, what, idx)
 
-#define        getsigthread    siggetthread
-#define        setsigthread    sigsetthread
-GETSET (siglock, thread_t, sigthread)
+GETSET (process_t, proc, PROC)
+GETSET (mach_port_t, cttyid, CTTYID)
+GETSET (file_t, cwdir, CWDIR)
+GETSET (file_t, crdir, CRDIR)
+GETSET (auth_t, auth, AUTH)