Defines | Functions

/home/sindre/dev_uclinux/suzaku_shared/hwos_sw/libhwos/hevent.h File Reference

[Hardware OS Event Interface] Notify and handle events between threads. More...

#include "hstructures.h"

Go to the source code of this file.

Defines

#define HEVENT_BLOCKING   1
#define HEVENT_NONBLOCKING   0

Functions

struct heventhevent_create (int blocking)
 Creates an event handler.
int hevent_notify (struct hevent *event, int notification)
 Notify an event.
int hevent_wait (struct hevent *event)
 Wait on event.
int hevent_remove (struct hevent *event)
 Remove an event handler.

Detailed Description

[Hardware OS Event Interface] Notify and handle events between threads.

This module contains functionality for handling events between threads. Events can be handled both blocking (asynchronously) or non-blocking (synchronously). The underlying implemenation use System V message queues.

Author (2011): Sindre Hansen

Definition in file hevent.h.


Function Documentation

struct hevent* hevent_create ( int  blocking  )  [read]

Creates an event handler.

Parameters:
async Set to true if hevent_wait should block while waiting for events.
Returns:
The event handler object.

Definition at line 23 of file hevent.c.

{
        if (blocking > 1 || blocking < 0)
                return NULL;

        struct hevent* event = calloc(1, sizeof(struct hevent));
        event->msqid = msgget(IPC_PRIVATE, 0644 | IPC_CREAT | IPC_EXCL);
        event->blocking = blocking;

        if (event->msqid == -1)
                return NULL;

        return event;
}

int hevent_notify ( struct hevent event,
int  notification 
)

Notify an event.

Parameters:
event Event handler.
notification The actual event/notification. Must be an integer.
Returns:
0 on success. Negative on failure.

Definition at line 39 of file hevent.c.

{
        if (event == NULL)
                return -1;

        struct hevent_msg msg;
        msg.mtype = 1;
        msg.mtext = notification;
        if (msgsnd(event->msqid, &msg, sizeof(msg.mtext), 0) == -1)
                return -1;

        return 0;
}

int hevent_remove ( struct hevent event  ) 

Remove an event handler.

Parameters:
event Event handler.
Returns:
0 on success. -1 on failure.

Definition at line 72 of file hevent.c.

{
        if (event == NULL)
                return -1;

        if (msgctl(event->msqid, IPC_RMID, NULL) == -1)
                return -1;
        else
                return 0;
}

int hevent_wait ( struct hevent event  ) 

Wait on event.

Wait may be performed in a blocking or non-blocking manner (see hevent_create).

Parameters:
event Event handler.
Returns:
The event on success. -1 on failure.

Definition at line 54 of file hevent.c.

{
        if (event == NULL)
                return -1;

        struct hevent_msg msg;

        int msgflg = IPC_NOWAIT;
        if (event->blocking)
                msgflg = 0;
        
        if (msgrcv(event->msqid, &msg, sizeof(msg.mtext), 0, msgflg) == -1)
                return -1;

        return msg.mtext;
}

 All Data Structures Files Functions Variables Enumerations Enumerator Defines