More uniformity in communication techniques bench
* Only use 2 * BUF_SIZE bytes for shared_memory
This commit is contained in:
parent
02db9b77f6
commit
12494e2fbc
|
@ -7,6 +7,7 @@
|
|||
#include <common_comm.h>
|
||||
|
||||
#define SHARED_SPACE_SIZE (2 * BUF_SIZE)
|
||||
#define SHARED_SPACE_UINTPTR (SHARED_SPACE_SIZE / sizeof(uintptr_t))
|
||||
|
||||
struct communication_assoc
|
||||
{
|
||||
|
@ -28,9 +29,9 @@ extern __thread volatile int cons_idx;
|
|||
|
||||
struct communication_assoc *create_comm_assoc(void);
|
||||
static inline void send(uintptr_t value) {
|
||||
while ((prod_idx + 1) % SHARED_SPACE_SIZE == cons_idx);
|
||||
while ((prod_idx + 1) % SHARED_SPACE_UINTPTR == cons_idx);
|
||||
shared_space[prod_idx] = value;
|
||||
prod_idx = (prod_idx + 1) % SHARED_SPACE_SIZE;
|
||||
prod_idx = (prod_idx + 1) % SHARED_SPACE_UINTPTR;
|
||||
}
|
||||
|
||||
__END_DECLS
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <common_comm.h>
|
||||
|
||||
#define SHARED_SPACE_SIZE (2 * BUF_SIZE)
|
||||
#define SHARED_SPACE_UINTPTR (SHARED_SPACE_SIZE / sizeof(uintptr_t))
|
||||
|
||||
struct communication_assoc
|
||||
{
|
||||
|
@ -30,13 +31,13 @@ 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))
|
||||
if (likely(((prod_idx + 1) % SHARED_SPACE_UINTPTR) == local_cons_idx))
|
||||
{
|
||||
while (((prod_idx + 1) % SHARED_SPACE_SIZE) == cons_idx);
|
||||
while (((prod_idx + 1) % SHARED_SPACE_UINTPTR) == cons_idx);
|
||||
local_cons_idx = cons_idx;
|
||||
}
|
||||
shared_space[prod_idx] = value;
|
||||
prod_idx = (prod_idx + 1) % SHARED_SPACE_SIZE;
|
||||
prod_idx = (prod_idx + 1) % SHARED_SPACE_UINTPTR;
|
||||
}
|
||||
|
||||
__END_DECLS
|
||||
|
|
|
@ -16,7 +16,7 @@ struct communication_assoc *create_comm_assoc(void)
|
|||
{
|
||||
struct communication_assoc *assoc;
|
||||
|
||||
shared_space = (uintptr_t *) malloc(SHARED_SPACE_SIZE * sizeof(uintptr_t));
|
||||
shared_space = (uintptr_t *) malloc(SHARED_SPACE_SIZE);
|
||||
assoc = (struct communication_assoc *) malloc(sizeof(struct communication_assoc));
|
||||
assoc->tid = pthread_self();
|
||||
assoc->shared_space = shared_space;
|
||||
|
@ -39,7 +39,7 @@ void reception(void (*on_receive)(uintptr_t))
|
|||
{
|
||||
int cons_idx;
|
||||
|
||||
for(cons_idx = *cur->cons_idx; cons_idx != *cur->prod_idx; cons_idx = (cons_idx + 1) % SHARED_SPACE_SIZE, *cur->cons_idx = cons_idx)
|
||||
for(cons_idx = *cur->cons_idx; cons_idx != *cur->prod_idx; cons_idx = (cons_idx + 1) % SHARED_SPACE_UINTPTR, *cur->cons_idx = cons_idx)
|
||||
{
|
||||
uintptr_t tmp;
|
||||
tmp = cur->shared_space[cons_idx];
|
||||
|
|
|
@ -16,7 +16,7 @@ struct communication_assoc *create_comm_assoc(void)
|
|||
{
|
||||
struct communication_assoc *assoc;
|
||||
|
||||
shared_space = (uintptr_t *) malloc(SHARED_SPACE_SIZE * sizeof(uintptr_t));
|
||||
shared_space = (uintptr_t *) malloc(SHARED_SPACE_SIZE);
|
||||
assoc = (struct communication_assoc *) malloc(sizeof(struct communication_assoc));
|
||||
assoc->tid = pthread_self();
|
||||
assoc->shared_space = shared_space;
|
||||
|
@ -43,7 +43,7 @@ void reception(void (*on_receive)(uintptr_t))
|
|||
do
|
||||
{
|
||||
prod_idx = *cur->prod_idx;
|
||||
for(; cons_idx != prod_idx; cons_idx = (cons_idx + 1) % SHARED_SPACE_SIZE)
|
||||
for(; cons_idx != prod_idx; cons_idx = (cons_idx + 1) % SHARED_SPACE_UINTPTR)
|
||||
{
|
||||
uintptr_t tmp;
|
||||
tmp = cur->shared_space[cons_idx];
|
||||
|
|
Loading…
Reference in New Issue