gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r5133 - in GNUnet/src: include util/threads


From: gnunet
Subject: [GNUnet-SVN] r5133 - in GNUnet/src: include util/threads
Date: Sun, 24 Jun 2007 02:42:07 -0600 (MDT)

Author: grothoff
Date: 2007-06-24 02:42:05 -0600 (Sun, 24 Jun 2007)
New Revision: 5133

Modified:
   GNUnet/src/include/gnunet_util_threads.h
   GNUnet/src/util/threads/mutex.c
   GNUnet/src/util/threads/pthread.c
   GNUnet/src/util/threads/semaphore.c
Log:
report high-latency thread operations

Modified: GNUnet/src/include/gnunet_util_threads.h
===================================================================
--- GNUnet/src/include/gnunet_util_threads.h    2007-06-24 07:48:52 UTC (rev 
5132)
+++ GNUnet/src/include/gnunet_util_threads.h    2007-06-24 08:42:05 UTC (rev 
5133)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2001, 2002, 2003, 2004, 2005, 2006 Christian Grothoff (and other 
contributing authors)
+     (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007 Christian Grothoff (and 
other contributing authors)
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -57,6 +57,8 @@
 #define cronMONTHS ((cron_t)(30 * cronDAYS))
 #define cronYEARS ((cron_t)(365 * cronDAYS))
 
+#define REALTIME_LIMIT (100 * cronMILLIS)
+
 /**
  * Main method of a thread.
  */
@@ -108,16 +110,28 @@
                                void * arg,
                                unsigned int stackSize);
 
+
+
 /**
  * Wait for the other thread to terminate.  May only be called
  * once per created thread, the handle is afterwards invalid.
  *
  * @param ret set to the return value of the other thread.
  */
-void PTHREAD_JOIN(struct PTHREAD * handle,
-                 void ** ret);
+void PTHREAD_JOIN_FL_(struct PTHREAD * handle,
+                     void ** ret,
+                     const char * file,
+                     unsigned int line);
 
 /**
+ * Wait for the other thread to terminate.  May only be called
+ * once per created thread, the handle is afterwards invalid.
+ *
+ * @param ret set to the return value of the other thread.
+ */
+#define PTHREAD_JOIN(handle,ret) PTHREAD_JOIN_FL(a,b,__FILE__,__LINE__)
+
+/**
  * Sleep for the specified time interval.  PTHREAD_STOP_SLEEP can be
  * used to interrupt the sleep.  Caller is responsible to check that
  * the sleep was long enough.
@@ -142,8 +156,12 @@
 
 void MUTEX_DESTROY(struct MUTEX * mutex);
 
-void MUTEX_LOCK(struct MUTEX * mutex);
+void MUTEX_LOCK_FL(struct MUTEX * mutex,
+                  const char * file,
+                  unsigned int line);
 
+#define MUTEX_LOCK(mutex) MUTEX_LOCK_FL(mutex, __FILE__, __LINE__)
+
 void MUTEX_UNLOCK(struct MUTEX * mutex);
 
 struct SEMAPHORE * SEMAPHORE_CREATE(int value);
@@ -156,10 +174,38 @@
  * @return SYSERR if would block, otherwise
  *  new count value after change
  */
-int SEMAPHORE_DOWN(struct SEMAPHORE * sem,
-                  int mayblock);
+int SEMAPHORE_DOWN_FL(struct SEMAPHORE * sem,
+                     int mayblock,
+                     int longwait,
+                     const char * file,
+                     unsigned int line);
 
