/* Serval DNA file descriptor queue Copyright (C) 2012-2013 Serval Project, Inc. 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. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef __SERVALDNA__FDQUEUE_H #define __SERVALDNA__FDQUEUE_H #ifdef HAVE_POLL_H #include #endif #include "os.h" #include "log.h" struct profile_total { struct profile_total *_next; int _initialised; const char *name; time_ms_t max_time; time_ms_t total_time; time_ms_t child_time; int calls; }; struct call_stats{ time_ms_t enter_time; time_ms_t child_time; struct profile_total *totals; struct call_stats *prev; }; struct sched_ent; typedef void (*ALARM_FUNCP) (struct sched_ent *alarm); struct sched_ent{ struct sched_ent *_next; struct sched_ent *_prev; ALARM_FUNCP function; void *context; struct pollfd poll; // when we should first consider the alarm time_ms_t alarm; // the order we will prioritise the alarm time_ms_t deadline; struct profile_total *stats; int _poll_index; }; int is_scheduled(const struct sched_ent *alarm); int _schedule(struct __sourceloc, struct sched_ent *alarm); int _unschedule(struct __sourceloc, struct sched_ent *alarm); int _watch(struct __sourceloc, struct sched_ent *alarm); int _unwatch(struct __sourceloc, struct sched_ent *alarm); #define schedule(alarm) _schedule(__WHENCE__, alarm) #define unschedule(alarm) _unschedule(__WHENCE__, alarm) #define watch(alarm) _watch(__WHENCE__, alarm) #define unwatch(alarm) _unwatch(__WHENCE__, alarm) int fd_poll(); /* function timing routines */ int fd_clearstats(); int fd_showstats(); int fd_checkalarms(); int fd_func_enter(struct __sourceloc, struct call_stats *this_call); int fd_func_exit(struct __sourceloc, struct call_stats *this_call); void dump_stack(int log_level); #define IN() static struct profile_total _aggregate_stats={NULL,0,__FUNCTION__,0,0,0}; \ struct call_stats _this_call={.totals=&_aggregate_stats}; \ fd_func_enter(__HERE__, &_this_call); #define OUT() fd_func_exit(__HERE__, &_this_call) #define RETURN(X) do { OUT(); return (X); } while (0); #define RETURNNULL do { OUT(); return (NULL); } while (0); #define RETURNVOID do { OUT(); return; } while (0); #endif // __SERVALDNA__FDQUEUE_H