Fix in communication techniques bench

* Producers now wait consumer when needed
This commit is contained in:
Thomas Preud'homme 2009-06-11 23:37:37 +02:00 committed by Thomas Preud'homme
parent 7e939d50da
commit 91c3ce6ca4
2 changed files with 11 additions and 0 deletions

View File

@ -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

View File

@ -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;
}