summaryrefslogtreecommitdiff
path: root/libguile/null-threads.h
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2016-07-24 13:16:45 +0200
committerAndy Wingo <wingo@pobox.com>2016-07-25 11:50:17 +0200
commitca2d00ad65e1e3db0a88f7964c5b0ab49b9471e9 (patch)
tree36b47896145abbe56859c860d34c0ec5f313cf38 /libguile/null-threads.h
parent315acd5ee0bb9ac942d1ca27c2485c8333582ff7 (diff)
downloadguile-ca2d00ad65e1e3db0a88f7964c5b0ab49b9471e9.tar.gz
Reimplement null-threads as inline functions
* libguile/null-threads.h: Reimplement null-threads stubs for pthread data types, initializers, and functions in terms of types and inline functions instead of CPP macros. Fixes unused-value warnings, and tightens things up in general. (scm_i_pthread_cleanup_push, scm_i_pthread_cleanup_pop): Remove these, as they were unused and incorrect -- they would never run the cleanup handler even if 1 was passed to pop.
Diffstat (limited to 'libguile/null-threads.h')
-rw-r--r--libguile/null-threads.h179
1 files changed, 149 insertions, 30 deletions
diff --git a/libguile/null-threads.h b/libguile/null-threads.h
index 116b845a5..dcb14e6a7 100644
--- a/libguile/null-threads.h
+++ b/libguile/null-threads.h
@@ -34,53 +34,172 @@
*/
#include <stdlib.h>
+#include <signal.h>
#include <errno.h>
/* Threads
*/
-#define scm_i_pthread_t int
-#define scm_i_pthread_self() 0
-#define scm_i_pthread_create(t,a,f,d) (*(t)=0, (void)(f), ENOSYS)
-#define scm_i_pthread_detach(t) do { } while (0)
-#define scm_i_pthread_exit(v) exit (EXIT_SUCCESS)
-#define scm_i_pthread_cancel(t) 0
-#define scm_i_pthread_cleanup_push(t,v) 0
-#define scm_i_pthread_cleanup_pop(e) 0
-#define scm_i_sched_yield() 0
+typedef int scm_i_pthread_t;
+typedef void scm_i_pthread_attr_t;
+
+static inline scm_i_pthread_t
+scm_i_pthread_self (void)
+{
+ return 0;
+}
+
+static inline int
+scm_i_pthread_create (scm_i_pthread_t *t, const scm_i_pthread_attr_t *attr,
+ void* (*f) (void*), void *arg)
+{
+ return ENOSYS;
+}
+
+static inline int
+scm_i_pthread_detach (scm_i_pthread_t t)
+{
+ return 0;
+}
+
+static inline void
+scm_i_pthread_exit (void *retval)
+{
+ exit (EXIT_SUCCESS);
+}
+
+static inline int
+scm_i_pthread_cancel (scm_i_pthread_t t)
+{
+ return 0;
+}
+
+static inline int
+scm_i_sched_yield (void)
+{
+ return 0;
+}
+
/* Signals
*/
-#define scm_i_pthread_sigmask sigprocmask
+static inline int
+scm_i_pthread_sigmask (int how, const sigset_t *set, sigset_t *oldset)
+{
+ return sigprocmask (how, set, oldset);
+}
/* Mutexes
*/
-#define SCM_I_PTHREAD_MUTEX_INITIALIZER 0
-#define scm_i_pthread_mutex_t int
-#define scm_i_pthread_mutex_init(m,a) (*(m) = 0)
-#define scm_i_pthread_mutex_destroy(m) do { (void)(m); } while(0)
-#define scm_i_pthread_mutex_trylock(m) ((*(m))++)
-#define scm_i_pthread_mutex_lock(m) ((*(m))++)
-#define scm_i_pthread_mutex_unlock(m) ((*(m))--)
+typedef enum {
+ SCM_I_PTHREAD_MUTEX_INITIALIZER = 0,
+ SCM_I_PTHREAD_MUTEX_LOCKED = 1
+} scm_i_pthread_mutex_t;
+typedef int scm_i_pthread_mutexattr_t;
+
+static inline int
+scm_i_pthread_mutex_init (scm_i_pthread_mutex_t *m,
+ scm_i_pthread_mutexattr_t *attr)
+{
+ *m = SCM_I_PTHREAD_MUTEX_INITIALIZER;
+ return 0;
+}
+
+static inline int
+scm_i_pthread_mutex_destroy (scm_i_pthread_mutex_t *m)
+{
+ return 0;
+}
+
+static inline int
+scm_i_pthread_mutex_trylock(scm_i_pthread_mutex_t *m)
+{
+ if (*m == SCM_I_PTHREAD_MUTEX_LOCKED)
+ return EDEADLK;
+ *m = SCM_I_PTHREAD_MUTEX_LOCKED;
+ return 0;
+}
+
+static inline int
+scm_i_pthread_mutex_lock (scm_i_pthread_mutex_t *m)
+{
+ *m = SCM_I_PTHREAD_MUTEX_LOCKED;
+ return 0;
+}
+
+static inline int
+scm_i_pthread_mutex_unlock (scm_i_pthread_mutex_t *m)
+{
+ *m = SCM_I_PTHREAD_MUTEX_INITIALIZER;
+ return 0;
+}
+
#define scm_i_pthread_mutexattr_recursive 0
/* Condition variables
*/
-#define SCM_I_PTHREAD_COND_INITIALIZER 0
-#define scm_i_pthread_cond_t int
-#define scm_i_pthread_cond_init(c,a) (*(c) = 0)
-#define scm_i_pthread_cond_destroy(c) do { (void)(c); } while(0)
-#define scm_i_pthread_cond_signal(c) (*(c) = 1)
-#define scm_i_pthread_cond_broadcast(c) (*(c) = 1)
-#define scm_i_pthread_cond_wait(c,m) (abort(), 0)
-#define scm_i_pthread_cond_timedwait(c,m,t) (abort(), 0)
+typedef enum {
+ SCM_I_PTHREAD_COND_INITIALIZER = 0
+} scm_i_pthread_cond_t;
+typedef int scm_i_pthread_condattr_t;
+
+static inline int
+scm_i_pthread_cond_init (scm_i_pthread_cond_t *c,
+ scm_i_pthread_condattr_t *attr)
+{
+ *c = SCM_I_PTHREAD_COND_INITIALIZER;
+ return 0;
+}
+
+static inline int
+scm_i_pthread_cond_destroy (scm_i_pthread_cond_t *c)
+{
+ return 0;
+}
+
+static inline int
+scm_i_pthread_cond_signal (scm_i_pthread_cond_t *c)
+{
+ return 0;
+}
+
+static inline int
+scm_i_pthread_cond_broadcast (scm_i_pthread_cond_t *c)
+{
+ return 0;
+}
+
+static inline int
+scm_i_pthread_cond_wait (scm_i_pthread_cond_t *c, scm_i_pthread_mutex_t *m)
+{
+ abort ();
+ return 0;
+}
+
+static inline int
+scm_i_pthread_cond_timedwait (scm_i_pthread_cond_t *c, scm_i_pthread_mutex_t *m,
+ const scm_t_timespec *t)
+{
+ abort();
+ return 0;
+}
/* Onces
*/
-#define scm_i_pthread_once_t int
-#define SCM_I_PTHREAD_ONCE_INIT 0
-#define scm_i_pthread_once(o,f) do { \
- if(!*(o)) { *(o)=1; f (); } \
- } while(0)
+typedef enum {
+ SCM_I_PTHREAD_ONCE_INIT = 0,
+ SCM_I_PTHREAD_ONCE_ALREADY = 1
+} scm_i_pthread_once_t;
+
+static inline int
+scm_i_pthread_once (scm_i_pthread_once_t *o, void(*init)(void))
+{
+ if (*o == SCM_I_PTHREAD_ONCE_INIT)
+ {
+ *o = SCM_I_PTHREAD_ONCE_ALREADY;
+ init ();
+ }
+ return 0;
+}
/* Thread specific storage
*/