*** empty log message ***
authorMatthew Mondor <mmondor@pulsar-zone.net>
Thu, 15 Sep 2005 11:46:58 +0000 (11:46 +0000)
committerMatthew Mondor <mmondor@pulsar-zone.net>
Thu, 15 Sep 2005 11:46:58 +0000 (11:46 +0000)
tests/pthread_utils/mm_pthread_msg.c
tests/pthread_utils/mm_pthread_msg.h
tests/pthread_utils/mm_pthread_poll.c

index 6dad6fb..74a5afa 100644 (file)
@@ -1,4 +1,4 @@
-/* $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
@@ -58,7 +58,7 @@
 
 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 $");
 
 
 
@@ -87,6 +87,16 @@ pthread_ring_init(pthread_ring_t *ring)
 }
 
 /*
+ * 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.
  */
@@ -195,6 +205,16 @@ pthread_port_init(pthread_port_t *port)
 }
 
 /*
+ * 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
@@ -249,6 +269,15 @@ pthread_msg_init(pthread_msg_t *msg, pthread_port_t *rport)
 }
 
 /*
+ * 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
index cd66e26..287bc2e 100644 (file)
@@ -1,4 +1,4 @@
-/* $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
@@ -84,17 +84,20 @@ typedef struct {
 
 
 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 *,
index 80abf60..1d29255 100644 (file)
@@ -1,4 +1,4 @@
-/* $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 $");
 
 
 
@@ -823,8 +823,8 @@ pthread_poll_ring(struct pollfd *fds, nfds_t nfds, int timeout,
  * 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
@@ -876,7 +876,7 @@ end:
                        (void) close(d);
                        d = -1;
                }
-               errno = error;
+               return error;
        }
 
        return d;
@@ -938,8 +938,7 @@ pthread_connect_ring(int s, const struct sockaddr *name, socklen_t namelen,
                /*
                 * 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;
        }