TIMER PROBLEM

My process is creating 5 timers using timer_create function but how will come to know which timer is expiring.

i was thinking of passing timer_id in pulse through sigevent structure but we need to intialise the structure before calling timer_create function.

so please give me idea how can i achieve this one.thanks in advance.

I think you answered your own question. Why not number the pulses 1, 2, 3, 4, 5?

Rahul,

This is how I do it:

timer_t mTimerId;
struct sigevent event;
SIGEV_PULSE_INIT(&event, ConnectAttach_r(ND_LOCAL_NODE, 0, mChannelId, _NTO_SIDE_CHANNEL, 0), SIGEV_PULSE_PRIO_INHERIT, 0, userId);
	
mTimerId = TimerCreate_r(CLOCK_REALTIME, &event));

Where:

mChannelId: is the channel created or passed your function (created via ChannelCreate() call). This is where the pulse will be delivered when the timer expires.

userId: is a unique identifier for your timer (1-5 in your case) so that you can identify which timer expires.

Then in your message handling code that receives messages/timer pulses you will have something like:

struct Message
{
    // This structure contains timer events
    struct _pulse timerPulse;

    // This structure contains event message data (our data in a message)
    Event data;
};

Message msg;
int mRecvId;

if ((mRecvId = MsgReceive_r(mChannelId, &msg, sizeof(Message), NULL)) < 0)
{
    printf ("error");
}
else
{
    // Determine if we received a message or timer pulse
    if (mRecvId == 0)
    {
        switch (msg.timerPulse.code)
       {
           case _PULSE_CODE_DISCONNECT:
              // Remote side disconnecting via name_close() from a 
              // name_open (this only occurs for a server process)
              ConnectDetach_r(msg.timerPulse.scoid);
              break;
          case _PULSE_CODE_UNBLOCK:
                // Sender hit by a signal so release them to process it
                Message emptyReply;
                reply(emptyReply);
                break;
          case _PULSE_CODE_THREADDEATH:
          case _PULSE_CODE_COIDDEATH:
                // Remote side died/exited!
                 break;
          default:
               // Timer pulse received
              processTimeout(msg.timerPulse.value.sival_int);
          break;
        }
    }
    else
    {
        // Actual message data.
    }
}

Where:

msg.timerPulse.value.sival_int is your unique timer id that was userId above.

Note that I cut out all code processing actual message data and omitted some error checks to simplify the code.

Tim