gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r2849 - in GNUnet/src: applications/advertising application


From: grothoff
Subject: [GNUnet-SVN] r2849 - in GNUnet/src: applications/advertising applications/fs/fsui util
Date: Fri, 19 May 2006 11:06:00 -0700 (PDT)

Author: grothoff
Date: 2006-05-19 11:05:57 -0700 (Fri, 19 May 2006)
New Revision: 2849

Modified:
   GNUnet/src/applications/advertising/bootstrap.c
   GNUnet/src/applications/fs/fsui/fsui-loader.c
   GNUnet/src/util/cron.c
   GNUnet/src/util/logging.c
   GNUnet/src/util/semaphore.c
Log:
more signaling improvements

Modified: GNUnet/src/applications/advertising/bootstrap.c
===================================================================
--- GNUnet/src/applications/advertising/bootstrap.c     2006-05-19 15:51:47 UTC 
(rev 2848)
+++ GNUnet/src/applications/advertising/bootstrap.c     2006-05-19 18:05:57 UTC 
(rev 2849)
@@ -40,8 +40,6 @@
 
 static PTHREAD_T pt;
 
-static int ptPID;
-
 static int abort_bootstrap = YES;
 
 typedef struct {
@@ -170,10 +168,9 @@
   }
 }
 
-static void processThread(void * unused) {
+static void * processThread(void * unused) {
   HelloListClosure cls;
 
-  ptPID = getpid();
   cls.helos = NULL;
   while (abort_bootstrap == NO) {
     while (abort_bootstrap == NO) {
@@ -196,7 +193,7 @@
         cls.helosCount);
     processhellos(&cls);
   }
-  ptPID = 0;
+  return NULL;
 }
 
 /**
@@ -209,7 +206,7 @@
   GNUNET_ASSERT(bootstrap != NULL);
   abort_bootstrap = NO;
   GNUNET_ASSERT(0 == PTHREAD_CREATE(&pt,
-                                   (PThreadMain)&processThread,
+                                   &processThread,
                                    NULL,
                                    8 * 1024)); 
 }
@@ -222,13 +219,7 @@
   void * unused;
 
   abort_bootstrap = YES;
-#if SOMEBSD || OSX || SOLARIS || MINGW
   PTHREAD_KILL(&pt, SIGALRM);
-#else
-  /* linux */
-  if (ptPID != 0)
-    kill(ptPID, SIGALRM);
-#endif
   PTHREAD_JOIN(&pt, &unused);
   coreAPI->releaseService(bootstrap);
   bootstrap = NULL;

Modified: GNUnet/src/applications/fs/fsui/fsui-loader.c
===================================================================
--- GNUnet/src/applications/fs/fsui/fsui-loader.c       2006-05-19 15:51:47 UTC 
(rev 2848)
+++ GNUnet/src/applications/fs/fsui/fsui-loader.c       2006-05-19 18:05:57 UTC 
(rev 2849)
@@ -49,6 +49,13 @@
   }
 #endif
 }
+static int parseOptions(int argc,
+                       char ** argv) {
+  FREENONNULL(setConfigurationString("GNUNET",
+                                    "LOGLEVEL",
+                                    "WARNING"));
+  return 0;
+}
 
 int main(int argc,
         char * argv[]) {
@@ -60,7 +67,7 @@
   }
   if(OK != initUtil(argc,
                    argv,
-                   NULL)) {
+                   &parseOptions)) {
     fprintf(stderr,
            "initUtil failed!\n");
     return -1;
@@ -70,9 +77,9 @@
                   YES,
                   &eventCallback,
                   NULL);
-  if (ctx != NULL)
+  if (ctx != NULL) {
     FSUI_stop(ctx);
-  else
+  } else
     fprintf(stderr,
            "FSUI_start failed!\n");
   stopCron();

Modified: GNUnet/src/util/cron.c
===================================================================
--- GNUnet/src/util/cron.c      2006-05-19 15:51:47 UTC (rev 2848)
+++ GNUnet/src/util/cron.c      2006-05-19 18:05:57 UTC (rev 2849)
@@ -116,27 +116,16 @@
  * The cron thread.
  */
 static int cron_shutdown = YES;
-static pid_t cronPID = 0;
 static Semaphore * cron_signal = NULL;
 static Semaphore * cron_signal_up = NULL;
 
 static PTHREAD_T cron_handle;
 
 
