This is the mail archive of the libc-alpha@sourceware.cygnus.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

New POSIX clock_* and timer_* functions.


Hi guys,

I have this stuff working already and should release something to the public
in a near timeframe.

The following functions are implemented:

    int clock_settime(clockid_t, const struct timespec *);
    int clock_gettime(clockid_t, struct timespec *);
    int clock_getres(clockid_t, struct timespec *);


    int timer_create(clockid_t, struct sigevent *, timer_t *);
    int timer_delete(timer_t);
    int timer_gettime(timer_t, struct itimerspec *);
    int timer_getoverrun(timer_t);
    int timer_settime(timer_t, int, const struct itimerspec *,
	    struct itimerspec *);


The timer module is capable of delivering signals, as well as calling
notification functions from internal threads: in other words, the SIGEV_THREAD
and SIGEV_SIGNAL methods documented in The Single UNIX Spec are supported.

Supported also is the passing of desired thread attributes for the creation of
these internal timer threads. 

Somewhat supported also are rogue applications that terminate threads
originating from the timer module; these terminations are detected and threads
are promptly replaced.

Timer overrun counting is not supported; the function just returns zero.
(Timer overrun counting means detecting, at signal delivery time, that
the previously queued signal has not yet been handled and bumping up
a counter against the timer; the counted value is then reported by
timer_getoverrun()).

Quick design note:

The implementation maintains an internal pool of threads and, in timer_create,
binds timers to threads having the desired attributes. (If multiple timers call
for a thread having identical attributes, the first timer_create makes the
thread with the required pthread_attr_t, and subsequent ones bind to that
thread based on a pthread_attr_t match; so only so many threads are needed as
the number of distinct attributes requested by the application.)

Signals are delivered via pthread_kill() from a single internal thread that is
dedicated to handling all signal-based timers. The pthread_kill() is first
tried on the thread which made the first call to timer_create(), the so-called
captured thread. If that fails, then the kill is delivered within the timer
thread itself via pthread_kill(pthread_self(), sig). (NOTE: I would tend to
discourage the use of timers that deliver signals.)

--
#exclude <windows.h>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]