remove getter, make global static, add closure argument
authorChristian Grothoff <christian@grothoff.org>
Sun, 14 Aug 2011 11:12:46 +0000 (11:12 +0000)
committerChristian Grothoff <christian@grothoff.org>
Sun, 14 Aug 2011 11:12:46 +0000 (11:12 +0000)
src/include/gnunet_scheduler_lib.h
src/util/disk.h
src/util/scheduler.c

index 6b927bba8730f1665abddcd06d7f8a4b541f4100..723f8ca91490f4cc44289b3d3705d676af67a769 100644 (file)
@@ -198,16 +198,18 @@ typedef void (*GNUNET_SCHEDULER_Task) (void *cls,
  * Signature of the select function used by the scheduler.
  * GNUNET_NETWORK_socket_select matches it.
  *
+ * @param cls closure
  * @param rfds set of sockets to be checked for readability
  * @param wfds set of sockets to be checked for writability
  * @param efds set of sockets to be checked for exceptions
  * @param timeout relative value when to return
  * @return number of selected sockets, GNUNET_SYSERR on error
  */
-typedef int (*GNUNET_SCHEDULER_select) (struct GNUNET_NETWORK_FDSet *rfds,
-                                  struct GNUNET_NETWORK_FDSet *wfds,
-                                  struct GNUNET_NETWORK_FDSet *efds,
-                                  struct GNUNET_TIME_Relative timeout);
+typedef int (*GNUNET_SCHEDULER_select) (void *cls,
+                                       struct GNUNET_NETWORK_FDSet *rfds,
+                                       struct GNUNET_NETWORK_FDSet *wfds,
+                                       struct GNUNET_NETWORK_FDSet *efds,
+                                       struct GNUNET_TIME_Relative timeout);
 /**
  * Initialize and run scheduler.  This function will return when all
  * tasks have completed.  On systems with signals, receiving a SIGTERM
@@ -511,19 +513,13 @@ GNUNET_SCHEDULER_add_select (enum GNUNET_SCHEDULER_Priority prio,
 /**
  * Sets the select function to use in the scheduler (scheduler_select).
  *
- * @param new_select new select function to use
- * @return previously used select function
+ * @param new_select new select function to use (NULL to reset to default)
+ * @param new_select_cls closure for 'new_select'
  */
-GNUNET_SCHEDULER_select
-GNUNET_SCHEDULER_set_select (GNUNET_SCHEDULER_select new_select);
+void
+GNUNET_SCHEDULER_set_select (GNUNET_SCHEDULER_select new_select,
+                            void *new_select_cls);
 
-/**
- * Gets the select function currently used in the scheduler.
- *
- * @return currently used select function
- */
-GNUNET_SCHEDULER_select
-GNUNET_SCHEDULER_get_select ();
 
 #if 0                           /* keep Emacsens' auto-indent happy */
 {
index fee43abb8761aa50c1d71645f7d45eb4f42427fd..0f094e2896cbe71451a64b6f3603f5920317cc08 100644 (file)
@@ -28,8 +28,6 @@
   
 #include "gnunet_disk_lib.h"
 
-};
-
 /**
  * Retrieve OS file handle
  *
index 692c4f0b7a3656df5b0a3d6f89d151b1dde4a0ad..d7f9a293b7a9fc1589b636c3e24c3a88fcfab080 100644 (file)
@@ -247,36 +247,29 @@ static int current_lifeness;
 
 /**
  * Function to use as a select() in the scheduler.
- * Defaults to GNUNET_NETWORK_socket_select ()
+ * If NULL, we use GNUNET_NETWORK_socket_select ().
  */
-GNUNET_SCHEDULER_select scheduler_select = GNUNET_NETWORK_socket_select;
+static GNUNET_SCHEDULER_select scheduler_select;
+
+/**
+ * Closure for 'scheduler_select'.
+ */
+static void *scheduler_select_cls;
 
 /**
  * Sets the select function to use in the scheduler (scheduler_select).
  *
  * @param new_select new select function to use
- * @return previously used select function
+ * @return previously used select function, NULL for default
  */
-GNUNET_SCHEDULER_select
-GNUNET_SCHEDULER_set_select (GNUNET_SCHEDULER_select new_select)
+void
+GNUNET_SCHEDULER_set_select (GNUNET_SCHEDULER_select new_select,
+                            void *new_select_cls)
 {
-  GNUNET_SCHEDULER_select old_select = scheduler_select;
   scheduler_select = new_select;
-  if (scheduler_select == NULL)
-    scheduler_select = GNUNET_NETWORK_socket_select;
-  return old_select;
+  scheduler_select_cls = new_select_cls;
 }
 
-/**
- * Gets the select function currently used in the scheduler.
- *
- * @return currently used select function
- */
-GNUNET_SCHEDULER_select
-GNUNET_SCHEDULER_get_select ()
-{
-  return scheduler_select;
-}
 
 /**
  * Check that the given priority is legal (and return it).
@@ -839,7 +832,12 @@ GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *task_cls)
           /* no blocking, more work already ready! */
           timeout = GNUNET_TIME_UNIT_ZERO;
         }
-      ret = scheduler_select (rs, ws, NULL, timeout);
+      if (NULL == scheduler_select)
+       ret = GNUNET_NETWORK_socket_select (rs, ws, NULL, timeout);
+      else
+       ret = scheduler_select (scheduler_select_cls,
+                               rs, ws, NULL, 
+                               timeout);
       if (ret == GNUNET_SYSERR)
         {
           if (errno == EINTR)