mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-05-04 22:49:32 +03:00
Merge pull request #41 from jedisct1/c-prototypes
fn() is not a valid C prototype
This commit is contained in:
commit
f5d1170ae7
7 changed files with 41 additions and 41 deletions
|
@ -39,7 +39,7 @@ static inline bool mi_atomic_compare_exchange(volatile uintptr_t* p, uintptr_t e
|
||||||
// Atomically exchange a value.
|
// Atomically exchange a value.
|
||||||
static inline uintptr_t mi_atomic_exchange(volatile uintptr_t* p, uintptr_t exchange);
|
static inline uintptr_t mi_atomic_exchange(volatile uintptr_t* p, uintptr_t exchange);
|
||||||
|
|
||||||
static inline void mi_atomic_yield();
|
static inline void mi_atomic_yield(void);
|
||||||
|
|
||||||
// Atomically compare and exchange a pointer; returns `true` if successful.
|
// Atomically compare and exchange a pointer; returns `true` if successful.
|
||||||
static inline bool mi_atomic_compare_exchange_ptr(volatile void** p, void* newp, void* compare) {
|
static inline bool mi_atomic_compare_exchange_ptr(volatile void** p, void* newp, void* compare) {
|
||||||
|
@ -85,7 +85,7 @@ static inline bool mi_atomic_compare_exchange(volatile uintptr_t* p, uintptr_t e
|
||||||
static inline uintptr_t mi_atomic_exchange(volatile uintptr_t* p, uintptr_t exchange) {
|
static inline uintptr_t mi_atomic_exchange(volatile uintptr_t* p, uintptr_t exchange) {
|
||||||
return (uintptr_t)RC64(_InterlockedExchange)((volatile intptr_t*)p, (intptr_t)exchange);
|
return (uintptr_t)RC64(_InterlockedExchange)((volatile intptr_t*)p, (intptr_t)exchange);
|
||||||
}
|
}
|
||||||
static inline void mi_atomic_yield() {
|
static inline void mi_atomic_yield(void) {
|
||||||
YieldProcessor();
|
YieldProcessor();
|
||||||
}
|
}
|
||||||
static inline int64_t mi_atomic_add(volatile int64_t* p, int64_t add) {
|
static inline int64_t mi_atomic_add(volatile int64_t* p, int64_t add) {
|
||||||
|
@ -150,23 +150,23 @@ static inline uintptr_t mi_atomic_exchange(volatile uintptr_t* p, uintptr_t exch
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
#include <thread>
|
#include <thread>
|
||||||
static inline void mi_atomic_yield() {
|
static inline void mi_atomic_yield(void) {
|
||||||
std::this_thread::yield();
|
std::this_thread::yield();
|
||||||
}
|
}
|
||||||
#elif (defined(__GNUC__) || defined(__clang__)) && \
|
#elif (defined(__GNUC__) || defined(__clang__)) && \
|
||||||
(defined(__x86_64__) || defined(__i386__) || defined(__arm__) || defined(__aarch64__))
|
(defined(__x86_64__) || defined(__i386__) || defined(__arm__) || defined(__aarch64__))
|
||||||
#if defined(__x86_64__) || defined(__i386__)
|
#if defined(__x86_64__) || defined(__i386__)
|
||||||
static inline void mi_atomic_yield() {
|
static inline void mi_atomic_yield(void) {
|
||||||
asm volatile ("pause" ::: "memory");
|
asm volatile ("pause" ::: "memory");
|
||||||
}
|
}
|
||||||
#elif defined(__arm__) || defined(__aarch64__)
|
#elif defined(__arm__) || defined(__aarch64__)
|
||||||
static inline void mi_atomic_yield() {
|
static inline void mi_atomic_yield(void) {
|
||||||
asm volatile("yield");
|
asm volatile("yield");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
static inline void mi_atomic_yield() {
|
static inline void mi_atomic_yield(void) {
|
||||||
sleep(0);
|
sleep(0);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -24,7 +24,7 @@ void _mi_verbose_message(const char* fmt, ...);
|
||||||
// "init.c"
|
// "init.c"
|
||||||
extern mi_stats_t _mi_stats_main;
|
extern mi_stats_t _mi_stats_main;
|
||||||
extern const mi_page_t _mi_page_empty;
|
extern const mi_page_t _mi_page_empty;
|
||||||
bool _mi_is_main_thread();
|
bool _mi_is_main_thread(void);
|
||||||
uintptr_t _mi_ptr_cookie(const void* p);
|
uintptr_t _mi_ptr_cookie(const void* p);
|
||||||
uintptr_t _mi_random_shuffle(uintptr_t x);
|
uintptr_t _mi_random_shuffle(uintptr_t x);
|
||||||
uintptr_t _mi_random_init(uintptr_t seed /* can be zero */);
|
uintptr_t _mi_random_init(uintptr_t seed /* can be zero */);
|
||||||
|
@ -38,7 +38,7 @@ bool _mi_os_protect(void* addr, size_t size);
|
||||||
bool _mi_os_unprotect(void* addr, size_t size);
|
bool _mi_os_unprotect(void* addr, size_t size);
|
||||||
|
|
||||||
void* _mi_os_alloc_aligned(size_t size, size_t alignment, mi_os_tld_t* tld);
|
void* _mi_os_alloc_aligned(size_t size, size_t alignment, mi_os_tld_t* tld);
|
||||||
size_t _mi_os_page_size();
|
size_t _mi_os_page_size(void);
|
||||||
uintptr_t _mi_align_up(uintptr_t sz, size_t alignment);
|
uintptr_t _mi_align_up(uintptr_t sz, size_t alignment);
|
||||||
|
|
||||||
// "segment.c"
|
// "segment.c"
|
||||||
|
@ -145,7 +145,7 @@ extern bool _mi_process_is_initialized;
|
||||||
|
|
||||||
extern mi_decl_thread mi_heap_t* _mi_heap_default; // default heap to allocate from
|
extern mi_decl_thread mi_heap_t* _mi_heap_default; // default heap to allocate from
|
||||||
|
|
||||||
static inline mi_heap_t* mi_get_default_heap() {
|
static inline mi_heap_t* mi_get_default_heap(void) {
|
||||||
#ifdef MI_TLS_RECURSE_GUARD
|
#ifdef MI_TLS_RECURSE_GUARD
|
||||||
// on some platforms, like macOS, the dynamic loader calls `malloc`
|
// on some platforms, like macOS, the dynamic loader calls `malloc`
|
||||||
// to initialize thread local data. To avoid recursion, we need to avoid
|
// to initialize thread local data. To avoid recursion, we need to avoid
|
||||||
|
@ -288,15 +288,15 @@ static inline void mi_block_set_next(mi_page_t* page, mi_block_t* block, mi_bloc
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
static inline uintptr_t _mi_thread_id() mi_attr_noexcept {
|
static inline uintptr_t _mi_thread_id(void) mi_attr_noexcept {
|
||||||
// Windows: works on Intel and ARM in both 32- and 64-bit
|
// Windows: works on Intel and ARM in both 32- and 64-bit
|
||||||
return (uintptr_t)NtCurrentTeb();
|
return (uintptr_t)NtCurrentTeb(void);
|
||||||
}
|
}
|
||||||
#elif (defined(__GNUC__) || defined(__clang__)) && \
|
#elif (defined(__GNUC__) || defined(__clang__)) && \
|
||||||
(defined(__x86_64__) || defined(__i386__) || defined(__arm__) || defined(__aarch64__))
|
(defined(__x86_64__) || defined(__i386__) || defined(__arm__) || defined(__aarch64__))
|
||||||
// TLS register on x86 is in the FS or GS register
|
// TLS register on x86 is in the FS or GS register
|
||||||
// see: https://akkadia.org/drepper/tls.pdf
|
// see: https://akkadia.org/drepper/tls.pdf
|
||||||
static inline uintptr_t _mi_thread_id() mi_attr_noexcept {
|
static inline uintptr_t _mi_thread_id(void) mi_attr_noexcept {
|
||||||
uintptr_t tid;
|
uintptr_t tid;
|
||||||
#if defined(__i386__)
|
#if defined(__i386__)
|
||||||
__asm__("movl %%gs:0, %0" : "=r" (tid) : : ); // 32-bit always uses GS
|
__asm__("movl %%gs:0, %0" : "=r" (tid) : : ); // 32-bit always uses GS
|
||||||
|
@ -313,7 +313,7 @@ static inline uintptr_t _mi_thread_id() mi_attr_noexcept {
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
// otherwise use standard C
|
// otherwise use standard C
|
||||||
static inline uintptr_t _mi_thread_id() mi_attr_noexcept {
|
static inline uintptr_t _mi_thread_id(void) mi_attr_noexcept {
|
||||||
return (uintptr_t)&_mi_heap_default;
|
return (uintptr_t)&_mi_heap_default;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -193,7 +193,7 @@ static size_t mi__msize_dbg_term(void* p, int block_type) {
|
||||||
// ------------------------------------------------------
|
// ------------------------------------------------------
|
||||||
// implement our own global atexit handler
|
// implement our own global atexit handler
|
||||||
// ------------------------------------------------------
|
// ------------------------------------------------------
|
||||||
typedef void (cbfun_t)();
|
typedef void (cbfun_t)(void);
|
||||||
typedef int (atexit_fun_t)(cbfun_t* fn);
|
typedef int (atexit_fun_t)(cbfun_t* fn);
|
||||||
typedef uintptr_t encoded_t;
|
typedef uintptr_t encoded_t;
|
||||||
|
|
||||||
|
@ -229,7 +229,7 @@ static void init_canary()
|
||||||
|
|
||||||
|
|
||||||
// initialize the list
|
// initialize the list
|
||||||
static void mi_initialize_atexit() {
|
static void mi_initialize_atexit(void) {
|
||||||
InitializeCriticalSection(&atexit_lock);
|
InitializeCriticalSection(&atexit_lock);
|
||||||
init_canary();
|
init_canary();
|
||||||
}
|
}
|
||||||
|
@ -495,12 +495,12 @@ mi_decl_export void mi_patches_disable(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enable all patches normally
|
// Enable all patches normally
|
||||||
mi_decl_export bool mi_patches_enable() {
|
mi_decl_export bool mi_patches_enable(void) {
|
||||||
return _mi_patches_apply( PATCH_TARGET, NULL );
|
return _mi_patches_apply( PATCH_TARGET, NULL );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enable all patches in termination phase where free is a no-op
|
// Enable all patches in termination phase where free is a no-op
|
||||||
mi_decl_export bool mi_patches_enable_term() {
|
mi_decl_export bool mi_patches_enable_term(void) {
|
||||||
return _mi_patches_apply(PATCH_TARGET_TERM, NULL);
|
return _mi_patches_apply(PATCH_TARGET_TERM, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -544,7 +544,7 @@ static atexit_fun_t* crt_atexit = NULL;
|
||||||
static atexit_fun_t* crt_at_quick_exit = NULL;
|
static atexit_fun_t* crt_at_quick_exit = NULL;
|
||||||
|
|
||||||
|
|
||||||
static bool mi_patches_resolve() {
|
static bool mi_patches_resolve(void) {
|
||||||
// get all loaded modules
|
// get all loaded modules
|
||||||
HANDLE process = GetCurrentProcess(); // always -1, no need to release
|
HANDLE process = GetCurrentProcess(); // always -1, no need to release
|
||||||
DWORD needed = 0;
|
DWORD needed = 0;
|
||||||
|
@ -604,12 +604,12 @@ static void NTAPI mi_fls_unwind(PVOID value) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mi_patches_atexit() {
|
static void mi_patches_atexit(void) {
|
||||||
mi_execute_exit_list(&atexit_list);
|
mi_execute_exit_list(&atexit_list);
|
||||||
mi_patches_enable_term(); // enter termination phase and patch realloc/free with a no-op
|
mi_patches_enable_term(); // enter termination phase and patch realloc/free with a no-op
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mi_patches_at_quick_exit() {
|
static void mi_patches_at_quick_exit(void) {
|
||||||
mi_execute_exit_list(&at_quick_exit_list);
|
mi_execute_exit_list(&at_quick_exit_list);
|
||||||
mi_patches_enable_term(); // enter termination phase and patch realloc/free with a no-op
|
mi_patches_enable_term(); // enter termination phase and patch realloc/free with a no-op
|
||||||
}
|
}
|
||||||
|
|
|
@ -157,12 +157,12 @@ void mi_collect(bool force) mi_attr_noexcept {
|
||||||
Heap new
|
Heap new
|
||||||
----------------------------------------------------------- */
|
----------------------------------------------------------- */
|
||||||
|
|
||||||
mi_heap_t* mi_heap_get_default() {
|
mi_heap_t* mi_heap_get_default(void) {
|
||||||
mi_thread_init();
|
mi_thread_init();
|
||||||
return mi_get_default_heap();
|
return mi_get_default_heap();
|
||||||
}
|
}
|
||||||
|
|
||||||
mi_heap_t* mi_heap_get_backing() {
|
mi_heap_t* mi_heap_get_backing(void) {
|
||||||
mi_heap_t* heap = mi_heap_get_default();
|
mi_heap_t* heap = mi_heap_get_default();
|
||||||
mi_assert_internal(heap!=NULL);
|
mi_assert_internal(heap!=NULL);
|
||||||
mi_heap_t* bheap = heap->tld->heap_backing;
|
mi_heap_t* bheap = heap->tld->heap_backing;
|
||||||
|
@ -177,7 +177,7 @@ uintptr_t _mi_heap_random(mi_heap_t* heap) {
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
mi_heap_t* mi_heap_new() {
|
mi_heap_t* mi_heap_new(void) {
|
||||||
mi_heap_t* bheap = mi_heap_get_backing();
|
mi_heap_t* bheap = mi_heap_get_backing();
|
||||||
mi_heap_t* heap = mi_heap_malloc_tp(bheap, mi_heap_t);
|
mi_heap_t* heap = mi_heap_malloc_tp(bheap, mi_heap_t);
|
||||||
if (heap==NULL) return NULL;
|
if (heap==NULL) return NULL;
|
||||||
|
|
18
src/init.c
18
src/init.c
|
@ -181,7 +181,7 @@ typedef struct mi_thread_data_s {
|
||||||
} mi_thread_data_t;
|
} mi_thread_data_t;
|
||||||
|
|
||||||
// Initialize the thread local default heap, called from `mi_thread_init`
|
// Initialize the thread local default heap, called from `mi_thread_init`
|
||||||
static bool _mi_heap_init() {
|
static bool _mi_heap_init(void) {
|
||||||
if (mi_heap_is_initialized(_mi_heap_default)) return true;
|
if (mi_heap_is_initialized(_mi_heap_default)) return true;
|
||||||
if (_mi_is_main_thread()) {
|
if (_mi_is_main_thread()) {
|
||||||
// the main heap is statically allocated
|
// the main heap is statically allocated
|
||||||
|
@ -212,7 +212,7 @@ static bool _mi_heap_init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Free the thread local default heap (called from `mi_thread_done`)
|
// Free the thread local default heap (called from `mi_thread_done`)
|
||||||
static bool _mi_heap_done() {
|
static bool _mi_heap_done(void) {
|
||||||
mi_heap_t* heap = _mi_heap_default;
|
mi_heap_t* heap = _mi_heap_default;
|
||||||
if (!mi_heap_is_initialized(heap)) return true;
|
if (!mi_heap_is_initialized(heap)) return true;
|
||||||
|
|
||||||
|
@ -285,7 +285,7 @@ static bool _mi_heap_done() {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Set up handlers so `mi_thread_done` is called automatically
|
// Set up handlers so `mi_thread_done` is called automatically
|
||||||
static void mi_process_setup_auto_thread_done() {
|
static void mi_process_setup_auto_thread_done(void) {
|
||||||
static bool tls_initialized = false; // fine if it races
|
static bool tls_initialized = false; // fine if it races
|
||||||
if (tls_initialized) return;
|
if (tls_initialized) return;
|
||||||
tls_initialized = true;
|
tls_initialized = true;
|
||||||
|
@ -299,12 +299,12 @@ static void mi_process_setup_auto_thread_done() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool _mi_is_main_thread() {
|
bool _mi_is_main_thread(void) {
|
||||||
return (_mi_heap_main.thread_id==0 || _mi_heap_main.thread_id == _mi_thread_id());
|
return (_mi_heap_main.thread_id==0 || _mi_heap_main.thread_id == _mi_thread_id());
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is called from the `mi_malloc_generic`
|
// This is called from the `mi_malloc_generic`
|
||||||
void mi_thread_init() mi_attr_noexcept
|
void mi_thread_init(void) mi_attr_noexcept
|
||||||
{
|
{
|
||||||
// ensure our process has started already
|
// ensure our process has started already
|
||||||
mi_process_init();
|
mi_process_init();
|
||||||
|
@ -329,7 +329,7 @@ void mi_thread_init() mi_attr_noexcept
|
||||||
_mi_verbose_message("thread init: 0x%zx\n", _mi_thread_id());
|
_mi_verbose_message("thread init: 0x%zx\n", _mi_thread_id());
|
||||||
}
|
}
|
||||||
|
|
||||||
void mi_thread_done() mi_attr_noexcept {
|
void mi_thread_done(void) mi_attr_noexcept {
|
||||||
// stats
|
// stats
|
||||||
mi_heap_t* heap = mi_get_default_heap();
|
mi_heap_t* heap = mi_get_default_heap();
|
||||||
if (!_mi_is_main_thread() && mi_heap_is_initialized(heap)) {
|
if (!_mi_is_main_thread() && mi_heap_is_initialized(heap)) {
|
||||||
|
@ -350,7 +350,7 @@ void mi_thread_done() mi_attr_noexcept {
|
||||||
// --------------------------------------------------------
|
// --------------------------------------------------------
|
||||||
static void mi_process_done(void);
|
static void mi_process_done(void);
|
||||||
|
|
||||||
void mi_process_init() mi_attr_noexcept {
|
void mi_process_init(void) mi_attr_noexcept {
|
||||||
// ensure we are called once
|
// ensure we are called once
|
||||||
if (_mi_process_is_initialized) return;
|
if (_mi_process_is_initialized) return;
|
||||||
_mi_process_is_initialized = true;
|
_mi_process_is_initialized = true;
|
||||||
|
@ -406,7 +406,7 @@ static void mi_process_done(void) {
|
||||||
|
|
||||||
#elif defined(__cplusplus)
|
#elif defined(__cplusplus)
|
||||||
// C++: use static initialization to detect process start
|
// C++: use static initialization to detect process start
|
||||||
static bool _mi_process_init() {
|
static bool _mi_process_init(void) {
|
||||||
mi_process_init();
|
mi_process_init();
|
||||||
return (mi_main_thread_id != 0);
|
return (mi_main_thread_id != 0);
|
||||||
}
|
}
|
||||||
|
@ -414,7 +414,7 @@ static void mi_process_done(void) {
|
||||||
|
|
||||||
#elif defined(__GNUC__) || defined(__clang__)
|
#elif defined(__GNUC__) || defined(__clang__)
|
||||||
// GCC,Clang: use the constructor attribute
|
// GCC,Clang: use the constructor attribute
|
||||||
static void __attribute__((constructor)) _mi_process_init() {
|
static void __attribute__((constructor)) _mi_process_init(void) {
|
||||||
mi_process_init();
|
mi_process_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
2
src/os.c
2
src/os.c
|
@ -50,7 +50,7 @@ static void* mi_align_down_ptr(void* p, size_t alignment) {
|
||||||
static void* os_pool_alloc(size_t size, size_t alignment, mi_os_tld_t* tld);
|
static void* os_pool_alloc(size_t size, size_t alignment, mi_os_tld_t* tld);
|
||||||
|
|
||||||
// cached OS page size
|
// cached OS page size
|
||||||
size_t _mi_os_page_size() {
|
size_t _mi_os_page_size(void) {
|
||||||
static size_t page_size = 0;
|
static size_t page_size = 0;
|
||||||
if (page_size == 0) {
|
if (page_size == 0) {
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
|
|
16
src/stats.c
16
src/stats.c
|
@ -123,7 +123,7 @@ static void mi_stats_add(mi_stats_t* stats, const mi_stats_t* src) {
|
||||||
static void mi_printf_amount(int64_t n, int64_t unit, FILE* out, const char* fmt) {
|
static void mi_printf_amount(int64_t n, int64_t unit, FILE* out, const char* fmt) {
|
||||||
char buf[32];
|
char buf[32];
|
||||||
int len = 32;
|
int len = 32;
|
||||||
char* suffix = (unit <= 0 ? " " : "b");
|
const char* suffix = (unit <= 0 ? " " : "b");
|
||||||
double base = (unit == 0 ? 1000.0 : 1024.0);
|
double base = (unit == 0 ? 1000.0 : 1024.0);
|
||||||
if (unit>0) n *= unit;
|
if (unit>0) n *= unit;
|
||||||
|
|
||||||
|
@ -256,15 +256,15 @@ static void _mi_stats_print(mi_stats_t* stats, double secs, FILE* out) mi_attr_n
|
||||||
}
|
}
|
||||||
|
|
||||||
static double mi_clock_end(double start);
|
static double mi_clock_end(double start);
|
||||||
static double mi_clock_start();
|
static double mi_clock_start(void);
|
||||||
static double mi_time_start = 0.0;
|
static double mi_time_start = 0.0;
|
||||||
|
|
||||||
static mi_stats_t* mi_stats_get_default() {
|
static mi_stats_t* mi_stats_get_default(void) {
|
||||||
mi_heap_t* heap = mi_heap_get_default();
|
mi_heap_t* heap = mi_heap_get_default();
|
||||||
return &heap->tld->stats;
|
return &heap->tld->stats;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mi_stats_reset() mi_attr_noexcept {
|
void mi_stats_reset(void) mi_attr_noexcept {
|
||||||
mi_stats_t* stats = mi_stats_get_default();
|
mi_stats_t* stats = mi_stats_get_default();
|
||||||
if (stats != &_mi_stats_main) { memset(stats, 0, sizeof(mi_stats_t)); }
|
if (stats != &_mi_stats_main) { memset(stats, 0, sizeof(mi_stats_t)); }
|
||||||
memset(&_mi_stats_main, 0, sizeof(mi_stats_t));
|
memset(&_mi_stats_main, 0, sizeof(mi_stats_t));
|
||||||
|
@ -305,7 +305,7 @@ static double mi_to_seconds(LARGE_INTEGER t) {
|
||||||
return ((double)(t.QuadPart) / freq);
|
return ((double)(t.QuadPart) / freq);
|
||||||
}
|
}
|
||||||
|
|
||||||
static double mi_clock_now() {
|
static double mi_clock_now(void) {
|
||||||
LARGE_INTEGER t;
|
LARGE_INTEGER t;
|
||||||
QueryPerformanceCounter(&t);
|
QueryPerformanceCounter(&t);
|
||||||
return mi_to_seconds(t);
|
return mi_to_seconds(t);
|
||||||
|
@ -313,14 +313,14 @@ static double mi_clock_now() {
|
||||||
#else
|
#else
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#ifdef CLOCK_REALTIME
|
#ifdef CLOCK_REALTIME
|
||||||
static double mi_clock_now() {
|
static double mi_clock_now(void) {
|
||||||
struct timespec t;
|
struct timespec t;
|
||||||
clock_gettime(CLOCK_REALTIME, &t);
|
clock_gettime(CLOCK_REALTIME, &t);
|
||||||
return (double)t.tv_sec + (1.0e-9 * (double)t.tv_nsec);
|
return (double)t.tv_sec + (1.0e-9 * (double)t.tv_nsec);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
// low resolution timer
|
// low resolution timer
|
||||||
static double mi_clock_now() {
|
static double mi_clock_now(void) {
|
||||||
return ((double)clock() / (double)CLOCKS_PER_SEC);
|
return ((double)clock() / (double)CLOCKS_PER_SEC);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -329,7 +329,7 @@ static double mi_clock_now() {
|
||||||
|
|
||||||
static double mi_clock_diff = 0.0;
|
static double mi_clock_diff = 0.0;
|
||||||
|
|
||||||
static double mi_clock_start() {
|
static double mi_clock_start(void) {
|
||||||
if (mi_clock_diff == 0.0) {
|
if (mi_clock_diff == 0.0) {
|
||||||
double t0 = mi_clock_now();
|
double t0 = mi_clock_now();
|
||||||
mi_clock_diff = mi_clock_now() - t0;
|
mi_clock_diff = mi_clock_now() - t0;
|
||||||
|
|
Loading…
Add table
Reference in a new issue