From 91c3ce6ca42b553e4220e934b11e2fa53c0bae5a Mon Sep 17 00:00:00 2001 From: Thomas Preud'homme Date: Thu, 11 Jun 2009 23:37:37 +0200 Subject: [PATCH] Fix in communication techniques bench * Producers now wait consumer when needed --- communication_techniques/include/common_comm.h | 3 +++ communication_techniques/include/shared_mem_comm.h | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/communication_techniques/include/common_comm.h b/communication_techniques/include/common_comm.h index 027d6e2..06935c4 100644 --- a/communication_techniques/include/common_comm.h +++ b/communication_techniques/include/common_comm.h @@ -6,6 +6,9 @@ #define CACHE_LINE_SIZE 128 #define BUF_SIZE CACHE_LINE_SIZE +#define likely(x) __builtin_expect(!!(x), 1) +#define unlikely(x) __builtin_expect(!!(x), 0) + extern volatile int cont; __BEGIN_DECLS diff --git a/communication_techniques/include/shared_mem_comm.h b/communication_techniques/include/shared_mem_comm.h index 95fc539..ec38cc8 100644 --- a/communication_techniques/include/shared_mem_comm.h +++ b/communication_techniques/include/shared_mem_comm.h @@ -24,9 +24,17 @@ __BEGIN_DECLS extern __thread uintptr_t *shared_space; extern __thread int prod_idx; +extern __thread int cons_idx; struct communication_assoc *create_comm_assoc(void); static inline void send(uintptr_t value) { + static __thread int local_cons_idx = 0; + + if (likely(((prod_idx + 1) % SHARED_SPACE_SIZE) == local_cons_idx)) + { + while (((prod_idx + 1) % SHARED_SPACE_SIZE) == cons_idx); + local_cons_idx = cons_idx; + } shared_space[prod_idx] = value; prod_idx = (prod_idx + 1) % SHARED_SPACE_SIZE; }