Re: Synchronous signal delivery..

Werner Almesberger
2003-02-15T04:15:52Z

Giuliano Pochini wrote:
> IMHO it's not simply a signal delivery system, it's a message queue.

Not entirely, because - as I understand it - signals would be
aggregated, so you'd always get one item, no matter how many
signals are actually pending at that time.

For generalizing such mechanisms, it might be useful to have
an atomic "overwrite" operation for pipes, and maybe also for
some sockets, e.g. something like this:

ssize_t overwrite(int fd,
const void *data_if_empty,size_t size_if_empty,
const void *data_if_full,size_t size_if_full,
int *was_empty);

If there is no data in the pipe/queue, "overwrite" would
write "data_if_empty", and clear *was_empty. Otherwise, it
would discard what's there, then write "data_if_full", and
set *was_empty. The whole operation is atomic with respect
to readers/pollers.

E.g.

static int signal_set = 0;

... add_signal(int signum)
{
int new_signal = 1 << signum;
int was_empty;

signal_set |= new_signal;
overwrite(fd,&new_signal,sizeof(int),&signal_set,sizeof(int),
&was_empty);
if (was_empty)
signal_set = new_signal;
}

- Werner

--
_________________________________________________________________________
/ Werner Almesberger, Buenos Aires, Argentina wa@almesberger.net /
/_http://www.almesberger.net/____________________________________________/