[gamin] GQueue not signal safe, atomic operations?

As the comment in gam_dnotify.c indicates, GQueue is not signal safe.
When there is little load this shouldn't be a problem.  In my stress
tests, however, I have noticed failures (see my email from yesterday
with the subject gam-poll.c rewrite).

I suggest that we use atomic operations.  Unfortunately, there is no
single API.  Glib has a very nice abstraction.  As it is easily
extracted from the code base for all of the architectures which glibc
supports, we can just source copy it into gamin.

I've attached a small (untested code snippet) as an example.


#include "atomic.h"

struct event {
    struct event *next;
    int fd;

struct event *head;

enqueue(int fd)
    struct event *e = xmalloc(sizeof(struct event));
    e->fd = fd;

	/* We don't need to do an atomic read here: if we get an
	   inconsistent result, the while predicate will fail.  */
	e->next = head;
    while (atomic_compare_and_exchange_bool_rel(&head, e, e->next));

struct e *
    struct event *e;

	e = head;
    while (atomic_compare_and_exchange_bool_rel(&head, e->next, e));

    return e;

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]