commit: r292 - trunk/libspread

[email protected]
Newsgroups gmane.network.spread.cvs
Message-ID <[email protected]>
Author: jschultz
Date: 2006-02-14 20:28:26 -0500 (Tue, 14 Feb 2006)
New Revision: 292

Modified:
   trunk/libspread/fl.c
   trunk/libspread/fl_p.h
Log:
Changes to make Flush build correctly with or without multithreaded support.  If _REETRANT is not defined it assumes single threaded build and all the thread calls are macro replaced with nothing.  Otherwise, the normal StdUtil fcns are called.



Modified: trunk/libspread/fl.c
===================================================================
--- trunk/libspread/fl.c	2006-02-13 21:08:43 UTC (rev 291)
+++ trunk/libspread/fl.c	2006-02-15 01:28:26 UTC (rev 292)
@@ -45,9 +45,12 @@
 #include <fl_p.h>
 #include <stdutil/stdutil.h>
 
+#ifdef _REENTRANT
+static FL_MUTEX glob_conns_lock;
+#endif
+
 /* glob_conns is a look up table that maps mailboxes to fl_conn*s */
-static stdmutex glob_conns_lock;
-static stdhash  glob_conns      = STDHASH_STATIC_CONSTRUCT(sizeof(mailbox), sizeof(fl_conn*), NULL, NULL, 0);
+static stdhash  glob_conns = STDHASH_STATIC_CONSTRUCT(sizeof(mailbox), sizeof(fl_conn*), NULL, NULL, 0);
 
 /********************************* public flush layer interface ********************************/
 
@@ -88,7 +91,8 @@
 
   if (first_time) {
     first_time = STDFALSE;
-    ret = stdmutex_construct(&glob_conns_lock, STDMUTEX_FAST);
+    FL_MUTEX_construct(&glob_conns_lock, STDMUTEX_FAST);
+    ret = 0;
   }
 
   return ret;
@@ -119,13 +123,13 @@
     if ((conn = (fl_conn*) calloc(1, sizeof(fl_conn))) == 0)
       stderr_abort("(%s, %d): calloc(1, %u)\n", __FILE__, __LINE__, sizeof(fl_conn));
     
-    stdmutex_construct(&conn->reserve_lock, STDMUTEX_FAST);
+    FL_MUTEX_construct(&conn->reserve_lock, STDMUTEX_FAST);
     conn->reservations  = 0;
     conn->disconnecting = 0;
-    stdcond_construct(&conn->destroy_cond);
+    FL_COND_construct(&conn->destroy_cond);
     
-    stdmutex_construct(&conn->recv_lock, STDMUTEX_FAST);
-    stdmutex_construct(&conn->conn_lock, STDMUTEX_FAST);
+    FL_MUTEX_construct(&conn->recv_lock, STDMUTEX_FAST);
+    FL_MUTEX_construct(&conn->conn_lock, STDMUTEX_FAST);
     
     conn->mbox       = *mbox;
     conn->priority   = priority;
@@ -139,9 +143,9 @@
     stddll_construct(&conn->mess_queue, sizeof(gc_buff_mess*));             /* <gc_buff_mess*> */
     conn->bytes_queued = 0;
     
-    stdmutex_grab(&glob_conns_lock);                                         /* LOCK CONNS TAB */
+    FL_MUTEX_grab(&glob_conns_lock);                                         /* LOCK CONNS TAB */
     stdhash_insert(&glob_conns, 0, mbox, &conn);                   /* add mbox -> conn mapping */
-    stdmutex_drop(&glob_conns_lock);                                     /* UNLOCK CONNS TAB */
+    FL_MUTEX_drop(&glob_conns_lock);                                     /* UNLOCK CONNS TAB */
   }
 
   DEBUG(std_stkfprintf(stderr, -1, "FL_connect: ret %d\n", ret));
@@ -161,32 +165,32 @@
   int ret;
 
   DEBUG(std_stkfprintf(stderr, 1, "FL_disconnect: mbox %d\n", mbox));
