2009-07-28 21:44:22 +00:00
|
|
|
/* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
|
|
|
|
*
|
|
|
|
* timed_thread.h: Abstraction layer for timed threads
|
2006-11-14 22:30:31 +00:00
|
|
|
*
|
2007-08-10 20:09:43 +00:00
|
|
|
* Copyright (C) 2006-2007 Philip Kovacs pkovacs@users.sourceforge.net
|
2006-12-13 16:54:59 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
|
2008-02-20 20:30:45 +00:00
|
|
|
* USA. */
|
2006-11-14 22:30:31 +00:00
|
|
|
|
2006-11-15 01:20:49 +00:00
|
|
|
#ifndef _TIMED_THREAD_H_
|
|
|
|
#define _TIMED_THREAD_H_
|
2006-11-14 22:30:31 +00:00
|
|
|
|
2008-06-14 18:41:12 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
/* 10000 microseconds = 10 ms = 0.01 sec */
|
|
|
|
#define MINIMUM_INTERVAL_USECS 10000
|
2006-11-14 22:30:31 +00:00
|
|
|
|
|
|
|
/* opaque structure for clients */
|
|
|
|
typedef struct _timed_thread timed_thread;
|
|
|
|
|
2007-08-31 21:35:30 +00:00
|
|
|
/* create a timed thread (object creation only) */
|
2008-02-20 20:30:45 +00:00
|
|
|
timed_thread *timed_thread_create(void *start_routine(void *), void *arg,
|
|
|
|
unsigned int interval_usecs);
|
2006-11-14 22:30:31 +00:00
|
|
|
|
2007-08-31 21:35:30 +00:00
|
|
|
/* run a timed thread (drop the thread and run it) */
|
2008-02-20 20:30:45 +00:00
|
|
|
int timed_thread_run(timed_thread *p_timed_thread);
|
2007-08-31 21:35:30 +00:00
|
|
|
|
2006-11-14 22:30:31 +00:00
|
|
|
/* destroy a timed thread */
|
2008-02-20 20:30:45 +00:00
|
|
|
void timed_thread_destroy(timed_thread *p_timed_thread,
|
|
|
|
timed_thread **addr_of_p_timed_thread);
|
2006-11-14 22:30:31 +00:00
|
|
|
|
|
|
|
/* lock a timed thread for critical section activity */
|
2008-02-20 20:30:45 +00:00
|
|
|
int timed_thread_lock(timed_thread *p_timed_thread);
|
2006-11-14 22:30:31 +00:00
|
|
|
|
|
|
|
/* unlock a timed thread after critical section activity */
|
2008-02-20 20:30:45 +00:00
|
|
|
int timed_thread_unlock(timed_thread *p_timed_thread);
|
2006-11-14 22:30:31 +00:00
|
|
|
|
2008-12-09 08:37:59 +00:00
|
|
|
/* waits required interval (unless override_wait_time is non-zero) for
|
2009-07-07 23:33:38 +00:00
|
|
|
* termination signal returns 1 if received, 0 otherwise. should also return 1
|
|
|
|
* if the thread has been asked kindly to die. */
|
2008-12-09 08:37:59 +00:00
|
|
|
int timed_thread_test(timed_thread *p_timed_thread, int override_wait_time);
|
2006-11-14 22:30:31 +00:00
|
|
|
|
|
|
|
/* exit a timed thread */
|
2008-03-29 11:35:02 +00:00
|
|
|
void timed_thread_exit(timed_thread *p_timed_thread) __attribute__((noreturn));
|
2006-11-14 22:30:31 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
/* register a timed thread for future destruction via
|
|
|
|
* timed_thread_destroy_registered_threads() */
|
|
|
|
int timed_thread_register(timed_thread *p_timed_thread,
|
|
|
|
timed_thread **addr_of_p_timed_thread);
|
2006-11-14 22:30:31 +00:00
|
|
|
|
|
|
|
/* destroy all registered timed threads */
|
2008-02-20 20:30:45 +00:00
|
|
|
void timed_thread_destroy_registered_threads(void);
|
2006-11-15 01:20:49 +00:00
|
|
|
|
2008-09-25 03:11:24 +00:00
|
|
|
/* returns read file descriptor for thread pipe */
|
|
|
|
int timed_thread_readfd(timed_thread *p_timed_thread);
|
|
|
|
|
2006-11-15 01:20:49 +00:00
|
|
|
#endif /* #ifdef _TIMED_THREAD_H_ */
|