rsys

Basic data structures and low-level features
git clone git://git.meso-star.fr/rsys.git
Log | Files | Refs | README | LICENSE

commit a1badb49b858c335fc5c92fef1762ccfc18796d0
parent 08e759751da0c8d901da0dbbf7278c02ed6fcda2
Author: vaplv <vaplv@free.fr>
Date:   Sun, 26 Jan 2014 01:08:27 +0100

Remove the useless time_val and time_sleep functions

Diffstat:
Msrc/CMakeLists.txt | 6++++++
Msrc/clock_time.c | 40----------------------------------------
Msrc/clock_time.h | 6------
Msrc/mem_allocator.c | 2+-
Msrc/rsys.h | 2+-
Msrc/test_time.c | 29++++++++++-------------------
6 files changed, 18 insertions(+), 67 deletions(-)

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt @@ -12,6 +12,9 @@ find_package(OpenMP) ################################################################################ # Setup compile flags/parameters ################################################################################ +if(CMAKE_SIZEOF_VOID_P EQUAL 8) + set(BUILD_32-BIT OFF CACHE BOOL "Force code generation for 32-bit environment") +endif(CMAKE_SIZEOF_VOID_P EQUAL 8) set(C_FLAGS "-pedantic -std=c89 -fvisibility=hidden -fstrict-aliasing") set(C_FLAGS_WARN "-Wall -Wextra -Wcast-align -Wmissing-declarations -Wmissing-prototypes -Wconversion") @@ -19,6 +22,9 @@ set(C_FLAGS_LINK "-Wl,--no-undefined") if(CMAKE_HOST_UNIX) set(C_FLAGS_UNIX "-fPIC") endif(CMAKE_HOST_UNIX) +if(BUILD_32-BIT) + set(C_FLAGS "${C_FLAGS} -m32") +endif(BUILD_32-BIT) set(CMAKE_C_FLAGS "${C_FLAGS} ${C_FLAGS_UNIX} ${C_FLAGS_WARN} ${C_FLAGS_LINK}") set(CMAKE_C_FLAGS_DEBUG "-g -DDEBUG") diff --git a/src/clock_time.c b/src/clock_time.c @@ -59,46 +59,6 @@ time_add(struct time* res, const struct time* a, const struct time* b) } } -void -time_val_set(struct time* time, const int64_t val, const enum time_unit unit) -{ - int64_t ns = 0; - int64_t s = 0; - - if(unit & (TIME_NSEC | TIME_USEC | TIME_MSEC)) { - switch(unit) { - case TIME_NSEC: - s = val / 1000000000L; - ns = val - s * 1000000000L; - break; - case TIME_USEC: - s = val / 1000000L; - ns = (val - s * 1000000L) * 1000L; - break; - case TIME_MSEC: - s = val / 1000L; - ns = (val - s * 1000L) * 1000000L; - break; - default: - ASSERT(0 && "Unreachable code"); - break; - } - } else { - int64_t factor = 0; - switch(unit) { - case TIME_SEC: factor = 0L; break; - case TIME_MIN: factor = 60L; break; - case TIME_HOUR: factor = 3600L; break; - case TIME_DAY: factor = 86400L; break; - default: ASSERT(0 && "Unreachable code"); break; - } - s = val * factor; - ns = 0; - } - time->sec = s; - time->nsec = ns; -} - int64_t time_val(const struct time* time, enum time_unit unit) { diff --git a/src/clock_time.h b/src/clock_time.h @@ -43,12 +43,6 @@ time_add const struct time* a, const struct time* b); -RSYS_API void -time_val_set - (struct time* time, - const int64_t val, - const enum time_unit unit); - RSYS_API int64_t time_val (const struct time* time, diff --git a/src/mem_allocator.c b/src/mem_allocator.c @@ -79,7 +79,7 @@ mem_realloc(void* mem, const size_t size) const size_t old_size = mem_size(mem); ASSERT - ( old_size < (size_t)INT64_MAX + ( old_size < SIZE_MAX && g_alloc_counter.allocated_size >= (int64_t)old_size); ATOMIC_SUB( &g_alloc_counter.allocated_size, old_size); diff --git a/src/rsys.h b/src/rsys.h @@ -182,5 +182,5 @@ #define OFFSET_PTR(Ptr, Offset) (void*)((uintptr_t)(Ptr) + (Offset)) -#endif /* SNLSYS_H */ +#endif /* RSYS_H */ diff --git a/src/test_time.c b/src/test_time.c @@ -13,33 +13,24 @@ int main(int argc, char** argv) { struct time start, end, res; + char dump[512]; int64_t time = 0; + int64_t i = 0; (void)argc, (void)argv; - time_val_set(&res, 1250, TIME_MSEC); time_current(&start); - time_sleep(&res); + FOR_EACH(i, 0, INT32_MAX / 64); /* Active wait */ time_current(&end); time_sub(&res, &end, &start); time = time_val(&res, TIME_NSEC); - CHECK(absi64(time - 1250000000) <= 1000000 , 1); - time = time_val(&res, TIME_USEC); - CHECK(absi64(time - 1250000) <= 1000 , 1); - time = time_val(&res, TIME_MSEC); - CHECK(absi64(time - 1250) <= 1 , 1); - time = time_val(&res, TIME_SEC); - CHECK(time, 1); - CHECK(time_val(&res, TIME_NSEC) >= time_val(&res, TIME_USEC) * 1000, 1); - CHECK(time_val(&res, TIME_USEC) >= time_val(&res, TIME_MSEC) * 1000, 1); - CHECK(time_val(&res, TIME_MSEC) >= time_val(&res, TIME_SEC) * 1000, 1); + CHECK(time > 0, 1 ); + CHECK( time_val(&res, TIME_USEC), time / 1000 ); + CHECK( time_val(&res, TIME_MSEC), time / 1000000 ); + CHECK( time_val(&res, TIME_SEC), time / 1000000000 ); - time_val_set(&res, 1234, TIME_USEC); - time_current(&start); - time_sleep(&res); - time_current(&end); - time_sub(&res, &end, &start); - time = time_val(&res, TIME_NSEC); - CHECK(absi64(time - 1234000) <= 1000000 , 1); + time_dump + (&res, TIME_SEC|TIME_MSEC|TIME_USEC|TIME_NSEC, NULL, dump, sizeof(dump)); + printf("%s\n", dump); return 0; }