-
-/**
- * The main-method of cron, will NEVER terminate.
- */
-static void * cron();
-
 /* don't do anything, we use SIGALRM to abort
    the nanosleep */
 #ifndef WINDOWS
 static void sigalrmHandler(int sig) {
-#if DEBUG_CRON
-  LOG(LOG_CRON,
-      "Received signal 'SIGALRM'.\n");
-#endif
 }
 #else
 static void CALLBACK sigalrmHandler(DWORD sig) {
@@ -176,46 +165,12 @@
   memset(&sig, 0, sizeof(struct sigaction));
   memset(&old, 0, sizeof(struct sigaction));
   sig.sa_flags = SA_NODEFER;
-  sig.sa_handler = &sigalrmHandler;
+  sig.sa_handler =  &sigalrmHandler; 
   sigaction(SIGALRM, &sig, &old);
 #endif
   cron_signal_up = SEMAPHORE_NEW(0);
 }
 
-/**
- * Make sure to call stopCron before calling this method!
- */
-void doneCron() {
-  int i;
-
-  i = firstUsed_;
-  while (i != -1) {
-    FREENONNULL(deltaList_[i].data);
-    i = deltaList_[i].next;
-  }
-  MUTEX_DESTROY(&deltaListLock_);
-  MUTEX_DESTROY(&inBlockLock_);
-  FREE(deltaList_);
-  SEMAPHORE_FREE(cron_signal_up);
-  deltaList_ = NULL;
-}
-
-/**
- * Start the cron jobs.
- */
-void startCron() {
-  GNUNET_ASSERT(cron_signal == NULL);
-  cron_shutdown = NO;
-  cron_signal = SEMAPHORE_NEW(0);
-  if (0 != PTHREAD_CREATE(&cron_handle,
-                         (PThreadMain) cron,
-                         NULL,
-                         256 * 1024))
-    DIE_STRERROR("pthread_create");
-  /* large stack, we don't know for sure
-     what the cron jobs may be doing */
-}
-
 static void noJob(void * unused) {
 #if DEBUG_CRON
   LOG(LOG_CRON,
@@ -229,12 +184,15 @@
 void stopCron() {
   void * unused;
 
+#if DEBUG_CRON
+  LOG(LOG_INFO,
+      _("Stopping cron\n"));
+#endif
   cron_shutdown = YES;
   addCronJob(&noJob, 0, 0, NULL);
   SEMAPHORE_DOWN(cron_signal);
   SEMAPHORE_FREE(cron_signal);
   cron_signal = NULL;
-  cronPID = 0;
   PTHREAD_JOIN(&cron_handle, &unused);
 #if DEBUG_CRON
   LOG(LOG_INFO,
@@ -248,7 +206,8 @@
  * CronJob to suspend the cron thread
  * until it is resumed.
  */
-static void block(Semaphore * sig) {
+static void block(void * sem) {
+  Semaphore * sig = sem;
   int ok = SYSERR;
 
   if (sig != NULL)
@@ -277,7 +236,7 @@
   inBlock++;
   if (inBlock == 1) {
     blockSignal = SEMAPHORE_NEW(0);
-    addCronJob((CronJob)&block,
+    addCronJob(&block,
               0,
               0,
               blockSignal);
@@ -313,27 +272,45 @@
 }
 
 static void abortSleep() {
-#if DEBUG_CRON
-  LOG(LOG_CRON,
-      "Sending signal to pid %d\n",
-      cronPID);
-#endif
-  if (! isCronRunning())
-    return;
+  if (cron_signal == NULL)
+    return; /* cron_handle not valid */
 #ifdef WINDOWS
   QueueUserAPC((PAPCFUNC) sigalrmHandler,
               IsWinNT() ? 0 : GetCurrentThread(), 0);
-#elif SOMEBSD || OSX || SOLARIS
-  PTHREAD_KILL(&cron_handle, SIGALRM);
 #else
-  /* linux */
-  if (cronPID != 0)
-    kill(cronPID, SIGALRM);
+  PTHREAD_KILL(&cron_handle, SIGALRM);
 #endif
 }
 
 
+#if HAVE_PRINT_CRON_TAB
+/**
+ * Print the cron-tab.
+ */
+void printCronTab() {
+  int jobId;
+  UTIL_cron_DeltaListEntry * tab;
+  cron_t now;
 
+  cronTime(&now);
+  MUTEX_LOCK(&deltaListLock_);
+
+  jobId = firstUsed_;
+  while (jobId != -1) {
+    tab = &deltaList_[jobId];
+    LOG(LOG_CRON,
+       "%3u: delta %8lld CU --- method %p --- repeat %8u CU\n",
+       jobId,
+       tab->delta - now,
+       (int)tab->method,
+       tab->deltaRepeat);
+    jobId = tab->next;
+  }
+  MUTEX_UNLOCK(&deltaListLock_);
+}
+#endif
+
+
 /**
  * If the specified cron-job exists in th delta-list, move it to the
  * head of the list.  If it is running, do nothing.  If it is does not
@@ -483,6 +460,9 @@
        = entry->next;
       entry->next = -1;
       MUTEX_UNLOCK(&deltaListLock_);
+#if HAVE_PRINT_CRON_TAB
+      printCronTab();
+#endif
       return;
     }
   }
@@ -490,42 +470,19 @@
   if (last == -1) {
     firstUsed_ = firstFree_;
     abortSleep();
-  } else
+  } else {
     deltaList_[last].next = firstFree_;
+#if HAVE_PRINT_CRON_TAB
+    printCronTab();
+#endif
+  }
   firstFree_
     = entry->next;
   entry->next = current;
   MUTEX_UNLOCK(&deltaListLock_);
 }
 
-#if HAVE_PRINT_CRON_TAB
 /**
- * Print the cron-tab.
- */
-void printCronTab() {
-  int jobId;
-  UTIL_cron_DeltaListEntry * tab;
-  cron_t now;
-
-  cronTime(&now);
-  MUTEX_LOCK(&deltaListLock_);
-
-  jobId = firstUsed_;
-  while (jobId != -1) {
-    tab = &deltaList_[jobId];
-    LOG(LOG_CRON,
-       "%3u: delta %8lld CU --- method %p --- repeat %8u CU\n",
-       jobId,
-       tab->delta - now,
-       (int)tab->method,
-       tab->deltaRepeat);
-    jobId = tab->next;
-  }
-  MUTEX_UNLOCK(&deltaListLock_);
-}
-#endif
-
-/**
  * Process the cron-job at the beginning of the waiting queue, that
  * is, remove, invoke, and re-insert if it is a periodical job. Make
  * sure the cron job is held when calling this method, but
@@ -589,11 +546,10 @@
 /**
  * The main-method of cron.
  */
-static void * cron() {
+static void * cron(void * unused) {
   cron_t now;
   cron_t next;
 
-  cronPID = getpid();
   while (cron_shutdown == NO) {
 #if HAVE_PRINT_CRON_TAB
     printCronTab();
@@ -649,7 +605,43 @@
   return NULL;
 }
 
+
 /**
+ * Make sure to call stopCron before calling this method!
+ */
+void doneCron() {
+  int i;
+
+  i = firstUsed_;
+  while (i != -1) {
+    FREENONNULL(deltaList_[i].data);
+    i = deltaList_[i].next;
+  }
+  MUTEX_DESTROY(&deltaListLock_);
+  MUTEX_DESTROY(&inBlockLock_);
+  FREE(deltaList_);
+  SEMAPHORE_FREE(cron_signal_up);
+  deltaList_ = NULL;
+}
+
+/**
+ * Start the cron jobs.
+ */
+void startCron() {
+  GNUNET_ASSERT(cron_signal == NULL);
+  cron_shutdown = NO;
+  cron_signal = SEMAPHORE_NEW(0);
+  if (0 != PTHREAD_CREATE(&cron_handle,
+                         &cron,
+                         NULL,
+                         256 * 1024))
+    DIE_STRERROR("pthread_create");
+  /* large stack, we don't know for sure
+     what the cron jobs may be doing */
+}
+
+
+/**
  * Remove all matching cron-jobs from the list. This method should
  * only be called while cron is suspended or stopped, or from a cron
  * job that deletes another cron job.  If cron is not suspended or

Modified: GNUnet/src/util/logging.c
===================================================================
--- GNUnet/src/util/logging.c   2006-05-19 15:51:47 UTC (rev 2848)
+++ GNUnet/src/util/logging.c   2006-05-19 18:05:57 UTC (rev 2849)
@@ -436,7 +436,6 @@
       lastlog = lcltime->tm_yday;
     }
 
-
     printTime();
     if (format[0] == ' ')
       FPRINTF(logfile, "%s:", gettext(loglevels[minLogLevel]));

Modified: GNUnet/src/util/semaphore.c
===================================================================
--- GNUnet/src/util/semaphore.c 2006-05-19 15:51:47 UTC (rev 2848)
+++ GNUnet/src/util/semaphore.c 2006-05-19 18:05:57 UTC (rev 2849)
@@ -332,6 +332,7 @@
 void PTHREAD_GET_SELF(PTHREAD_T * pt) {
   pt->internal = MALLOC(sizeof(pthread_t));
   *((pthread_t*)pt->internal) = pthread_self();
+  GNUNET_ASSERT(NULL != *((pthread_t*)pt->internal));
 }
 
 /**
@@ -439,10 +440,11 @@
 
   handle = pt->internal;
   if (handle == NULL) {
-    /*    BREAK(); */
+    BREAK();
     return;
   }
-  pthread_kill(*handle, signal);
+  if (0 != pthread_kill(*handle, signal))
+    LOG_STRERROR(LOG_ERROR, "pthread_kill");
 }
 
 





reply via email to

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