#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "cm_setup.h"
#include "cm_error_handler.h"
#define SPIN_COUNT 50000000
typedef struct {
em_queue_t dest;
unsigned int seq;
} hello_event_t;
typedef struct {
em_eo_t this_eo;
em_eo_t other_eo;
int is_a;
char name[16];
} my_eo_context_t;
typedef struct {
em_queue_t queue;
} my_queue_context_t;
typedef struct {
em_pool_t pool;
my_eo_context_t eo_context_a;
my_eo_context_t eo_context_b;
my_queue_context_t queue_context_a;
my_queue_context_t queue_context_b;
em_queue_t queue_a;
} hello_shm_t;
HELLO_SHM_T__SIZE_ERROR);
hello_start(my_eo_context_t *eo_ctx, em_eo_t eo,
const em_eo_conf_t *conf);
hello_stop(my_eo_context_t *eo_ctx, em_eo_t eo);
static void
hello_receive_event(my_eo_context_t *eo_ctx, em_event_t event,
my_queue_context_t *q_ctx);
int main(int argc, char *argv[])
{
return cm_setup(argc, argv);
}
void test_init(const appl_conf_t *appl_conf)
{
(void)appl_conf;
if (core == 0) {
hello_shm = env_shared_reserve("HelloSharedMem",
sizeof(hello_shm_t));
} else {
hello_shm = env_shared_lookup("HelloSharedMem");
}
if (hello_shm == NULL) {
"Hello init failed on EM-core: %u",
} else if (core == 0) {
memset(hello_shm, 0, sizeof(hello_shm_t));
}
}
void test_start(const appl_conf_t *appl_conf)
{
em_eo_t eo_a, eo_b;
if (appl_conf->num_pools >= 1)
hello_shm->pool = appl_conf->pools[0];
else
APPL_PRINT("\n"
"***********************************************************\n"
"EM APPLICATION: '%s' initializing:\n"
" %s: %s() - EM-core:%d\n"
" Application running on %u EM-cores (procs:%u, threads:%u)\n"
" using event pool:%" PRI_POOL " - %s\n"
"***********************************************************\n"
"\n",
appl_conf->name, NO_PATH(__FILE__), __func__,
em_core_id(),
appl_conf->core_count, appl_conf->num_procs, appl_conf->num_threads,
hello_shm->pool, pool_name);
"Undefined application event pool!");
&hello_shm->eo_context_a);
test_fatal_if(eo_a ==
EM_EO_UNDEF,
"EO A creation failed!");
&hello_shm->eo_context_b);
test_fatal_if(eo_b ==
EM_EO_UNDEF,
"EO B creation failed!");
hello_shm->eo_context_a.this_eo = eo_a;
hello_shm->eo_context_a.other_eo = eo_b;
hello_shm->eo_context_a.is_a = 1;
hello_shm->eo_context_b.this_eo = eo_b;
hello_shm->eo_context_b.other_eo = eo_a;
hello_shm->eo_context_b.is_a = 0;
"EO A start:%" PRI_STAT " %" PRI_STAT "",
ret, start_ret);
"EO B start:%" PRI_STAT " %" PRI_STAT "",
ret, start_ret);
}
void test_stop(const appl_conf_t *appl_conf)
{
const em_eo_t eo_a = hello_shm->eo_context_a.this_eo;
const em_eo_t eo_b = hello_shm->eo_context_b.this_eo;
(void)appl_conf;
APPL_PRINT("%s() on EM-core %d\n", __func__, core);
APPL_EXIT_FAILURE("EO A stop failed!");
APPL_EXIT_FAILURE("EO B stop failed!");
}
void test_term(const appl_conf_t *appl_conf)
{
(void)appl_conf;
APPL_PRINT("%s() on EM-core %d\n", __func__, core);
if (core == 0) {
env_shared_free(hello_shm);
}
}
hello_start(my_eo_context_t *eo_ctx, em_eo_t eo,
const em_eo_conf_t *conf)
{
em_queue_t queue;
my_queue_context_t *q_ctx;
const char *queue_name;
(void)conf;
if (eo_ctx->is_a) {
queue_name = "queue A";
q_ctx = &hello_shm->queue_context_a;
} else {
queue_name = "queue B";
q_ctx = &hello_shm->queue_context_b;
}
NULL);
queue_name);
q_ctx->queue = queue;
test_fatal_if(status !=
EM_OK,
"Set queue context:%" PRI_STAT "\n"
test_fatal_if(status !=
EM_OK,
"EO add queue:%" PRI_STAT
"\n"
APPL_PRINT("Hello world started %s.\t"
eo_ctx->name, eo, queue);
if (eo_ctx->is_a) {
hello_shm->queue_a = queue;
} else {
em_event_t event;
hello_event_t *hello;
hello_shm->pool);
"Event allocation failed!");
hello->dest = queue;
hello->seq = 0;
status =
em_send(event, hello_shm->queue_a);
test_fatal_if(status !=
EM_OK,
"em_send():%" PRI_STAT
"\n"
status, eo, hello_shm->queue_a);
}
}
hello_stop(my_eo_context_t *eo_ctx, em_eo_t eo)
{
my_queue_context_t *q_ctx;
APPL_PRINT(
"Hello world stop on EM-core %d (%s, eo id %" PRI_EO ")\n",
if (eo_ctx->is_a)
q_ctx = &hello_shm->queue_context_a;
else
q_ctx = &hello_shm->queue_context_b;
APPL_EXIT_FAILURE("EO remove queue failed!");
APPL_EXIT_FAILURE("Queue delete failed!");
APPL_EXIT_FAILURE("EO delete failed!");
return stat;
}
static void
hello_receive_event(my_eo_context_t *eo_ctx, em_event_t event,
my_queue_context_t *q_ctx)
{
em_queue_t dest;
hello_event_t *hello;
(void)type;
if (unlikely(appl_shm->exit_flag)) {
return;
}
dest = hello->dest;
hello->dest = queue;
APPL_PRINT(
"Hello world from %s! My queue is %" PRI_QUEUE ".\t"
"I'm on core %02i. Event seq is %u.\n",
eo_ctx->name, q_ctx->queue,
em_core_id(), hello->seq++);
delay_spin(SPIN_COUNT);
if (unlikely(status !=
EM_OK)) {
test_fatal_if(!appl_shm->exit_flag,
"em_send():%" PRI_STAT "\n"
status, eo_ctx->this_eo, hello_shm->queue_a);
}
}