How can I find my connection ID ??

Hi,

I don’t know if I’m so near the solution that I can’t see it but I
cannot figure out how to find the connection ID or channel ID of my
resource manager.

On one side I have a resource manager created by the simpliest way:

if ((tpp = create_thread_pool()) != NULL) {
if (init_database(database_path)) {
thread_pool_start(tpp);
}
}
}

I want the resource manager can receive a pulse so, I can do:

pulse_attach(dpp, 0, my_code, my_func, NULL);


Now, I want to generate the pulse with a timer. I can initialize it with
the convenient macro:

SIGEV_PULSE_INIT(&event, coid, SIGEV_PULSE_PRIO_INHERIT, my_code,
0);

My problem is know where I can find the connection ID or the channel ID
to send it to my dispatch handler?

thanks,
Alain.

You need to use message_connect(). Here’s some pseudo code:

timer_code = pulse_attach(dpp, MSG_FLAG_ALLOC_PULSE, 0, my_func, ac);
coid = message_connect(dpp, MSG_FLAG_SIDE_CHANNEL);

sig.sigev_notify = SIGEV_PULSE;
sig.sigev_coid = coid;
sig.sigev_priority = getprio();
sig.sigev_code = timer_code;
sig.sigev_value.sival_int = 0;

timer_create(CLOCK_REALTIME, &sig, &tmr);
timer_settime(tmr, 0, &to, 0);

-seanb

Alain Bonnefoy <alain.bonnefoy@icbt.com> wrote:
: Hi,

: I don’t know if I’m so near the solution that I can’t see it but I
: cannot figure out how to find the connection ID or channel ID of my
: resource manager.

: On one side I have a resource manager created by the simpliest way:

: if ((tpp = create_thread_pool()) != NULL) {
: if (init_database(database_path)) {
: thread_pool_start(tpp);
: }
: }
: }

: I want the resource manager can receive a pulse so, I can do:

: pulse_attach(dpp, 0, my_code, my_func, NULL);


: Now, I want to generate the pulse with a timer. I can initialize it with
: the convenient macro:

: SIGEV_PULSE_INIT(&event, coid, SIGEV_PULSE_PRIO_INHERIT, my_code,
: 0);

: My problem is know where I can find the connection ID or the channel ID
: to send it to my dispatch handler?

: thanks,
: Alain.

Sean Boudreau a écrit :

You need to use message_connect(). Here’s some pseudo code:

timer_code = pulse_attach(dpp, MSG_FLAG_ALLOC_PULSE, 0, my_func, ac);
coid = message_connect(dpp, MSG_FLAG_SIDE_CHANNEL);

sig.sigev_notify = SIGEV_PULSE;
sig.sigev_coid = coid;
sig.sigev_priority = getprio();
sig.sigev_code = timer_code;
sig.sigev_value.sival_int = 0;

timer_create(CLOCK_REALTIME, &sig, &tmr);
timer_settime(tmr, 0, &to, 0);

-seanb

I tried it, I call the following function after dispatch_create() and
resmgr_attach(). I haven’t any error during this procedure but nothing
happens. I don’t know what’s wrong here.
Unfortunately, psin doesn’t yet display any information about timers.

struct sigevent event;
struct itimerspec itime;

void init_diag_pulse(void){
int coid, pulse_code;
timer_t timerID;

dataServer_diagnosis.cps = SYSPAGE_ENTRY(qtime)->cycles_per_sec;

if ((pulse_code = pulse_attach(dpp, MSG_FLAG_ALLOC_PULSE, 0,
incr_sample_num_request_pulse, NULL)) == -1) {
int status = errno;
log_critical_error("%s: (pulse_attach)%s, %s\n", basename(FILE),
LINE, “”, status);
exit(status);
}

if ((coid = message_connect(dpp, MSG_FLAG_SIDE_CHANNEL)) == -1) {
int status = errno;
log_critical_error("%s: (message_connect)%s, %s\n",
basename(FILE), LINE, “”, status);
exit(status);
}

SIGEV_PULSE_INIT(&event, coid, SIGEV_PULSE_PRIO_INHERIT, pulse_code, 0);

if (timer_create(CLOCK_REALTIME, &event, &timerID) == -1) {
int status = errno;
log_critical_error("%s: (timer_create)%s, %s\n", FILE, LINE,
“”, status);
exit(status);
}

itime.it_value.tv_sec = 0;
itime.it_value.tv_nsec = 500000000;
itime.it_interval.tv_sec = 0;
itime.it_interval.tv_nsec = 500000000;

if (timer_settime(timerID, 0, &itime, NULL) == -1) {
int status = errno;
log_critical_error("%s: (timer_settime)%s, %s\n", FILE, LINE,
“”, status);
exit(status);
}
}

