updates.
[silc.git] / lib / silcutil / silcschedule.h
index 2272f8e12f122b8f44ccca8a955dcf0edd338ae6..4b23067dd4cf566d7950448aafae8ddde8008304 100644 (file)
@@ -1,26 +1,28 @@
-/****h* silcutil/silcschedule.h
- *
- * NAME
- *
- * silcschedule.h
- *
- * COPYRIGHT
- *
- * Author: Pekka Riikonen <priikone@silcnet.org>
- *
- * Copyright (C) 1998 - 2001 Pekka Riikonen
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+/*
+  
+  silcschedule.h
+  COPYRIGHT
+  Author: Pekka Riikonen <priikone@silcnet.org>
+  Copyright (C) 1998 - 2001 Pekka Riikonen
+  This program is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; either version 2 of the License, or
+  (at your option) any later version.
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+*/
+/****h* silcutil/SILC Schedule Interface
  *
# DESCRIPTION
* 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,
@@ -63,7 +65,7 @@
  * application could be created by allocating own scheduler for each of the
  * worker threads.
  *
- */
+ ***/
 
 #ifndef SILCSCHEDULE_H
 #define SILCSCHEDULE_H
@@ -118,7 +120,7 @@ typedef enum {
   /* File descriptor task that performs some event over file descriptors.
      These tasks are for example network connections. */
   SILC_TASK_FD,
-  
+
   /* Timeout tasks are tasks that are executed after the specified 
      time has elapsed. After the task is executed the task is removed
      automatically from the scheduler. It is safe to re-register the
@@ -170,7 +172,7 @@ typedef enum {
  *
  * NAME
  * 
- *    typedef enum { ... } SilcTaskPriority
+ *    typedef enum { ... } SilcTaskPriority;
  *
  * DESCRIPTION
  *
@@ -197,12 +199,12 @@ typedef enum {
 } SilcTaskPriority;
 /***/
 
-/****f* silcutil/SilcScheduleAPI/silc_schedule_init
+/****f* silcutil/SilcScheduleAPI/SilcTaskCallback
  *
  * SYNOPSIS
  *
  *    typedef void (*SilcTaskCallback)(SilcSchedule schedule, 
- *                                     SilcTaskEvent type, uint32 fd, 
+ *                                     SilcTaskEvent type, SilcUInt32 fd, 
  *                                     void *context);
  *
  * DESCRIPTION
@@ -222,7 +224,7 @@ typedef enum {
  *
  ***/
 typedef void (*SilcTaskCallback)(SilcSchedule schedule, SilcTaskEvent type,
-                                uint32 fd, void *context);
+                                SilcUInt32 fd, void *context);
 
 /* Macros */
 
@@ -257,10 +259,10 @@ typedef void (*SilcTaskCallback)(SilcSchedule schedule, SilcTaskEvent type,
  */
 #define SILC_TASK_CALLBACK(func)                               \
 static void func(SilcSchedule schedule, SilcTaskEvent type,    \
-                uint32 fd, void *context)
+                SilcUInt32 fd, void *context)
 /***/
 
-/****d* silcutil/SilcScheduleAPI/SILC_TASK_CALLBACK
+/****d* silcutil/SilcScheduleAPI/SILC_TASK_CALLBACK_GLOBAL
  *
  * NAME
  * 
@@ -277,7 +279,7 @@ static void func(SilcSchedule schedule, SilcTaskEvent type, \
  */
 #define SILC_TASK_CALLBACK_GLOBAL(func)                        \
 void func(SilcSchedule schedule, SilcTaskEvent type,   \
-         uint32 fd, void *context)
+         SilcUInt32 fd, void *context)
 /***/
 
 /* Prototypes */
@@ -314,6 +316,26 @@ SilcSchedule silc_schedule_init(int max_tasks);
  ***/
 bool silc_schedule_uninit(SilcSchedule schedule);
 
+/****f* silcutil/SilcScheduleAPI/silc_schedule_reinit
+ *
+ * SYNOPSIS
+ *
+ *    SilcSchedule silc_schedule_reinit(int max_tasks);
+ *
+ * DESCRIPTION
+ *
+ *    This function can be called to enlarge the task handling capabilities
+ *    of the scheduler indicated by `schedule'.  The `max_tasks' must be
+ *    larger than what was set in silc_schedule_init function.  This function
+ *    returns FALSE if it cannot reinit the scheduler.  This function does
+ *    not do anything else except ready the scheduler to handle `max_tasks'
+ *    number of tasks after this function returns.  It is safe to call this
+ *    function at any time, and it is guaranteed that existing tasks remain
+ *    as they are in the scheduler.
+ *
+ ***/
+bool silc_schedule_reinit(SilcSchedule schedule, int max_tasks);
+
 /****f* silcutil/SilcScheduleAPI/silc_schedule_stop
  *
  * SYNOPSIS
@@ -324,7 +346,10 @@ bool silc_schedule_uninit(SilcSchedule schedule);
  *
  *    Stops the scheduler even if it is not supposed to be stopped yet. 
  *    After calling this, one must call silc_schedule_uninit (after the 
- *    silc_schedule has returned).
+ *    silc_schedule has returned).  After this is called it is guaranteed
+ *    that next time the scheduler enters the main loop it will be stopped.
+ *    However, untill it enters the main loop it will not detect that
+ *    it is stopped for example if this is called from another thread.
  *
  ***/
 void silc_schedule_stop(SilcSchedule schedule);