+
 /**
+ * @param block set to NO to never block (and
+ *        thus fail if semaphore counter is 0)
+ * @param longwait it is expected that this operation
+ *        may cause a long wait
+ * @return SYSERR if would block, otherwise
+ *  new count value after change
+ */
+#define SEMAPHORE_DOWN(sem, mayblock) SEMAPHORE_DOWN_FL(sem, mayblock, YES, 
__FILE__, __LINE__)
+
+
+/**
+ * Like SEMAPHORE_DOWN, just with the expectation
+ * that this operation does not take a long time.
+ * (used for debugging unexpected high-latency
+ * behavior).
+ *
+ * @param block set to NO to never block (and
+ *        thus fail if semaphore counter is 0)
+ * @return SYSERR if would block, otherwise
+ *  new count value after change
+ */
+#define SEMAPHORE_DOWN_FAST(sem, mayblock) SEMAPHORE_DOWN_FL(sem, mayblock, 
NO, __FILE__, __LINE__)
+
+/**
  * function increments the semaphore and signals any threads that
  * are blocked waiting a change in the semaphore.
  *

Modified: GNUnet/src/util/threads/mutex.c
===================================================================
--- GNUnet/src/util/threads/mutex.c     2007-06-24 07:48:52 UTC (rev 5132)
+++ GNUnet/src/util/threads/mutex.c     2007-06-24 08:42:05 UTC (rev 5133)
@@ -119,25 +119,26 @@
   FREE(mutex);
 }
 
-#define DEBUG_LOCK_DELAY NO
-
-void MUTEX_LOCK(Mutex * mutex) {
+void MUTEX_LOCK_FL(Mutex * mutex,
+                  const char * file,
+                  unsigned int line) {
   int ret;
-#if DEBUG_LOCK_DELAY
   cron_t start;
-#endif
+  cron_t end;
 
   GE_ASSERT(NULL, mutex != NULL);
-#if DEBUG_LOCK_DELAY
   start = get_time();
-#endif
   ret = pthread_mutex_lock(&mutex->pt);
-#if DEBUG_LOCK_DELAY
-  start = get_time() - start;
-  if (start > 10)
-    printf("Locking took %llu ms!\n",
-          start);
-#endif
+  end = get_time();
+  if ( (end - start > REALTIME_LIMIT) &&
+       (REALTIME_LIMIT != 0) ) {
+    GE_LOG(NULL,
+          GE_DEVELOPER | GE_WARNING | GE_IMMEDIATE,
+          _("Real-time delay violation (%llu ms) at %s:%u\n"),
+          end - start,
+          file,
+          line);
+  }  
   if (ret != 0) {
     if (ret == EINVAL)
       GE_LOG(NULL,

Modified: GNUnet/src/util/threads/pthread.c
===================================================================
--- GNUnet/src/util/threads/pthread.c   2007-06-24 07:48:52 UTC (rev 5132)
+++ GNUnet/src/util/threads/pthread.c   2007-06-24 08:42:05 UTC (rev 5133)
@@ -120,34 +120,30 @@
   return handle;
 }
 
-/**
- * Should we debug the time a join takes?
- * Useful for detecting missing PTHREAD_STOP_SLEEPS
- * and similar signaling operations.
- */
-#define DEBUG_JOIN_DELAY NO
-
-void PTHREAD_JOIN(PThread * handle,
-                 void ** ret) {
-#if DEBUG_JOIN_DELAY
+void PTHREAD_JOIN_FL(PThread * handle,
+                    void ** ret,
+                    const char * file,
+                    unsigned int line) {
   cron_t start;
-#endif
+  cron_t end;
   int k;
 
   GE_ASSERT(NULL,
            handle != NULL);
   GE_ASSERT(NULL,
            NO == PTHREAD_TEST_SELF(handle));
-#if DEBUG_JOIN_DELAY
   start = get_time();
-#endif
   k = pthread_join(handle->pt, ret);
-#if DEBUG_JOIN_DELAY
-  start = get_time() - start;
-  if (start > 10)
-    printf("Join took %llu ms\n",
-          start);
-#endif
+  end = get_time();
+  if ( (end - start > REALTIME_LIMIT) &&
+       (REALTIME_LIMIT != 0) ) {
+    GE_LOG(NULL,
+          GE_DEVELOPER | GE_WARNING | GE_IMMEDIATE,
+          _("Real-time delay violation (%llu ms) at %s:%u\n"),
+          end - start,
+          file,
+          line);
+  }
   FREE(handle);
   switch (k) {
   case 0:

Modified: GNUnet/src/util/threads/semaphore.c
===================================================================
--- GNUnet/src/util/threads/semaphore.c 2007-06-24 07:48:52 UTC (rev 5132)
+++ GNUnet/src/util/threads/semaphore.c 2007-06-24 08:42:05 UTC (rev 5133)
@@ -142,11 +142,17 @@
   return ret;
 }
 
-int SEMAPHORE_DOWN(Semaphore * s,
-                  int mayblock) {
+int SEMAPHORE_DOWN_FL(Semaphore * s,
+                     int mayblock,
+                     int longwait,
+                     const char * file,
+                     unsigned int line) {
   int ret;
-
+  cron_t start;
+  cron_t end;
+  
   GE_ASSERT(NULL, s != NULL);
+  start = get_time();
   GE_ASSERT(NULL,
            0 == pthread_mutex_lock(&s->mutex));
   while ( (s->v <= 0) && mayblock)
@@ -159,6 +165,17 @@
     ret = SYSERR;
   GE_ASSERT(NULL,
            0 == pthread_mutex_unlock(&s->mutex));
+  end = get_time();
+  if ( (longwait == NO) &&
+       (end - start > REALTIME_LIMIT) &&
+       (REALTIME_LIMIT != 0) ) {
+    GE_LOG(NULL,
+          GE_DEVELOPER | GE_WARNING | GE_IMMEDIATE,
+          _("Real-time delay violation (%llu ms) at %s:%u\n"),
+          end - start,
+          file,
+          line);
+  }  
   return ret;
 }
 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]