Any idea?

Thanks,
Alain.

Have you called thread_pool_create(), thread_pool_start()?
Here’s some real code:

-seanb


#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <stddef.h>
#define THREAD_POOL_PARAM_T dispatch_context_t
#include <sys/dispatch.h>

const char *my_arg1=“Got one\n”;
const char *my_arg2=“Got two\n”;

int code1, code2, coid;

dispatch_t *dpp;
int pulse_input(message_context_t *ctp, int code, unsigned flags, void *handle);
void * worker (void *arg);


int
main(int argc, char **argv) {
thread_pool_attr_t pool_attr;
thread_pool_t *tpp;
timer_t tmr;
struct sigevent sig;
struct itimerspec to= {{1, 0}, {1, 0}};


if((dpp = dispatch_create()) == NULL)
{
fprintf(stderr, “%s: Unable to allocate dispatch context.\n”,argv[0]);
return EXIT_FAILURE;
}

memset(&pool_attr, 0, sizeof pool_attr);
pool_attr.handle = dpp;
pool_attr.context_alloc = dispatch_context_alloc;
pool_attr.block_func = dispatch_block;
pool_attr.handler_func = dispatch_handler;
pool_attr.context_free = dispatch_context_free;
pool_attr.lo_water = 1;
pool_attr.hi_water = 1;
pool_attr.increment = 0;
pool_attr.maximum = 1;

if((tpp = thread_pool_create(&pool_attr, POOL_FLAG_EXIT_SELF)) == NULL)
{
fprintf(stderr, “%s: Unable to initialize thread pool.\n”,argv[0]);
return EXIT_FAILURE;
}

if ((code1 = pulse_attach (dpp, MSG_FLAG_ALLOC_PULSE, 0, pulse_input, my_arg1)) == -1 ||
(code2 = pulse_attach (dpp, MSG_FLAG_ALLOC_PULSE, 0, pulse_input, my_arg2)) == -1)
{
fprintf(stderr, “Unable to attach pulse.\n”);
return EXIT_FAILURE;
}

if ((coid = message_connect(dpp, MSG_FLAG_SIDE_CHANNEL)) == -1 )
{
fprintf(stderr, “Unable to connect.\n”);
return EXIT_FAILURE;
}

sig.sigev_notify= SIGEV_PULSE;
sig.sigev_coid= coid;
sig.sigev_priority= getprio(0);
sig.sigev_code= code1;
sig.sigev_value.sival_int= 0;

if (timer_create(CLOCK_REALTIME, &sig, &tmr))
{
fprintf(stderr, “timer_create.\n”);
return EXIT_FAILURE;
}

if (timer_settime(tmr, 0, &to, 0) == -1)
{
fprintf(stderr, “timer_settime.\n”);
return EXIT_FAILURE;
}

pthread_create (NULL, NULL, worker, NULL);
// Never returns
thread_pool_start(tpp);
return 0;
}

