MESG_PORT(3)

NAME
mesg_port - generic message ports

LIBRARY
PDEL Library (libpdel, -lpdel)

SYNOPSIS
#include <pthread.h>
#include <pdel/util/mesg_port.h>
struct mesg_port *
mesg_port_create(const char *mtype);
void
mesg_port_destroy(struct mesg_port **portp);
int
mesg_port_put(struct mesg_port *port, void *data);
void *
mesg_port_get(struct mesg_port *port, int timeout);
u_int
mesg_port_qlen(struct mesg_port *port);

DESCRIPTION
These functions implement a message port for inter-thread communication.

mesg_port_create() creates a new messge port, using typed_mem(3) type mtype for internal memory allocation.

mesg_port_destroy() destroys the message port pointed to by *portp. There must be no messages in the message port, otherwise mesg_port_destroy() aborts with an assertion failure. Upon return, *portp will be set to NULL. If *portp is already NULL when mesg_port_destroy() is invoked, nothing happens.

mesg_port_put() writes the message represented by data to the message port pointed to by port. The data may not be NULL.

mesg_port_get() retrieves the next available message written to the message port pointed to by port. Messages are read in the same order as they are written. If there are no messages, mesg_port_get() waits for up to timeout milliseconds, or indefinitely if timeout is negative. The thread calling mesg_port_get() may be canceled without ill effect.

mesg_port_qlen() returns the current number of messages queued on the message port pointed to by port.

mesg_port_put(), mesg_port_get(), and mesg_port_qlen() may be called safely at the same time from different threads.

RETURN VALUES
mesg_port_create(), mesg_port_put(), and mesg_port_get() return NULL or -1 to indicate an error, with errno set appropriately.

SEE ALSO
libpdel(3), pevent(3), pthread(3), typed_mem(3)

HISTORY
The PDEL library was developed at Packet Design, LLC. http://www.packetdesign.com/

AUTHORS
Archie Cobbs <archie@freebsd.org>