\doxysection{timer.\+h}
\label{timer_8h_source}\index{include/osmocom/core/timer.h@{include/osmocom/core/timer.h}}
\textbf{ Go to the documentation of this file.}
\begin{DoxyCode}{0}
\DoxyCodeLine{1 }
\DoxyCodeLine{3 \textcolor{comment}{/*}}
\DoxyCodeLine{4 \textcolor{comment}{ * (C) 2008, 2009 by Holger Hans Peter Freyther <zecke@selfish.org>}}
\DoxyCodeLine{5 \textcolor{comment}{ * All Rights Reserved}}
\DoxyCodeLine{6 \textcolor{comment}{ *}}
\DoxyCodeLine{7 \textcolor{comment}{ * This program is free software; you can redistribute it and/or modify}}
\DoxyCodeLine{8 \textcolor{comment}{ * it under the terms of the GNU General Public License as published by}}
\DoxyCodeLine{9 \textcolor{comment}{ * the Free Software Foundation; either version 2 of the License, or}}
\DoxyCodeLine{10 \textcolor{comment}{ * (at your option) any later version.}}
\DoxyCodeLine{11 \textcolor{comment}{ *}}
\DoxyCodeLine{12 \textcolor{comment}{ * This program is distributed in the hope that it will be useful,}}
\DoxyCodeLine{13 \textcolor{comment}{ * but WITHOUT ANY WARRANTY; without even the implied warranty of}}
\DoxyCodeLine{14 \textcolor{comment}{ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the}}
\DoxyCodeLine{15 \textcolor{comment}{ * GNU General Public License for more details.}}
\DoxyCodeLine{16 \textcolor{comment}{ *}}
\DoxyCodeLine{17 \textcolor{comment}{ */}}
\DoxyCodeLine{18 }
\DoxyCodeLine{36 \textcolor{preprocessor}{\#pragma once}}
\DoxyCodeLine{37 }
\DoxyCodeLine{38 \textcolor{preprocessor}{\#include <sys/time.h>}}
\DoxyCodeLine{39 \textcolor{preprocessor}{\#include <time.h>}}
\DoxyCodeLine{40 \textcolor{preprocessor}{\#include <stdbool.h>}}
\DoxyCodeLine{41 }
\DoxyCodeLine{42 \textcolor{preprocessor}{\#include <osmocom/core/linuxlist.h>}}
\DoxyCodeLine{43 \textcolor{preprocessor}{\#include <osmocom/core/linuxrbtree.h>}}
\DoxyCodeLine{44 \textcolor{preprocessor}{\#include <osmocom/core/timer\_compat.h>}}
\DoxyCodeLine{45 }
\DoxyCodeLine{46 \textcolor{comment}{/* convert absolute time (in seconds) to elapsed days/hours/minutes */}}
\DoxyCodeLine{47 \textcolor{preprocessor}{\#define OSMO\_SEC2MIN(sec) ((sec \% (60 * 60)) / 60)}}
\DoxyCodeLine{48 \textcolor{preprocessor}{\#define OSMO\_SEC2HRS(sec) ((sec \% (60 * 60 * 24)) / (60 * 60))}}
\DoxyCodeLine{49 \textcolor{preprocessor}{\#define OSMO\_SEC2DAY(sec) ((sec \% (60 * 60 * 24 * 365)) / (60 * 60 * 24)) }\textcolor{comment}{/* we ignore leap year for simplicity */}\textcolor{preprocessor}{}}
\DoxyCodeLine{50 }
\DoxyCodeLine{52 \textcolor{keyword}{struct }osmo\_timer\_list \{}
\DoxyCodeLine{53         \textcolor{keyword}{struct }rb\_node node;   }
\DoxyCodeLine{54         \textcolor{keyword}{struct }llist\_head list;   }
\DoxyCodeLine{55         \textcolor{keyword}{struct }timeval timeout;   }
\DoxyCodeLine{56         \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} active  : 1; }
\DoxyCodeLine{58         void (*cb)(\textcolor{keywordtype}{void}*);      }
\DoxyCodeLine{59         \textcolor{keywordtype}{void} *data;           }
\DoxyCodeLine{60 \};}
\DoxyCodeLine{61 }
\DoxyCodeLine{62 \textcolor{comment}{/*}}
\DoxyCodeLine{63 \textcolor{comment}{ * timer management}}
\DoxyCodeLine{64 \textcolor{comment}{ */}}
\DoxyCodeLine{65 }
\DoxyCodeLine{66 \textcolor{keywordtype}{void} osmo\_timer\_setup(\textcolor{keyword}{struct} osmo\_timer\_list *timer, \textcolor{keywordtype}{void} (*cb)(\textcolor{keywordtype}{void} *data), \textcolor{keywordtype}{void} *data);}
\DoxyCodeLine{67 }
\DoxyCodeLine{68 \textcolor{keywordtype}{void} osmo\_timer\_add(\textcolor{keyword}{struct} osmo\_timer\_list *timer);}
\DoxyCodeLine{69 }
\DoxyCodeLine{70 \textcolor{keywordtype}{void} osmo\_timer\_schedule(\textcolor{keyword}{struct} osmo\_timer\_list *timer, \textcolor{keywordtype}{int} seconds, \textcolor{keywordtype}{int} microseconds);}
\DoxyCodeLine{71 }
\DoxyCodeLine{72 \textcolor{keywordtype}{void} osmo\_timer\_del(\textcolor{keyword}{struct} osmo\_timer\_list *timer);}
\DoxyCodeLine{73 }
\DoxyCodeLine{74 \textcolor{keywordtype}{int} osmo\_timer\_pending(\textcolor{keyword}{const} \textcolor{keyword}{struct} osmo\_timer\_list *timer);}
\DoxyCodeLine{75 }
\DoxyCodeLine{76 \textcolor{keywordtype}{int} osmo\_timer\_remaining(\textcolor{keyword}{const} \textcolor{keyword}{struct} osmo\_timer\_list *timer,}
\DoxyCodeLine{77                          \textcolor{keyword}{const} \textcolor{keyword}{struct} timeval *now,}
\DoxyCodeLine{78                          \textcolor{keyword}{struct} timeval *remaining);}
\DoxyCodeLine{79 \textcolor{comment}{/*}}
\DoxyCodeLine{80 \textcolor{comment}{ * internal timer list management}}
\DoxyCodeLine{81 \textcolor{comment}{ */}}
\DoxyCodeLine{82 \textcolor{keyword}{struct }timeval *osmo\_timers\_nearest(\textcolor{keywordtype}{void});}
\DoxyCodeLine{83 \textcolor{keywordtype}{int} osmo\_timers\_nearest\_ms(\textcolor{keywordtype}{void});}
\DoxyCodeLine{84 \textcolor{keywordtype}{void} osmo\_timers\_prepare(\textcolor{keywordtype}{void});}
\DoxyCodeLine{85 \textcolor{keywordtype}{int} osmo\_timers\_update(\textcolor{keywordtype}{void});}
\DoxyCodeLine{86 \textcolor{keywordtype}{int} osmo\_timers\_check(\textcolor{keywordtype}{void});}
\DoxyCodeLine{87 }
\DoxyCodeLine{88 \textcolor{keywordtype}{int} osmo\_gettimeofday(\textcolor{keyword}{struct} timeval *tv, \textcolor{keyword}{struct} timezone *tz);}
\DoxyCodeLine{89 \textcolor{keywordtype}{int} osmo\_clock\_gettime(clockid\_t clk\_id, \textcolor{keyword}{struct} timespec *tp);}
\DoxyCodeLine{90 }
\DoxyCodeLine{91 \textcolor{comment}{/*}}
\DoxyCodeLine{92 \textcolor{comment}{ * timer override}}
\DoxyCodeLine{93 \textcolor{comment}{ */}}
\DoxyCodeLine{94 }
\DoxyCodeLine{95 \textcolor{keyword}{extern} \textcolor{keywordtype}{bool} osmo\_gettimeofday\_override;}
\DoxyCodeLine{96 \textcolor{keyword}{extern} \textcolor{keyword}{struct }timeval osmo\_gettimeofday\_override\_time;}
\DoxyCodeLine{97 \textcolor{keywordtype}{void} osmo\_gettimeofday\_override\_add(time\_t secs, suseconds\_t usecs);}
\DoxyCodeLine{98 }
\DoxyCodeLine{99 \textcolor{keywordtype}{void} osmo\_clock\_override\_enable(clockid\_t clk\_id, \textcolor{keywordtype}{bool} enable);}
\DoxyCodeLine{100 \textcolor{keywordtype}{void} osmo\_clock\_override\_add(clockid\_t clk\_id, time\_t secs, \textcolor{keywordtype}{long} nsecs);}
\DoxyCodeLine{101 \textcolor{keyword}{struct }timespec *osmo\_clock\_override\_gettimespec(clockid\_t clk\_id);}
\DoxyCodeLine{102 }

\end{DoxyCode}