void *
worker (void *arg)
{
int prio = getprio(0);

for(;:wink:
{
sleep(1);
MsgSendPulse(coid, prio, code2, 0);
}
}

int
pulse_input(message_context_t *ctp, int code, unsigned flags, void *handle)
{
printf("%s", (char *)handle);
return 0;
}

Alain Bonnefoy <alain.bonnefoy@icbt.com> wrote:

:> You need to use message_connect(). Here’s some pseudo code:
:>
:> timer_code = pulse_attach(dpp, MSG_FLAG_ALLOC_PULSE, 0, my_func, ac);
:> coid = message_connect(dpp, MSG_FLAG_SIDE_CHANNEL);
:>
:> sig.sigev_notify = SIGEV_PULSE;
:> sig.sigev_coid = coid;
:> sig.sigev_priority = getprio();
:> sig.sigev_code = timer_code;
:> sig.sigev_value.sival_int = 0;
:>
:> timer_create(CLOCK_REALTIME, &sig, &tmr);
:> timer_settime(tmr, 0, &to, 0);
:>
:> -seanb
:>
:>

: I tried it, I call the following function after dispatch_create() and
: resmgr_attach(). I haven’t any error during this procedure but nothing
: happens. I don’t know what’s wrong here.
: Unfortunately, psin doesn’t yet display any information about timers.

Sean Boudreau a écrit :

Have you called thread_pool_create(), thread_pool_start()?
Here’s some real code:

-seanb

#include <stdio.h
#include <stdlib.h
#include <unistd.h
#include <stddef.h
#define THREAD_POOL_PARAM_T dispatch_context_t
#include <sys/dispatch.h

const char *my_arg1=“Got one\n”;
const char *my_arg2=“Got two\n”;

int code1, code2, coid;

dispatch_t *dpp;
int pulse_input(message_context_t *ctp, int code, unsigned flags, void *handle);
void * worker (void *arg);

int
main(int argc, char **argv) {
thread_pool_attr_t pool_attr;
thread_pool_t *tpp;
timer_t tmr;
struct sigevent sig;
struct itimerspec to= {{1, 0}, {1, 0}};

if((dpp = dispatch_create()) == NULL)
{
fprintf(stderr, “%s: Unable to allocate dispatch context.\n”,argv[0]);
return EXIT_FAILURE;
}

memset(&pool_attr, 0, sizeof pool_attr);
pool_attr.handle = dpp;
pool_attr.context_alloc = dispatch_context_alloc;
pool_attr.block_func = dispatch_block;
pool_attr.handler_func = dispatch_handler;
pool_attr.context_free = dispatch_context_free;
pool_attr.lo_water = 1;
pool_attr.hi_water = 1;
pool_attr.increment = 0;
pool_attr.maximum = 1;

if((tpp = thread_pool_create(&pool_attr, POOL_FLAG_EXIT_SELF)) == NULL)
{
fprintf(stderr, “%s: Unable to initialize thread pool.\n”,argv[0]);
return EXIT_FAILURE;
}

if ((code1 = pulse_attach (dpp, MSG_FLAG_ALLOC_PULSE, 0, pulse_input, my_arg1)) == -1 ||
(code2 = pulse_attach (dpp, MSG_FLAG_ALLOC_PULSE, 0, pulse_input, my_arg2)) == -1)
{
fprintf(stderr, “Unable to attach pulse.\n”);
return EXIT_FAILURE;
}

if ((coid = message_connect(dpp, MSG_FLAG_SIDE_CHANNEL)) == -1 )
{
fprintf(stderr, “Unable to connect.\n”);
return EXIT_FAILURE;
}

sig.sigev_notify= SIGEV_PULSE;
sig.sigev_coid= coid;
sig.sigev_priority= getprio(0);
sig.sigev_code= code1;
sig.sigev_value.sival_int= 0;

if (timer_create(CLOCK_REALTIME, &sig, &tmr))
{
fprintf(stderr, “timer_create.\n”);
return EXIT_FAILURE;
}

if (timer_settime(tmr, 0, &to, 0) == -1)
{
fprintf(stderr, “timer_settime.\n”);
return EXIT_FAILURE;
}

pthread_create (NULL, NULL, worker, NULL);
// Never returns
thread_pool_start(tpp);
return 0;
}

void *
worker (void *arg)
{
int prio = getprio(0);

for(;:wink:
{
sleep(1);
MsgSendPulse(coid, prio, code2, 0);
}
}

int
pulse_input(message_context_t *ctp, int code, unsigned flags, void *handle)
{
printf("%s", (char *)handle);
return 0;
}

Alain Bonnefoy <> alain.bonnefoy@icbt.com> > wrote:

Ok, I understood. After I saw your code, I looked at the doc and I saw that my problem came from my
thread pool initialization.
I used resmgr_handler() instead of dispatch_handler().

pool_attr_p->context_alloc = resmgr_context_alloc;
pool_attr_p->block_func = resmgr_block;
pool_attr_p->handler_func = resmgr_handler;
pool_attr_p->context_free = resmgr_context_free;

Thanks,
Alain.