-  stdmutex_grab(&glob_conns_lock);                                           /* LOCK CONNS TAB */
+  FL_MUTEX_grab(&glob_conns_lock);                                           /* LOCK CONNS TAB */
   if (!stdhash_is_end(&glob_conns, stdhash_find(&glob_conns, &hit, &mbox))) {              /* mbox found */
     conn = *(fl_conn**) stdhash_it_val(&hit);
     stdhash_erase(&glob_conns, &hit);                                 /* remove mbox -> fl_conn* mapping */
-    stdmutex_drop(&glob_conns_lock);                                     /* UNLOCK CONNS TAB */
+    FL_MUTEX_drop(&glob_conns_lock);                                     /* UNLOCK CONNS TAB */
     /* now threads cannot come behind us and make_reservations() on this fl_conn */
     
-    stdmutex_grab(&conn->reserve_lock);                                   /* LOCK RESERVE_LOCK */
+    FL_MUTEX_grab(&conn->reserve_lock);                                   /* LOCK RESERVE_LOCK */
     conn->disconnecting = 1;                                 /* set disconnection indicator */
     ret = SP_disconnect(mbox);                                /* unblock any blocked receivers */
     
     if (conn->reservations != 0) {                          /* WAIT if connection still in use */
       DEBUG(std_stkfprintf(stderr, 0, "Waiting for mbox(%d, %p) to no longer be in use: "
 			   "%d reservations!\n", mbox, conn, conn->reservations));
-      stdcond_wait(&conn->destroy_cond, &conn->reserve_lock);
+      FL_COND_wait(&conn->destroy_cond, &conn->reserve_lock);
     }
     assert(conn->reservations == 0);                         /* should be no more reservations */
 
     /* now, no other threads are using the connection -> safe to reclaim */
     DEBUG(std_stkfprintf(stderr, 0, "Mbox(%d, %p) no longer in use: reclaiming!\n", mbox, conn));
-    stdmutex_drop(&conn->reserve_lock);                               /* UNLOCK RESERVE_LOCK */
+    FL_MUTEX_drop(&conn->reserve_lock);                               /* UNLOCK RESERVE_LOCK */
     
-    stdmutex_destruct(&conn->reserve_lock);  /* recursively destroy fl_conn and sub-structures */
-    stdcond_destruct(&conn->destroy_cond);
-    stdmutex_destruct(&conn->recv_lock);
-    stdmutex_destruct(&conn->conn_lock);
+    FL_MUTEX_destruct(&conn->reserve_lock);  /* recursively destroy fl_conn and sub-structures */
+    FL_COND_destruct(&conn->destroy_cond);
+    FL_MUTEX_destruct(&conn->recv_lock);
+    FL_MUTEX_destruct(&conn->conn_lock);
     
     for (stdhash_begin(&conn->groups, &hit); !stdhash_is_end(&conn->groups, &hit); stdhash_it_next(&hit))
       free_fl_group(*(fl_group**) stdhash_it_val(&hit));
@@ -198,7 +202,7 @@
     
     free(conn);
   } else {
-    stdmutex_drop(&glob_conns_lock);                                     /* UNLOCK CONNS TAB */
+    FL_MUTEX_drop(&glob_conns_lock);                                     /* UNLOCK CONNS TAB */
     DEBUG(std_stkfprintf(stderr, 0, "FL ILLEGAL_SESSION(%d)\n", mbox));
     ret = ILLEGAL_SESSION; 
   }
@@ -738,28 +742,31 @@
   stdit hit;
   fl_conn *conn;
 
-  stdmutex_grab(&glob_conns_lock);                                 /* LOCK CONNS TAB */
+  FL_MUTEX_grab(&glob_conns_lock);                                 /* LOCK CONNS TAB */
 
-  if (stdhash_is_end(&glob_conns, stdhash_find(&glob_conns, &hit, &mbox)))     /* no such mbox */
-    return stdmutex_drop(&glob_conns_lock), (fl_conn*) 0;      /* UNLOCK CONNS TAB */
+  if (stdhash_is_end(&glob_conns, stdhash_find(&glob_conns, &hit, &mbox))) {    /* no such mbox */
+    FL_MUTEX_drop(&glob_conns_lock);
+    return (fl_conn*) 0;                                                        /* UNLOCK CONNS TAB */
+  }
 
   conn = *(fl_conn**) stdhash_it_val(&hit);
