summaryrefslogtreecommitdiff
path: root/src/base/myTimer.c
diff options
context:
space:
mode:
authorxHire <xhire@tuxportal.cz>2009-05-26 00:44:42 +0200
committerxHire <xhire@tuxportal.cz>2009-05-26 01:12:04 +0200
commit409083e69d4bb9d8b1eb492b3474c86e093f2de8 (patch)
tree741e3214c07578cde88e700895f203706284017c /src/base/myTimer.c
parentb992c007c186fddf31f67a7ed0bd5789cfb9b85e (diff)
Rewritten messages/comments in code of base
Rectified the coding style in code of base
Diffstat (limited to 'src/base/myTimer.c')
-rw-r--r--src/base/myTimer.c42
1 files changed, 22 insertions, 20 deletions
diff --git a/src/base/myTimer.c b/src/base/myTimer.c
index 0f72d3e..0c1ff5b 100644
--- a/src/base/myTimer.c
+++ b/src/base/myTimer.c
@@ -1,4 +1,3 @@
-
#include <time.h>
#include <assert.h>
#include <stdlib.h>
@@ -6,17 +5,17 @@
#include <sys/time.h>
#include <signal.h>
#ifdef __WIN32__
-# include <time.h>
-#endif
+#include <time.h>
+#endif /* __WIN32__ */
#include "main.h"
#include "list.h"
#include "myTimer.h"
#ifndef PUBLIC_SERVER
-# include "interface.h"
-#endif
+#include "interface.h"
+#endif /* PUBLIC_SERVER */
-static struct timeval my_start = {.tv_sec = 0,.tv_usec = 0 };
+static struct timeval my_start = {.tv_sec = 0, .tv_usec = 0};
list_t *timer_new()
{
@@ -34,12 +33,13 @@ my_time_t timer_get_current_time()
struct timeval now;
my_time_t ticks;
- if (my_start.tv_sec == 0 && my_start.tv_usec == 0)
+ if (my_start.tv_sec == 0 && my_start.tv_usec == 0) {
timer_restart();
+ }
gettimeofday(&now, NULL);
ticks = (now.tv_sec - my_start.tv_sec) * 1000 + (now.tv_usec - my_start.tv_usec) / 1000;
- //printf("-> %d\n", ticks);
+ /*printf("-> %d\n", ticks);*/
return ticks;
}
@@ -50,18 +50,18 @@ my_time_t timer_get_current_timeMicro()
struct timeval now;
my_time_t ticks;
- if (my_micro_start.tv_sec == 0 && my_micro_start.tv_usec == 0)
+ if (my_micro_start.tv_sec == 0 && my_micro_start.tv_usec == 0) {
gettimeofday(&my_micro_start, NULL);
+ }
gettimeofday(&now, NULL);
ticks = (now.tv_sec - my_micro_start.tv_sec) * 1000 * 1000 + (now.tv_usec - my_micro_start.tv_usec);
- //printf("-> %d\n", ticks);
+ /*printf("-> %d\n", ticks);*/
return ticks;
}
-my_timer_t *timer_newItem(int type, void (*fce) (void *p), void *arg,
- my_time_t my_time)
+my_timer_t *timer_newItem(int type, void (*fce) (void *p), void *arg, my_time_t my_time)
{
static int new_id = 0;
my_timer_t *new;
@@ -80,13 +80,13 @@ my_timer_t *timer_newItem(int type, void (*fce) (void *p), void *arg,
return new;
}
-static void timer_destroyItem(my_timer_t * p)
+static void timer_destroyItem(my_timer_t *p)
{
assert(p != NULL);
free(p);
}
-int timer_add_task(list_t * listTimer, int type, void (*fce) (void *p), void *arg, my_time_t my_time)
+int timer_add_task(list_t *listTimer, int type, void (*fce) (void *p), void *arg, my_time_t my_time)
{
my_timer_t *new;
@@ -96,7 +96,7 @@ int timer_add_task(list_t * listTimer, int type, void (*fce) (void *p), void *ar
return new->id;
}
-void timer_event(list_t * listTimer)
+void timer_event(list_t *listTimer)
{
int i;
my_timer_t *thisTimer;
@@ -123,13 +123,13 @@ void timer_event(list_t * listTimer)
}
break;
default:
- assert(!_("Timer is really weirdly set!"));
+ assert(!_("[Error] Bad setting of the timer"));
break;
}
}
}
-void timer_del(list_t * listTimer, int id)
+void timer_del(list_t *listTimer, int id)
{
my_timer_t *thisTimer;
int i;
@@ -139,16 +139,18 @@ void timer_del(list_t * listTimer, int id)
assert(thisTimer != NULL);
- if (thisTimer->id == (unsigned)id) {
+ if (thisTimer->id == (unsigned) id) {
list_del_item(listTimer, i, free);
return;
}
}
- assert(!_("There is no such ID!"));
+
+ fprintf(stderr, _("[Error] Unable to delete event from the timer as it is not present in it [%d]\n"), id);
+ assert(0);
}
-void timer_destroy(list_t * listTimer)
+void timer_destroy(list_t *listTimer)
{
list_destroy_item(listTimer, timer_destroyItem);
}