Skip to content

Commit

Permalink
libflux: switch msglist internals to ccan
Browse files Browse the repository at this point in the history
  • Loading branch information
garlick committed Oct 13, 2023
1 parent 467ed6d commit efce070
Showing 1 changed file with 11 additions and 29 deletions.
40 changes: 11 additions & 29 deletions src/common/libflux/msglist.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,18 @@
#include <errno.h>
#include <sys/eventfd.h>

#include "src/common/libczmqcontainers/czmq_containers.h"
#include "ccan/list/list.h"

#include "message.h"
#include "msglist.h"

struct flux_msglist {
zlistx_t *zl;
struct list_head *head;
int pollevents;
int pollfd;
uint64_t event;
};

static void *msg_duplicator (const void *item)
{
return (flux_msg_t *)flux_msg_incref (item);
}

static void msg_destructor (void **item)
{
if (item) {
flux_msg_decref (*item);
*item = NULL;
}
}
};

struct flux_msglist *flux_msglist_create (void)
{
Expand All @@ -49,21 +37,20 @@ struct flux_msglist *flux_msglist_create (void)
return NULL;
l->pollfd = -1;
l->pollevents = POLLOUT;
if (!(l->zl = zlistx_new ())) {
free (l);
errno = ENOMEM;
return NULL;
}
zlistx_set_destructor (l->zl, msg_destructor);
zlistx_set_duplicator (l->zl, msg_duplicator);
list_head_init (&l->head);
return l;
}

void flux_msglist_destroy (struct flux_msglist *l)
{
if (l) {
int saved_errno = errno;
zlistx_destroy (&l->zl);
flux_msg_t *msg = NULL;
flux_msg_t *next;
list_for_each_safe (&l->head, msg, next, list) {
list_del (&msg->list);
flux_msg_decref (msg);
}
if (l->pollfd >= 0)
close (l->pollfd);
free (l);
Expand Down Expand Up @@ -101,12 +88,7 @@ int flux_msglist_append (struct flux_msglist *l, const flux_msg_t *msg)
if (msglist_raise_event (l) < 0)
return -1;
}
if (!zlistx_add_end (l->zl, (flux_msg_t *)msg)) {
l->pollevents |= POLLERR;
msglist_raise_event (l);
errno = ENOMEM;
return -1;
}
list_add (&l->head, &msg->list);
return 0;
}

Expand Down

0 comments on commit efce070

Please sign in to comment.