1 /*****************************************************************************
2 * This file is part of gfxprim library. *
4 * Gfxprim is free software; you can redistribute it and/or *
5 * modify it under the terms of the GNU Lesser General Public *
6 * License as published by the Free Software Foundation; either *
7 * version 2.1 of the License, or (at your option) any later version. *
9 * Gfxprim is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
12 * Lesser General Public License for more details. *
14 * You should have received a copy of the GNU Lesser General Public *
15 * License along with gfxprim; if not, write to the Free Software *
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
17 * Boston, MA 02110-1301 USA *
19 * Copyright (C) 2009-2013 Cyril Hrubis <metan@ucw.cz> *
21 *****************************************************************************/
25 Simple example how to use raw timer priority queue.
38 return random() % 30 + 1;
45 GP_TIMER_DECLARE(oneshot
, 30, 0, "Oneshot", callback1
, NULL
);
46 GP_TIMER_DECLARE(recurrent
, 0, 4, "Recurrent", callback1
, NULL
);
47 GP_TIMER_DECLARE(random
, 10, 0, "Random", callback3
, NULL
);
49 GP_Timer
*queue
= NULL
;
56 GP_TimerQueueInsert(&queue
, 0, &oneshot
);
57 GP_TimerQueueInsert(&queue
, 0, &recurrent
);
58 GP_TimerQueueInsert(&queue
, 0, &random
);
60 for (i
= 0; i
< MAX
; i
++) {
61 timers
[i
].expires
= MAX
- i
;
63 timers
[i
].Callback
= callback1
;
64 timers
[i
].priv
= NULL
;
65 sprintf(ids
[i
], "Timer%i", MAX
- i
);
66 timers
[i
].id
= ids
[i
];
67 GP_TimerQueueInsert(&queue
, 0, &timers
[i
]);
70 GP_TimerQueueDump(queue
);
72 GP_TimerQueueRemove(&queue
, &timers
[MAX
-1]);
74 GP_TimerQueueDump(queue
);
76 for (now
= 0; now
< 100; now
+= 3) {
77 printf("NOW %u\n", (unsigned int) now
);
78 printf("-------------------------------------\n");
79 ret
= GP_TimerQueueProcess(&queue
, now
);
80 printf("Processed %i timer events\n", ret
);
81 printf("--------------------------------------\n");
82 GP_TimerQueueDump(queue
);
83 printf("--------------------------------------\n\n");