[En-Nut-Discussion] NutEventPost and event queues

Harald Kipp harald.kipp at egnite.de
Tue Nov 25 17:14:12 CET 2003


Geir,

HANDLE is a pointer, define in sys/types.h as

   typedef void * HANDLE;

So you declare

   HANDLE semaphore;

If done as a global variable, it will be cleared to
zero by the C runtime during system start. Avoid
using

   HANDLE semaphore = 0;

like some C manuals demand. This creates additional
code with most compilers like AVRGCC.

Also note, that this is not a semaphore really,
but an event queue, which may be used to implement
different kind of semaphores.

If you set semaphore = NULL before calling NutEventWait()
or NutEventPost(), then you risk to put other threads,
which are already added to the queue, into an endless sleep.

Other event queues used in Nut/OS are declared inside
dynamically created structures, like TCPSOCKET. Typically
these structures are cleared after creation.

The IDE code had been done by Michael Fischer, who also
contributed some valuable enhancements to event queues.
If he is with us, he may be able to give additional hints.

I can't see, where the handle is cleared in lanc111.c.
But this code is one of the rare parts, where an event
queue is used as a mutex semaphore, something that had been
implemented by Michael for the first time (as far as I know).

Please let me know, if this doesn't fully answer your
question.

Harald





More information about the En-Nut-Discussion mailing list