X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=ucw%2Fmainloop.h;h=51a3683a46e145b50867c4feec9c0e82a379ca1c;hb=6efdc514c193f18c9ef840096750c37e78a01bf6;hp=6de703d862f747687229d4cac5df5f03629083c2;hpb=5467f05c05e6e41dd1f87f9718c0db01634ab9ae;p=libucw.git diff --git a/ucw/mainloop.h b/ucw/mainloop.h index 6de703d8..51a3683a 100644 --- a/ucw/mainloop.h +++ b/ucw/mainloop.h @@ -1,7 +1,7 @@ /* * UCW Library -- Main Loop * - * (c) 2004--2011 Martin Mares + * (c) 2004--2012 Martin Mares * * This software may be freely distributed and used according to the terms * of the GNU Lesser General Public License. @@ -10,7 +10,8 @@ #ifndef _UCW_MAINLOOP_H #define _UCW_MAINLOOP_H -#include "ucw/clists.h" +#include +#include #include @@ -24,8 +25,7 @@ /** The main loop context **/ struct main_context { - timestamp_t now; /* [*] Current time in milliseconds since the UNIX epoch. See main_get_time(). */ - ucw_time_t now_seconds; /* [*] Current time in seconds since the epoch. */ + timestamp_t now; /* [*] Current time in milliseconds since an unknown epoch. See main_get_time(). */ timestamp_t idle_time; /* [*] Total time in milliseconds spent by waiting for events. */ uns shutdown; /* [*] Setting this to nonzero forces the main_loop() function to terminate. */ clist file_list; @@ -111,7 +111,7 @@ static inline void main_shut_down(void) /** * Show the current state of a given context (use @main_debug() for the current context). - * Available only if LibUCW has been compiled with `CONFIG_DEBUG`. + * Available only if LibUCW has been compiled with `CONFIG_UCW_DEBUG`. **/ void main_debug_context(struct main_context *m); @@ -143,12 +143,6 @@ static inline timestamp_t main_get_now(void) return main_current()->now; } -/** An analog of @main_get_now() returning the number of seconds since the system epoch. **/ -static inline ucw_time_t main_get_now_seconds(void) -{ - return main_current()->now_seconds; -} - /** * This is a description of a timer. * You define the handler function and possibly user-defined data you wish @@ -168,7 +162,8 @@ struct main_timer { * timer. It is permitted (and usual) to call this function from the * timer's handler itself if you want the timer to trigger again. * - * The @expire parameter is absolute, use @timer_add_rel() for a relative version. + * The @expire parameter is absolute (in the same time scale as @main_get_now()), + * use @timer_add_rel() for a relative version. **/ void timer_add(struct main_timer *tm, timestamp_t expires); @@ -178,7 +173,7 @@ void timer_add_rel(struct main_timer *tm, timestamp_t expires_delta); /** * Removes a timer from the active ones. It is permitted (and common) to call * this function from the timer's handler itself if you want to deactivate - * the timer. + * the timer. Removing an already removed timer does nothing. **/ void timer_del(struct main_timer *tm); @@ -196,7 +191,7 @@ static inline int timer_is_active(struct main_timer *tm) **/ void main_get_time(void); -/** Show current state of a timer. Available only if LibUCW has been compiled with `CONFIG_DEBUG`. **/ +/** Show current state of a timer. Available only if LibUCW has been compiled with `CONFIG_UCW_DEBUG`. **/ void timer_debug(struct main_timer *tm); /*** @@ -247,12 +242,15 @@ enum main_hook_return { * Inserts a new hook into the loop. * The hook will be scheduled at least once before next sleep. * May be called from inside a hook handler too. + * Adding an already added hook is permitted and if the hook has been run, + * it will be run again before next sleep. **/ void hook_add(struct main_hook *ho); /** * Removes an existing hook from the loop. * May be called from inside a hook handler (to delete itself or another hook). + * Removing an already removed hook does nothing. **/ void hook_del(struct main_hook *ho); @@ -262,7 +260,7 @@ static inline int hook_is_active(struct main_hook *ho) return clist_is_linked(&ho->n); } -/** Show current state of a hook. Available only if LibUCW has been compiled with `CONFIG_DEBUG`. **/ +/** Show current state of a hook. Available only if LibUCW has been compiled with `CONFIG_UCW_DEBUG`. **/ void hook_debug(struct main_hook *ho); @@ -339,6 +337,7 @@ void file_chg(struct main_file *fi); * please use this function first. * * Can be called from a handler. + * Removing an already removed file does nothing. **/ void file_del(struct main_file *fi); @@ -348,7 +347,7 @@ static inline int file_is_active(struct main_file *fi) return clist_is_linked(&fi->n); } -/** Show current state of a file. Available only if LibUCW has been compiled with `CONFIG_DEBUG`. **/ +/** Show current state of a file. Available only if LibUCW has been compiled with `CONFIG_UCW_DEBUG`. **/ void file_debug(struct main_file *fi); /*** @@ -391,7 +390,7 @@ struct main_block_io { /** Activate a block I/O structure. **/ void block_io_add(struct main_block_io *bio, int fd); -/** Deactivate a block I/O structure. **/ +/** Deactivate a block I/O structure. Calling twice is safe. **/ void block_io_del(struct main_block_io *bio); /** @@ -518,7 +517,7 @@ struct main_rec_io { /** Activate a record I/O structure. **/ void rec_io_add(struct main_rec_io *rio, int fd); -/** Deactivate a record I/O structure. **/ +/** Deactivate a record I/O structure. Calling twice is safe. **/ void rec_io_del(struct main_rec_io *rio); /** @@ -607,6 +606,7 @@ void process_add(struct main_process *mp); * Removes the process from the watched set. This is done * automatically, when the process terminates, so you need it only * when you do not want to watch a running process any more. + * Removing an already removed process does nothing. */ void process_del(struct main_process *mp); @@ -632,7 +632,7 @@ static inline int process_is_active(struct main_process *mp) return clist_is_linked(&mp->n); } -/** Show current state of a process. Available only if LibUCW has been compiled with `CONFIG_DEBUG`. **/ +/** Show current state of a process. Available only if LibUCW has been compiled with `CONFIG_UCW_DEBUG`. **/ void process_debug(struct main_process *pr); /*** @@ -672,7 +672,7 @@ struct main_signal { /** Request a signal to be caught and delivered synchronously. **/ void signal_add(struct main_signal *ms); -/** Cancel a request for signal catching. **/ +/** Cancel a request for signal catching. Calling twice is safe. **/ void signal_del(struct main_signal *ms); /** Tells if a signal catcher is active (i.e., added). **/ @@ -681,7 +681,7 @@ static inline int signal_is_active(struct main_signal *ms) return clist_is_linked(&ms->n); } -/** Show current state of a signal catcher. Available only if LibUCW has been compiled with `CONFIG_DEBUG`. **/ +/** Show current state of a signal catcher. Available only if LibUCW has been compiled with `CONFIG_UCW_DEBUG`. **/ void signal_debug(struct main_signal *sg); #endif