summaryrefslogtreecommitdiff
path: root/src/base/myTimer.c
diff options
context:
space:
mode:
authorTomas Chvatal (scarabeus) <tomas.chvatal@gmail.com>2008-10-22 22:53:48 +0200
committerTomas Chvatal (scarabeus) <tomas.chvatal@gmail.com>2008-10-22 22:53:48 +0200
commit130d45bfc935da1702a7b5c246a099ea3b4a0bdf (patch)
tree5cc4b029f24e7a3cfaf1fcbc671772059a9b8e73 /src/base/myTimer.c
parent44daf03024fbf7cbffa10349044786f6ab784821 (diff)
Ident all code correctly.
Diffstat (limited to 'src/base/myTimer.c')
-rw-r--r--src/base/myTimer.c191
1 files changed, 103 insertions, 88 deletions
diff --git a/src/base/myTimer.c b/src/base/myTimer.c
index 4de0fcc..0121a5f 100644
--- a/src/base/myTimer.c
+++ b/src/base/myTimer.c
@@ -16,124 +16,139 @@
#include "interface.h"
#endif
-static struct timeval start = { .tv_sec = 0, .tv_usec = 0 };
+static struct timeval start = {.tv_sec = 0,.tv_usec = 0 };
-list_t* newTimer()
+list_t *
+newTimer()
{
- return newList();
+ return newList();
}
-void restartTimer()
+void
+restartTimer()
{
- gettimeofday(&start, NULL);
+ gettimeofday(&start, NULL);
}
-my_time_t getMyTime()
+my_time_t
+getMyTime()
{
- struct timeval now;
- my_time_t ticks;
-
- if (start.tv_sec == 0 && start.tv_usec == 0)
- restartTimer();
- gettimeofday(&now, NULL);
- ticks = (now.tv_sec-start.tv_sec)*1000+(now.tv_usec-start.tv_usec)/1000;
- //printf("-> %d\n", ticks);
- return ticks;
+ struct timeval now;
+ my_time_t ticks;
+
+ if (start.tv_sec == 0 && start.tv_usec == 0)
+ restartTimer();
+ gettimeofday(&now, NULL);
+ ticks =
+ (now.tv_sec - start.tv_sec) * 1000 + (now.tv_usec -
+ start.tv_usec) / 1000;
+ //printf("-> %d\n", ticks);
+ return ticks;
}
-my_time_t getMyTimeMicro()
+my_time_t
+getMyTimeMicro()
{
- static struct timeval start = { .tv_sec = 0, .tv_usec = 0 };
- struct timeval now;
- my_time_t ticks;
- if (start.tv_sec == 0 && start.tv_usec == 0)
- gettimeofday(&start, NULL);
- gettimeofday(&now, NULL);
- ticks = (now.tv_sec-start.tv_sec)*1000*1000+(now.tv_usec-start.tv_usec);
- //printf("-> %d\n", ticks);
- return ticks;
+ static struct timeval start = {.tv_sec = 0,.tv_usec = 0 };
+ struct timeval now;
+ my_time_t ticks;
+ if (start.tv_sec == 0 && start.tv_usec == 0)
+ gettimeofday(&start, NULL);
+ gettimeofday(&now, NULL);
+ ticks =
+ (now.tv_sec - start.tv_sec) * 1000 * 1000 + (now.tv_usec -
+ start.tv_usec);
+ //printf("-> %d\n", ticks);
+ return ticks;
}
-my_timer_t* newTimerItem(int type, void (*fce)(void *p), void *arg, my_time_t my_time)
+my_timer_t *
+newTimerItem(int type, void (*fce) (void *p), void *arg, my_time_t my_time)
{
- static int new_id = 0;
- my_timer_t *new;
- assert( fce != NULL );
- new = malloc( sizeof(my_timer_t) );
- memset(new, 0, sizeof(my_timer_t));
- new->id = new_id++;
- new->type = type;
- new->fce = fce;
- new->arg = arg;
- new->createTime = getMyTime();
- new->time = my_time;
- return new;
+ static int new_id = 0;
+ my_timer_t *new;
+ assert(fce != NULL);
+ new = malloc(sizeof(my_timer_t));
+ memset(new, 0, sizeof(my_timer_t));
+ new->id = new_id++;
+ new->type = type;
+ new->fce = fce;
+ new->arg = arg;
+ new->createTime = getMyTime();
+ new->time = my_time;
+ return new;
}
-static void destroyTimerItem(my_timer_t *p)
+static void
+destroyTimerItem(my_timer_t * p)
{
- assert( p != NULL );
- free(p);
+ assert(p != NULL);
+ free(p);
}
-int addTaskToTimer(list_t *listTimer, int type, void (*fce)(void *p), void *arg, my_time_t my_time)
+int
+addTaskToTimer(list_t * listTimer, int type, void (*fce) (void *p), void *arg,
+ my_time_t my_time)
{
- my_timer_t *new;
+ my_timer_t *new;
- new = newTimerItem(type, fce, arg, my_time);
- addList(listTimer, new);
- return new->id;
+ new = newTimerItem(type, fce, arg, my_time);
+ addList(listTimer, new);
+ return new->id;
}
-void eventTimer(list_t *listTimer)
+void
+eventTimer(list_t * listTimer)
{
- int i;
- my_timer_t *thisTimer;
- my_time_t currentTime;
- currentTime = getMyTime();
- for (i = 0; i < listTimer->count; i++) {
- thisTimer = (my_timer_t *)listTimer->list[i];
- assert(thisTimer != NULL);
- switch (thisTimer->type) {
- case TIMER_ONE:
- if (currentTime >= thisTimer->createTime + thisTimer->time) {
- thisTimer->fce(thisTimer->arg);
- delListItem(listTimer, i, free);
- i--;
- }
- break;
- case TIMER_PERIODIC:
- if (currentTime >= thisTimer->createTime + thisTimer->time) {
- thisTimer->fce(thisTimer->arg);
- thisTimer->createTime = getMyTime();
- }
- break;
- default :
- assert(! _("Timer is really wierdly set!"));
- break;
- }
- }
+ int i;
+ my_timer_t *thisTimer;
+ my_time_t currentTime;
+ currentTime = getMyTime();
+ for (i = 0; i < listTimer->count; i++) {
+ thisTimer = (my_timer_t *) listTimer->list[i];
+ assert(thisTimer != NULL);
+ switch (thisTimer->type) {
+ case TIMER_ONE:
+ if (currentTime >= thisTimer->createTime + thisTimer->time) {
+ thisTimer->fce(thisTimer->arg);
+ delListItem(listTimer, i, free);
+ i--;
+ }
+ break;
+ case TIMER_PERIODIC:
+ if (currentTime >= thisTimer->createTime + thisTimer->time) {
+ thisTimer->fce(thisTimer->arg);
+ thisTimer->createTime = getMyTime();
+ }
+ break;
+ default:
+ assert(!_("Timer is really wierdly set!"));
+ break;
+ }
+ }
}
-void delTimer(list_t *listTimer, int id)
+void
+delTimer(list_t * listTimer, int id)
{
- int i;
- my_timer_t *thisTimer;
-
- for (i = 0; i < listTimer->count; i++) {
- thisTimer = (my_timer_t *)listTimer->list[i];
- assert(thisTimer != NULL);
- if (thisTimer->id == id ) {
- delListItem(listTimer, i, free);
- return;
- }
- }
- assert(! _("There is no such ID!"));
+ int i;
+ my_timer_t *thisTimer;
+
+ for (i = 0; i < listTimer->count; i++) {
+ thisTimer = (my_timer_t *) listTimer->list[i];
+ assert(thisTimer != NULL);
+ if (thisTimer->id == id) {
+ delListItem(listTimer, i, free);
+ return;
+ }
+ }
+ assert(!_("There is no such ID!"));
}
-void destroyTimer(list_t *listTimer)
+void
+destroyTimer(list_t * listTimer)
{
- destroyListItem(listTimer, destroyTimerItem);
+ destroyListItem(listTimer, destroyTimerItem);
}