From 559fe1daace8f48a8dc37906f840e9981b961415 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 26 Jul 2014 20:29:48 +0200 Subject: Add Plan 9-style barriers Plan 9 has a very interesting synchronization mechanism, the rendezvous() call. A good property of this is that you don't need to explicitly initialize and destroy a barrier object, unlike as with e.g. POSIX barriers (which are mandatory to begin with). Upon "meeting", they can exchange a value. This mechanism will be nice to synchronize certain stages of initialization between threads in the following commit. Unlike Plan 9 rendezvous(), this is not implemented with a hashtable, because that would require additional effort (especially if you want to make it actually scele). Unlike the Plan 9 variant, we use intptr_t instead of void* as type for the value, because I expect that we will be mostly passing a status code as value and not a pointer. Converting an integer to void* requires two cast (because the integer needs to be intptr_t), the other way around it's only one cast. We don't particularly care about performance in this case either. It's simply not important for our use-case. So a simple linked list is used for waiters, and on wakeup, all waiters are temporarily woken up. --- misc/rendezvous.h | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 misc/rendezvous.h (limited to 'misc/rendezvous.h') diff --git a/misc/rendezvous.h b/misc/rendezvous.h new file mode 100644 index 0000000000..ffcc89a22c --- /dev/null +++ b/misc/rendezvous.h @@ -0,0 +1,8 @@ +#ifndef MP_RENDEZVOUS_H_ +#define MP_RENDEZVOUS_H_ + +#include + +intptr_t mp_rendezvous(void *tag, intptr_t value); + +#endif -- cgit v1.2.3