-  stdmutex_grab(&conn->reserve_lock);                           /* LOCK RESERVE_LOCK */
-  stdmutex_drop(&glob_conns_lock);                             /* UNLOCK CONNS TAB */
+  FL_MUTEX_grab(&conn->reserve_lock);                           /* LOCK RESERVE_LOCK */
+  FL_MUTEX_drop(&glob_conns_lock);                             /* UNLOCK CONNS TAB */
   if (!conn->disconnecting)                                /* check if disconnecting */
     ++conn->reservations;                               /* increment reservation cnt */
-  stdmutex_drop(&conn->reserve_lock);                       /* UNLOCK RESERVE_LOCK */
+  FL_MUTEX_drop(&conn->reserve_lock);                       /* UNLOCK RESERVE_LOCK */
 
   return !conn->disconnecting ? conn : 0;
 }
 
 /* Relinquish a reservation this thread owns on a connection. */
 static void cancel_reservation(fl_conn *conn) {
-  stdmutex_grab(&conn->reserve_lock);                           /* LOCK RESERVE_LOCK */
+  FL_MUTEX_grab(&conn->reserve_lock);                           /* LOCK RESERVE_LOCK */
   assert(conn->reservations != 0);
-  if (--conn->reservations == 0 && conn->disconnecting) /* decrement reservation cnt */
-    stdcond_wake_all(&conn->destroy_cond);               /* signal disconnector thread */
-  stdmutex_drop(&conn->reserve_lock);                       /* UNLOCK RESERVE_LOCK */
+  if (--conn->reservations == 0 && conn->disconnecting) { /* decrement reservation cnt */
+    FL_COND_wake_all(&conn->destroy_cond);               /* signal disconnector thread */
+  }
+  FL_MUTEX_drop(&conn->reserve_lock);                       /* UNLOCK RESERVE_LOCK */
 }
 
 /* Acquire a connection's conn lock. The caller must have an
@@ -774,9 +781,11 @@
    prevent self-deadlocks.  
 */
 static int acquire_conn_lock(fl_conn *conn) {
-  stdmutex_grab(&conn->conn_lock);                                 /* LOCK CONN_LOCK */
-  if (conn->disconnecting)                                  /* conn is disconnecting */
-    return stdmutex_drop(&conn->conn_lock), 0;
+  FL_MUTEX_grab(&conn->conn_lock);                                 /* LOCK CONN_LOCK */
+  if (conn->disconnecting) {                                /* conn is disconnecting */
+    FL_MUTEX_drop(&conn->conn_lock);
+    return 0;
+  }
 
   return 1;
 }
@@ -787,7 +796,7 @@
    any intervening calls to release_conn_lock on release.  
 */
 static void release_conn_lock(fl_conn *release) {
-  stdmutex_drop(&release->conn_lock);                            /* UNLOCK CONN_LOCK */
+  FL_MUTEX_drop(&release->conn_lock);                            /* UNLOCK CONN_LOCK */
 }
 
 /* Acquire a connection's recv lock. The caller must have an
@@ -804,9 +813,11 @@
    ENTER THE BODY OF FL_scat_recv!!  
 */
 static int acquire_recv_lock(fl_conn *conn) {
-  stdmutex_grab(&conn->recv_lock);           /* LOCK RECV_LOCK */
-  if (conn->disconnecting)                   /* conn is disconnecting */
-    return stdmutex_drop(&conn->recv_lock), 0;
+  FL_MUTEX_grab(&conn->recv_lock);           /* LOCK RECV_LOCK */
+  if (conn->disconnecting) {                 /* conn is disconnecting */
+    FL_MUTEX_drop(&conn->recv_lock);
+    return 0;
+  }
 
   return 1;
 }
