updastes.
authorPekka Riikonen <priikone@silcnet.org>
Tue, 10 Jul 2001 12:55:12 +0000 (12:55 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Tue, 10 Jul 2001 12:55:12 +0000 (12:55 +0000)
lib/silcutil/silcschedule.c
lib/silcutil/silcschedule.h
lib/silcutil/silctask.c
lib/silcutil/silctask.h

index 046cfa3077aa88a9cbec040dbcbaaf114650f7c3..8146c1de0bd533747c4ee459fadd33e109a138c5 100644 (file)
 /* Routine to remove the task. Implemented in silctask.c. */
 int silc_task_remove(SilcTaskQueue queue, SilcTask task);
 
+/* Routine to compare task timeouts. Implemented in silctask.c. */
+int silc_task_timeout_compare(struct timeval *smaller, 
+                             struct timeval *bigger);
+
 /* System specific routines. Implemented under unix/ and win32/. */
 
 /* System specific select(). */
index 07549c477091459d939ca3aa9a7331699def6df3..21ec78271d4d87e7a67bbe0eccd973128c455951 100644 (file)
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
+ # DESCRIPTION
+ *
+ * The SILC Scheduler is the heart of any application. The scheduler provides
+ * the application's main loop that can handle incoming data, outgoing data,
+ * timeouts and dispatch different kind of tasks.
+ *
+ * The SILC Scheduler supports file descriptor based tasks, timeout tasks
+ * and generic tasks. File descriptor tasks are tasks that perform some 
+ * operation over the specified file descriptor. These include network 
+ * connections, for example. The timeout tasks are timeouts that are executed
+ * after the specified timeout has elapsed. The generic tasks are tasks that
+ * apply to all registered file descriptors thus providing one task that
+ * applies to many independent connections.
+ *
+ * The SILC Scheduler is designed to be the sole main loop of the application
+ * so that the application does not need any other main loop.  However,
+ * SILC Scheduler does support running the scheduler only once, so that the
+ * scheduler does not block, and thus providing a possiblity that some
+ * external main loop is run over the SILC Scheduler. However, these 
+ * applications are considered to be special cases.
+ *
+ * Typical application first initializes the scheduler and then registers
+ * the very first tasks to the scheduler and then run the scheduler.  After
+ * the scheduler's run function returns the application is considered to be 
+ * ended.
+ *
+ * The SILC Scheduler supports multi-threads as well. The actual scheduler
+ * must be run in single-thread but other threads may register new tasks
+ * and unregister old tasks.  However, it is enforced that the actual
+ * task is always run in the main thread.  The scheduler is context based
+ * which makes it possible to allocate several schedulers for one application.
+ * Since the scheduler must be run in single-thread, a multi-threaded
+ * application could be created by allocating own scheduler for each of the
+ * worker threads. However, in this case the schedulers must not share
+ * same task queues. Each of the schedulers must allocate their own
+ * task queues.
+ *
+ * See the SILC Task API for task management interface. It is used to 
+ * register and unregister the actual tasks.
+ *
  */
 
 #ifndef SILCSCHEDULE_H
@@ -54,11 +94,12 @@ typedef struct SilcScheduleStruct *SilcSchedule;
  *
  * DESCRIPTION
  *
- *    Initializes the scheduler. Sets the non-timeout task queue hook and
- *    the timeout task queue hook. This must be called before the scheduler
- *    is able to work. This will allocate the queue pointers if they are
- *    not allocated. Returns the scheduler context that must be freed by
- *    the silc_schedule_uninit function.
+ *    Initializes the scheduler. Sets the non-timeout task queue hook,
+ *    the timeout task queue hook, and the generic task queue hook. This 
+ *    must be called before the scheduler is able to work. This will
+ *    allocate the queue pointers if they are not allocated. Returns the
+ *    scheduler context that must be freed by the silc_schedule_uninit 
+ *    function.
  *
  ***/
 SilcSchedule silc_schedule_init(SilcTaskQueue *fd_queue,
@@ -153,7 +194,7 @@ void silc_schedule(SilcSchedule schedule);
  *    Same as the silc_schedule but runs the scheduler only one round
  *    and then returns.  This function is handy when the SILC scheduler
  *    is used inside some other external scheduler, for example.  If
- *    the `timeout_usecs' is positive a timeout will be added to the
+ *    the `timeout_usecs' is non-negative a timeout will be added to the
  *    scheduler.  The function will not return in this timeout unless
  *    some other event occurs.
  *
index c210ffef59338d2056ac773afd6b7abc4326933f..36bf5d498bcd0c487ef16c905535a6f9b3e45add 100644 (file)
 
 #include "silcincludes.h"
 
+/* Routine to compare task timeouts. */
+int silc_task_timeout_compare(struct timeval *smaller, 
+                             struct timeval *bigger);
+
 /* Allocates a new task queue into the Silc. If 'valid' is TRUE the
    queue becomes valid task queue. If it is FALSE scheduler will skip
    the queue. */
@@ -62,8 +66,8 @@ void silc_task_queue_wakeup(SilcTaskQueue queue)
    by silc_task_register function. Returns a pointer to the registered 
    task. */
 
-SilcTask silc_task_add(SilcTaskQueue queue, SilcTask new, 
-                      SilcTaskPriority priority)
+static SilcTask silc_task_add(SilcTaskQueue queue, SilcTask new, 
+                             SilcTaskPriority priority)
 {
   SilcTask task, next, prev;
 
@@ -147,8 +151,8 @@ static SilcTask silc_task_get_first(SilcTaskQueue queue, SilcTask first)
    order. The priority matters if there are more than one task with
    same timeout. */
 
-SilcTask silc_task_add_timeout(SilcTaskQueue queue, SilcTask new,
-                              SilcTaskPriority priority)
+static SilcTask silc_task_add_timeout(SilcTaskQueue queue, SilcTask new,
+                                     SilcTaskPriority priority)
 {
   SilcTask task, prev, next;
 
index c07a86eb583bfcf4e3804bc3d79f002ae323d3d0..c33a6b2ed34cd85d277d9c1031007da6446b94ef 100644 (file)
@@ -216,18 +216,6 @@ struct SilcTaskQueueStruct {
 
 /* Macros */
 
-/* These can be used instead of calling directly the registering function. 
-   XXX: These are not used currently, maybe they should be :) */
-#define SILC_REGISTER_FD_TASK(queue, fd, cb, ctx, pri) \
-  (silc_task_register((queue), (fd), (cb), (ctx), 0, 0, \
-                     SILC_TASK_FD, (pri)))
-#define SILC_REGISTER_TIMEOUT_TASK(queue, fd, cb, ctx, sec, usec, pri) \
-  (silc_task_register((queue), (fd), (cb), (ctx), (sec), (usec), \
-                     SILC_TASK_TIMEOUT, (pri)))
-#define SILC_REGISTER_GENERIC_TASK(queue, fd, cb, ctx, pri) \
-  (silc_task_register((queue), (fd), (cb), (ctx), 0, 0, \
-                     SILC_TASK_GENERIC, (pri)))
-
 /* Generic macro to define task callback functions. This defines a function
    with name 'func' as a task callback function. */
 #define SILC_TASK_CALLBACK(func) \
@@ -240,10 +228,6 @@ void silc_task_queue_alloc(SilcSchedule schedule, SilcTaskQueue *queue,
                           bool valid);
 void silc_task_queue_free(SilcTaskQueue queue);
 void silc_task_queue_wakeup(SilcTaskQueue queue);
-SilcTask silc_task_add(SilcTaskQueue queue, SilcTask task, 
-                      SilcTaskPriority priority);
-SilcTask silc_task_add_timeout(SilcTaskQueue queue, SilcTask task,
-                              SilcTaskPriority priority);
 SilcTask silc_task_register(SilcTaskQueue queue, int fd, 
                            SilcTaskCallback cb, void *context, 
                            long seconds, long useconds, 
@@ -256,7 +240,5 @@ void silc_task_unregister_by_callback(SilcTaskQueue queue,
 void silc_task_unregister_by_context(SilcTaskQueue queue, void *context);
 void silc_task_set_iotype(SilcTask task, int type);
 void silc_task_reset_iotype(SilcTask task, int type);
-int silc_task_timeout_compare(struct timeval *smaller, 
-                             struct timeval *bigger);
 
 #endif