@@ -344,7 +369,7 @@ void silc_schedule_stop(SilcSchedule schedule);
  ***/
 void silc_schedule(SilcSchedule schedule);
 
-/****f* silcutil/SilcScheduleAPI/silc_schedule
+/****f* silcutil/SilcScheduleAPI/silc_schedule_one
  *
  * SYNOPSIS
  *
@@ -384,7 +409,7 @@ void silc_schedule_wakeup(SilcSchedule schedule);
  *
  * SYNOPSIS
  *
- *    SilcTask silc_schedule_task_add(SilcSchedule schedule, uint32 fd,
+ *    SilcTask silc_schedule_task_add(SilcSchedule schedule, SilcUInt32 fd,
  *                                    SilcTaskCallback callback, 
  *                                    void *context, 
  *                                    long seconds, long useconds, 
@@ -423,7 +448,7 @@ void silc_schedule_wakeup(SilcSchedule schedule);
  *    in other threads as well.
  *   
  ***/
-SilcTask silc_schedule_task_add(SilcSchedule schedule, uint32 fd,
+SilcTask silc_schedule_task_add(SilcSchedule schedule, SilcUInt32 fd,
                                SilcTaskCallback callback, void *context, 
                                long seconds, long useconds, 
                                SilcTaskType type, 
@@ -453,7 +478,7 @@ void silc_schedule_task_del(SilcSchedule schedule, SilcTask task);
  *
  * SYNOPSIS
  *
- *    void silc_schedule_task_del_by_fd(SilcSchedule schedule, uint32 fd);
+ *    void silc_schedule_task_del_by_fd(SilcSchedule schedule, SilcUInt32 fd);
  *
  * DESCRIPTION
  *
@@ -467,7 +492,7 @@ void silc_schedule_task_del(SilcSchedule schedule, SilcTask task);
  *    since generic tasks does not match any specific fd.
  *
  ***/
-void silc_schedule_task_del_by_fd(SilcSchedule schedule, uint32 fd);
+void silc_schedule_task_del_by_fd(SilcSchedule schedule, SilcUInt32 fd);
 
 /****f* silcutil/SilcScheduleAPI/silc_schedule_task_del_by_callback
  *
@@ -511,7 +536,7 @@ void silc_schedule_task_del_by_context(SilcSchedule schedule, void *context);
  *
  * SYNOPSIS
  *
- *    void silc_schedule_set_listen_fd(SilcSchedule schedule, uint32 fd,
+ *    void silc_schedule_set_listen_fd(SilcSchedule schedule, SilcUInt32 fd,
  *                                     SilcTaskEvent mask);
  *
  * DESCRIPTION
@@ -526,14 +551,14 @@ void silc_schedule_task_del_by_context(SilcSchedule schedule, void *context);
  *    times to change the events.
  *
  ***/
-void silc_schedule_set_listen_fd(SilcSchedule schedule, uint32 fd,
+void silc_schedule_set_listen_fd(SilcSchedule schedule, SilcUInt32 fd,
                                 SilcTaskEvent mask);
 
 /****f* silcutil/SilcScheduleAPI/silc_schedule_unset_listen_fd
  *
  * SYNOPSIS
  *
- *    void silc_schedule_unset_listen_fd(SilcSchedule schedule, uint32 fd);
+ *    void silc_schedule_unset_listen_fd(SilcSchedule schedule, SilcUInt32 fd);
  *
  * DESCRIPTION
  *
@@ -542,6 +567,40 @@ void silc_schedule_set_listen_fd(SilcSchedule schedule, uint32 fd,
  *    after calling this function.
  *
  ***/
-void silc_schedule_unset_listen_fd(SilcSchedule schedule, uint32 fd);
+void silc_schedule_unset_listen_fd(SilcSchedule schedule, SilcUInt32 fd);
+
+/****f* silcutil/SilcScheduleAPI/silc_schedule_signal_register
+ *
+ * SYNOPSIS
+ *
+ *    void silc_schedule_signal_register(SilcSchedule schedule, 
+ *                                       SilcUInt32 signal);
+ *
+ * DESCRIPTION
+ *
+ *    Register signal indicated by `signal' to the scheduler.  Application
+ *    should register all signals it is going to use to the scheduler.
+ *    To unregister a signal call silc_schedule_signal_unregister.  On
+ *    platform that does not support signals calling this function has not
+ *    effect.
+ *
+ ***/
+void silc_schedule_signal_register(SilcSchedule schedule, SilcUInt32 signal);
+
+/****f* silcutil/SilcScheduleAPI/silc_schedule_signal_unregister
+ *
+ * SYNOPSIS
+ *
+ *    void silc_schedule_signal_unregister(SilcSchedule schedule, 
+ *                                         SilcUInt32 signal);
+ *
+ * DESCRIPTION
+ *
+ *    Unregister a signal indicated by `signal' from the scheduler.  On
+ *    platform that does not support signals calling this function has no
+ *    effect.
+ *
+ ***/
+void silc_schedule_signal_unregister(SilcSchedule schedule, SilcUInt32 signal);
 
 #endif