-/* $Id: mm_pthread_msg.c,v 1.2 2005/09/12 12:00:05 mmondor Exp $ */
+/* $Id: mm_pthread_msg.c,v 1.3 2005/09/15 11:46:58 mmondor Exp $ */
/*
* Copyright (C) 2005, Matthew Mondor
MMCOPYRIGHT("@(#) Copyright (c) 2005\n\
\tMatthew Mondor. All rights reserved.\n");
-MMRCSID("$Id: mm_pthread_msg.c,v 1.2 2005/09/12 12:00:05 mmondor Exp $");
+MMRCSID("$Id: mm_pthread_msg.c,v 1.3 2005/09/15 11:46:58 mmondor Exp $");
}
/*
+ * Returns TRUE if the supplied ring is a valid/usable one, or FALSE
+ * otherwise. Useful to conditionally destroy it.
+ */
+int
+pthread_ring_valid(pthread_ring_t *ring)
+{
+ return (ring != NULL && ring->magic == PRING_MAGIC);
+}
+
+/*
* Destroys a ring. Note that all message ports attached to this ring should
* first be detached or destroyed.
*/
}
/*
+ * Returns TRUE if the supplied port is valid/usable, or FALSE otherwise.
+ * Useful to conditionally destroy a port, for instance.
+ */
+int
+pthread_port_valid(pthread_port_t *port)
+{
+ return (port != NULL && port->magic == PPORT_MAGIC);
+}
+
+/*
* Destroys the specified port, previously created using pthread_port_init().
*/
int
}
/*
+ * Returns TRUE if supplied message is valid/usable or FALSE otherwise.
+ */
+int
+pthread_msg_valid(pthread_msg_t *msg)
+{
+ return (msg != NULL && msg->magic == PMESG_MAGIC);
+}
+
+/*
* Invalidates a message, so that it can no longer be sent over ports.
*/
int
-/* $Id: mm_pthread_msg.h,v 1.2 2005/09/12 12:00:05 mmondor Exp $ */
+/* $Id: mm_pthread_msg.h,v 1.3 2005/09/15 11:46:58 mmondor Exp $ */
/*
* Copyright (C) 2005, Matthew Mondor
extern int pthread_ring_init(pthread_ring_t *);
+extern int pthread_ring_valid(pthread_ring_t *);
extern int pthread_ring_destroy(pthread_ring_t *);
extern int pthread_ring_wait(pthread_ring_t *,
const struct timespec *);
extern int pthread_ring_notify(pthread_ring_t *);
extern int pthread_port_init(pthread_port_t *);
+extern int pthread_port_valid(pthread_port_t *);
extern int pthread_port_destroy(pthread_port_t *);
extern int pthread_port_set_ring(pthread_port_t *,
pthread_ring_t *);
extern int pthread_msg_init(pthread_msg_t *,
pthread_port_t *);
+extern int pthread_msg_valid(pthread_msg_t *);
extern int pthread_msg_destroy(pthread_msg_t *);
extern pthread_msg_t *pthread_msg_get(pthread_port_t *);
extern int pthread_msg_put(pthread_port_t *,
-/* $Id: mm_pthread_poll.c,v 1.2 2005/09/12 12:00:05 mmondor Exp $ */
+/* $Id: mm_pthread_poll.c,v 1.3 2005/09/15 11:46:58 mmondor Exp $ */
/*
* Copyright (C) 2005, Matthew Mondor
MMCOPYRIGHT("@(#) Copyright (c) 2005\n\
\tMatthew Mondor. All rights reserved.\n");
-MMRCSID("$Id: mm_pthread_poll.c,v 1.2 2005/09/12 12:00:05 mmondor Exp $");
+MMRCSID("$Id: mm_pthread_poll.c,v 1.3 2005/09/15 11:46:58 mmondor Exp $");
* via pthread_ring_t events. Internally implemented using
* pthread_poll_ring(). Will internally set the descriptor in non-blocking
* mode if necessary, then reverting it to the mode it was supplied in.
- * Returns a new descriptor on success, or -1 on failure, in which case
- * errno will be set to either EINVAL, ETIMEDOUT, ECANCELLED, or others.
+ * Returns a new descriptor on success, or a negative value, which can be
+ * EINVAL, ETIMEDOUT, ECANCELLED, or others.
* Timeout is in milliseconds, like for poll(2) and can be -1.
*/
int
(void) close(d);
d = -1;
}
- errno = error;
+ return error;
}
return d;
/*
* connect(2) completed, return result
*/
- if (getsockopt(s, SOL_SOCKET, SO_ERROR, &error, &l)
- == -1)
+ if (getsockopt(s, SOL_SOCKET, SO_ERROR, &error, &l) == -1)
error = errno;
}