TimerThread.h
Go to the documentation of this file.
/*******************************************************************************
*
* Copyright (c) 2000-2003 Intel Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* * Neither name of Intel Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************/
#ifndef TIMERTHREAD_H
#define TIMERTHREAD_H
#include "FreeList.h"
#include "LinkedList.h"
#include "ThreadPool.h"
#include "ithread.h"
#ifdef __cplusplus
extern "C" {
#endif
#define INVALID_EVENT_ID (-10 & 1 << 29)
typedef enum timeoutType
{
ABS_SEC,
REL_SEC
} TimeoutType;
typedef struct TIMERTHREAD
{
ithread_mutex_t mutex;
ithread_cond_t condition;
int lastEventId;
LinkedList eventQ;
int shutdown;
FreeList freeEvents;
ThreadPool *tp;
} TimerThread;
typedef struct TIMEREVENT
{
ThreadPoolJob job;
time_t eventTime;
Duration persistent;
int id;
} TimerEvent;
int TimerThreadInit(
TimerThread *timer,
ThreadPool *tp);
int TimerThreadSchedule(
TimerThread *timer,
time_t time,
TimeoutType type,
ThreadPoolJob *job,
Duration duration,
int *id);
int TimerThreadRemove(
TimerThread *timer,
int id,
ThreadPoolJob *out);
int TimerThreadShutdown(
TimerThread *timer);
#ifdef __cplusplus
}
#endif
#endif /* TIMER_THREAD_H */
FreeList.h
FreeList
struct FREELIST FreeList
LinkedList.h
LinkedList
struct LINKEDLIST LinkedList
ThreadPool.h
ThreadPool
struct THREADPOOL ThreadPool
A thread pool similar to the thread pool in the UPnP SDK.
ThreadPoolJob
struct THREADPOOLJOB ThreadPoolJob
TimeoutType
enum timeoutType TimeoutType
TimerThreadShutdown
int TimerThreadShutdown(TimerThread *timer)
Shutdown the timer thread.
Definition TimerThread.c:355
TimerEvent
struct TIMEREVENT TimerEvent
TimerThread
struct TIMERTHREAD TimerThread
TimerThreadInit
int TimerThreadInit(TimerThread *timer, ThreadPool *tp)
Initializes and starts timer thread.
Definition TimerThread.c:197
TimerThreadSchedule
int TimerThreadSchedule(TimerThread *timer, time_t time, TimeoutType type, ThreadPoolJob *job, Duration duration, int *id)
Schedules an event to run at a specified time.
Definition TimerThread.c:253
timeoutType
timeoutType
Definition TimerThread.h:52
ABS_SEC
@ ABS_SEC
Definition TimerThread.h:54
REL_SEC
@ REL_SEC
Definition TimerThread.h:56
TimerThreadRemove
int TimerThreadRemove(TimerThread *timer, int id, ThreadPoolJob *out)
Removes an event from the timer Q.
Definition TimerThread.c:321
ithread.h
TIMEREVENT
Definition TimerThread.h:85
TIMEREVENT::persistent
Duration persistent
Definition TimerThread.h:90
TIMEREVENT::eventTime
time_t eventTime
Definition TimerThread.h:88
TIMERTHREAD
Definition TimerThread.h:69