diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/library.c | 11 | ||||
-rw-r--r-- | common/library.h | 2 | ||||
-rw-r--r-- | common/mock.c | 1 |
3 files changed, 14 insertions, 0 deletions
diff --git a/common/library.c b/common/library.c index b7d6923..502ea98 100644 --- a/common/library.c +++ b/common/library.c @@ -63,6 +63,8 @@ p11_mutex_t p11_library_mutex; pthread_once_t p11_library_once = PTHREAD_ONCE_INIT; #endif +unsigned int p11_forkid = 1; + static char * thread_local_message (void) { @@ -103,6 +105,13 @@ _p11_library_get_thread_local (void) return local; } +static void +count_forks (void) +{ + /* Thread safe, executed in child, one thread exists */ + p11_forkid++; +} + void p11_library_init_impl (void) { @@ -111,6 +120,8 @@ p11_library_init_impl (void) p11_mutex_init (&p11_library_mutex); pthread_key_create (&thread_local, free); p11_message_storage = thread_local_message; + + pthread_atfork (NULL, NULL, count_forks); } void diff --git a/common/library.h b/common/library.h index 33a33fb..f87494d 100644 --- a/common/library.h +++ b/common/library.h @@ -44,6 +44,8 @@ extern p11_mutex_t p11_library_mutex; +extern unsigned int p11_forkid; + #define p11_lock() p11_mutex_lock (&p11_library_mutex); #define p11_unlock() p11_mutex_unlock (&p11_library_mutex); diff --git a/common/mock.c b/common/mock.c index 01e095d..a73ae9d 100644 --- a/common/mock.c +++ b/common/mock.c @@ -46,6 +46,7 @@ #include "debug.h" #include "dict.h" #include "array.h" +#include "library.h" #include <assert.h> #include <ctype.h> |