]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
[NO_THREADS]: The mutex_* macros now let mutex_t work as an `in-use'
authorUlrich Drepper <drepper@redhat.com>
Fri, 10 Dec 1999 05:29:37 +0000 (05:29 +0000)
committerUlrich Drepper <drepper@redhat.com>
Fri, 10 Dec 1999 05:29:37 +0000 (05:29 +0000)
flag even without threads.

malloc/thread-m.h

index 1598db8ee772dff67bd089929aba8a312648a159..d5b1e2f4b0259fff09887300f36021a7a5266bed 100644 (file)
@@ -207,18 +207,24 @@ int tsd_key_next;
 
 typedef int thread_id;
 
+/* The mutex functions used to do absolutely nothing, i.e. lock,
+   trylock and unlock would always just return 0.  However, even
+   without any concurrently active threads, a mutex can be used
+   legitimately as an `in use' flag.  To make the code that is
+   protected by a mutex async-signal safe, these macros would have to
+   be based on atomic test-and-set operations, for example. */
 typedef int mutex_t;
 
 #define MUTEX_INITIALIZER          0
 #define mutex_init(m)              (*(m) = 0)
-#define mutex_lock(m)              (0)
-#define mutex_trylock(m)           (0)
-#define mutex_unlock(m)            (0)
+#define mutex_lock(m)              ((*(m) = 1), 0)
+#define mutex_trylock(m)           (*(m) ? 1 : ((*(m) = 1), 0))
+#define mutex_unlock(m)            (*(m) = 0)
 
 typedef void *tsd_key_t;
 #define tsd_key_create(key, destr) do {} while(0)
-#define tsd_setspecific(key, data) do {} while(0)
-#define tsd_getspecific(key, vptr) (vptr = NULL)
+#define tsd_setspecific(key, data) ((key) = (data))
+#define tsd_getspecific(key, vptr) (vptr = (key))
 
 #define thread_atfork(prepare, parent, child) do {} while(0)