@@ -817,7 +828,7 @@
    intervening calls to release_recv_lock on release.  
 */
 static void release_recv_lock(fl_conn *release) {
-  stdmutex_drop(&release->recv_lock);           /* UNLOCK RECV_LOCK */
+  FL_MUTEX_drop(&release->recv_lock);           /* UNLOCK RECV_LOCK */
 }
 
 static fl_group *add_group(fl_conn *conn, const char *group_name) {
@@ -1087,9 +1098,9 @@
   int grp_not_priv;                                           /* is grp not a private group ? */
   int ret, i;
 
-  int fix_scat = 0;                                      /* did I modify the user's scat? */
+  int fix_scat = 0;                                           /* did I modify the user's scat? */
   scatter *scat = (scatter*) user_scat;                           /* get rid of const warnings */
-  scat_element senders_elem;                   /* for copy of user's element I might overwrite */
+  scat_element senders_elem = { 0 };           /* for copy of user's element I might overwrite */
   char copy_buf[sizeof(group_id) + sizeof(int16) + MAX_GROUP_NAME];           /* append buffer */
   char *curr_ptr = copy_buf, *key;                             /* current pos in append buffer */
 

Modified: trunk/libspread/fl_p.h
===================================================================
--- trunk/libspread/fl_p.h	2006-02-13 21:08:43 UTC (rev 291)
+++ trunk/libspread/fl_p.h	2006-02-15 01:28:26 UTC (rev 292)
@@ -32,8 +32,6 @@
  *
  */
 
-
-
 #ifndef flush_p_h_2000_04_24_14_16_31_jschultz_at_cnds_jhu_edu
 #define flush_p_h_2000_04_24_14_16_31_jschultz_at_cnds_jhu_edu
 
@@ -42,13 +40,14 @@
    assume that all reasonable calls to stdutil fcns won't fail, and if
    they do (due to a system problem, such as malloc failing) they abort
    with an appropriate error message, line number, etc.
+
+   JLS 2006 - That's bad form for a library John. Oh well ... ;)
 */
 
 #include <fl.h>
 #include <scatp.h>
 #include <stdutil/stddefines.h>
 #include <stdutil/stderror.h>
-#include <stdutil/stdthread.h>
 #include <stdutil/stddll.h>
 #include <stdutil/stdhash.h>
 
@@ -56,6 +55,31 @@
 #define FL_MINOR_VERSION 0
 #define FL_PATCH_VERSION 0
 
+#ifdef _REENTRANT
+#  include <stdutil/stdthread.h>
+#  define FL_MUTEX                      stdmutex
+#  define FL_COND                       stdcond
+#  define FL_MUTEX_construct(mut, type) stdmutex_construct((mut), (type))
+#  define FL_MUTEX_destruct(mut)        stdmutex_destruct(mut)
+#  define FL_MUTEX_grab(mut)            stdmutex_grab(mut)
+#  define FL_MUTEX_drop(mut)            stdmutex_drop(mut)
+#  define FL_COND_construct(cond)       stdcond_construct(cond)
+#  define FL_COND_destruct(cond)        stdcond_destruct(cond)
+#  define FL_COND_wait(cond, mut)       stdcond_wait((cond), (mut))
+#  define FL_COND_wake_all(cond)        stdcond_wake_all(cond)
+#else
+#  define FL_MUTEX                      int
+#  define FL_COND                       int
+#  define FL_MUTEX_construct(mut, type)
+#  define FL_MUTEX_destruct(mut)
+#  define FL_MUTEX_grab(mut)
+#  define FL_MUTEX_drop(mut)
+#  define FL_COND_construct(cond)
+#  define FL_COND_destruct(cond)
+#  define FL_COND_wait(cond, mut)
+#  define FL_COND_wake_all(cond)
+#endif
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -215,13 +239,13 @@
 
 /* This struct contains all of the connection level context for a connection */
 typedef struct {
-  stdmutex reserve_lock;  /* protects reservations, disconnecting; destroy_cond's mutex */
+  FL_MUTEX reserve_lock;  /* protects reservations, disconnecting; destroy_cond's mutex */
   size_t   reservations;                    /* count of reservations on this connection */
   int      disconnecting;                     /* is this connection being disconnected? */
-  stdcond  destroy_cond;   /* disconnector thread waits on this until reservations == 0 */
+  FL_COND  destroy_cond;   /* disconnector thread waits on this until reservations == 0 */
 
-  stdmutex recv_lock;             /* used to serialize calls to FL_recv on a connection */
-  stdmutex conn_lock;            /* lock for access to the connection's data, see below */
+  FL_MUTEX recv_lock;             /* used to serialize calls to FL_recv on a connection */
+  FL_MUTEX conn_lock;            /* lock for access to the connection's data, see below */
 
   /* acquiring conn_lock allows a thread to examine everything below here */
   mailbox mbox;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.