summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2012-02-17 11:35:02 +0100
committerAndy Wingo <wingo@pobox.com>2012-02-17 12:09:28 +0100
commit2f745b64a1eb06e9e175a1b497d5270bebff9097 (patch)
tree56706ae52f6e7f4097c8e4e2b4771b27e2525a19
parentf609480611cfd1585409fd6b1b90beb730b026cf (diff)
downloadguile-2f745b64a1eb06e9e175a1b497d5270bebff9097.tar.gz
add pthread_atfork helpers to our threading shims
* libguile/null-threads.h: * libguile/pthread-threads.h (SCM_DEFINE_ATFORK_HANDLERS_FOR_MUTEX) (scm_i_pthread_atfork): Define a pthread_atfork shim, and a helper to declare procedures to lock and unlock a mutex. * libguile/threads.h (SCM_PTHREAD_ATFORK_LOCK_STATIC_MUTEX): New macro, causes the snarfer to emit a pthread_atfork call to lock a mutex, if threads are enabled.
-rw-r--r--libguile/null-threads.h5
-rw-r--r--libguile/pthread-threads.h10
-rw-r--r--libguile/threads.h6
3 files changed, 18 insertions, 3 deletions
diff --git a/libguile/null-threads.h b/libguile/null-threads.h
index 116b845a5..4779ee033 100644
--- a/libguile/null-threads.h
+++ b/libguile/null-threads.h
@@ -3,7 +3,7 @@
#ifndef SCM_NULL_THREADS_H
#define SCM_NULL_THREADS_H
-/* Copyright (C) 2005, 2006, 2010 Free Software Foundation, Inc.
+/* Copyright (C) 2005, 2006, 2010, 2012 Free Software Foundation, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
@@ -102,6 +102,9 @@ SCM_API int scm_i_pthread_key_create (scm_i_pthread_key_t *key,
#define scm_i_scm_pthread_cond_wait scm_i_pthread_cond_wait
#define scm_i_scm_pthread_cond_timedwait scm_i_pthread_cond_timedwait
+#define SCM_DEFINE_ATFORK_HANDLERS_FOR_MUTEX(m,lock,unlock) /* noop */
+#define scm_i_pthread_atfork(pre,parent,child) do {} while (0)
+
#endif /* SCM_NULL_THREADS_H */
diff --git a/libguile/pthread-threads.h b/libguile/pthread-threads.h
index b5fae4e89..63b47b222 100644
--- a/libguile/pthread-threads.h
+++ b/libguile/pthread-threads.h
@@ -3,7 +3,7 @@
#ifndef SCM_PTHREADS_THREADS_H
#define SCM_PTHREADS_THREADS_H
-/* Copyright (C) 2002, 2005, 2006, 2011 Free Software Foundation, Inc.
+/* Copyright (C) 2002, 2005, 2006, 2011, 2012 Free Software Foundation, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
@@ -97,6 +97,14 @@ extern pthread_mutexattr_t scm_i_pthread_mutexattr_recursive[1];
#define scm_i_scm_pthread_cond_wait scm_pthread_cond_wait
#define scm_i_scm_pthread_cond_timedwait scm_pthread_cond_timedwait
+#define SCM_DEFINE_ATFORK_HANDLERS_FOR_MUTEX(m,lock,unlock) \
+ static void lock (void) { pthread_mutex_lock (m); } \
+ static void unlock (void) { pthread_mutex_unlock (m); }
+
+/* noop */
+#define scm_i_pthread_atfork(pre,parent,child) \
+ pthread_atfork (pre, parent, child)
+
#endif /* SCM_PTHREADS_THREADS_H */
/*
diff --git a/libguile/threads.h b/libguile/threads.h
index 54d64141b..f8404cfb6 100644
--- a/libguile/threads.h
+++ b/libguile/threads.h
@@ -3,7 +3,7 @@
#ifndef SCM_THREADS_H
#define SCM_THREADS_H
-/* Copyright (C) 1996,1997,1998,2000,2001, 2002, 2003, 2004, 2006, 2007, 2008, 2009, 2011 Free Software Foundation, Inc.
+/* Copyright (C) 1996,1997,1998,2000,2001, 2002, 2003, 2004, 2006, 2007, 2008, 2009, 2011, 2012 Free Software Foundation, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
@@ -130,6 +130,10 @@ typedef struct scm_i_thread {
#define SCM_VALIDATE_CONDVAR(pos, a) \
scm_assert_smob_type (scm_tc16_condvar, (a))
+#define SCM_PTHREAD_ATFORK_LOCK_STATIC_MUTEX(m) \
+ SCM_SNARF_HERE(SCM_DEFINE_ATFORK_HANDLERS_FOR_MUTEX(&m,lock_##m,unlock_##m))\
+ SCM_SNARF_INIT(scm_i_pthread_atfork (lock_##m, unlock_##m, unlock_##m);)
+
SCM_API SCM scm_spawn_thread (scm_t_catch_body body, void *body_data,
scm_t_catch_handler handler, void *handler_data);