3 /* sysdep.c -- all system dependency */
4 /* no system header should be loaded out of this file so that we have only */
5 /* one file to check when porting to another OS */
7 /* Copyright (c) 2004 Martin Quinson. All rights reserved. */
9 /* This program is free software; you can redistribute it and/or modify it
10 * under the terms of the license (GNU LGPL) which comes with this package. */
12 #include "xbt/sysdep.h"
13 #include "xbt/xbt_portability.h" /* private */
20 XBT_PUBLIC(void) xbt_free_f(void* p)
26 /* TSC (tick-level) timers are said to be unreliable on SMP hosts and thus
27 disabled in SDL source code */
30 /* \defgroup XBT_sysdep All system dependency
31 * \brief This section describes many macros/functions that can serve as
35 double xbt_os_time(void) {
36 #ifdef HAVE_GETTIMEOFDAY
39 gettimeofday(&tv, NULL);
41 return (double)(tv.tv_sec + tv.tv_usec / 1000000.0);
44 return (double)(time(NULL));
45 #endif /* HAVE_GETTIMEOFDAY? */
48 /*XBT_LOG_NEW_DEFAULT_SUBCATEGORY(sysdep, xbt, "System dependency");*/
51 struct s_xbt_os_timer {
52 #ifdef HAVE_GETTIMEOFDAY
53 struct timeval start,stop;
55 unsigned long int start,stop;
59 xbt_os_timer_t xbt_os_timer_new(void) {
60 return xbt_new0(struct s_xbt_os_timer,1);
62 void xbt_os_timer_free(xbt_os_timer_t timer) {
65 void xbt_os_timer_start(xbt_os_timer_t timer) {
66 #ifdef HAVE_GETTIMEOFDAY
67 gettimeofday(&(timer->start), NULL);
69 timer->start = (unsigned long int)(time(NULL));
72 void xbt_os_timer_stop(xbt_os_timer_t timer) {
73 #ifdef HAVE_GETTIMEOFDAY
74 gettimeofday(&(timer->stop), NULL);
76 timer->stop = (unsigned long int)(time(NULL));
79 double xbt_os_timer_elapsed(xbt_os_timer_t timer) {
80 #ifdef HAVE_GETTIMEOFDAY
81 return ((double)timer->stop.tv_sec) - ((double)timer->start.tv_sec) +
82 ((((double)timer->stop.tv_usec) - ((double)timer->start.tv_usec)) / 1000000.0);
84 return (double)timer->stop - (double)timer->start;