small fixes

This commit is contained in:
Daan Leijen 2023-03-14 18:24:38 -07:00
parent 10f62eb5a1
commit 4348a05d0f
5 changed files with 32 additions and 20 deletions

View file

@ -9,7 +9,8 @@ terms of the MIT license. A copy of the license can be found in the file
#include "mimalloc-atomic.h"
#include "prim/prim.h" // mi_prim_out_stderr
#include <stdio.h>
#include <stdio.h> // FILE
#include <stdlib.h> // abort
#include <stdarg.h>

View file

@ -504,7 +504,13 @@ mi_msecs_t _mi_prim_clock_now(void) {
// low resolution timer
mi_msecs_t _mi_prim_clock_now(void) {
return ((mi_msecs_t)clock() / ((mi_msecs_t)CLOCKS_PER_SEC / 1000));
#if !defined(CLOCKS_PER_SEC) || (CLOCKS_PER_SEC == 1000) || (CLOCKS_PER_SEC == 0)
return (mi_msecs_t)clock();
#elif (CLOCKS_PER_SEC < 1000)
return (mi_msecs_t)clock() * (1000 / (mi_msecs_t)CLOCKS_PER_SEC);
#else
return (mi_msecs_t)clock() / ((mi_msecs_t)CLOCKS_PER_SEC / 1000);
#endif
}
#endif

View file

@ -110,7 +110,7 @@ static void* mi_prim_mem_grow(size_t size, size_t try_alignment) {
// Note: the `try_alignment` is just a hint and the returned pointer is not guaranteed to be aligned.
void* _mi_prim_alloc(size_t size, size_t try_alignment, bool commit, bool allow_large, bool* is_large) {
MI_UNUSED(allow_large);
MI_UNUSED(allow_large); MI_UNUSED(commit);
*is_large = false;
return mi_prim_mem_grow(size, try_alignment);
}
@ -176,7 +176,13 @@ mi_msecs_t _mi_prim_clock_now(void) {
// low resolution timer
mi_msecs_t _mi_prim_clock_now(void) {
return ((mi_msecs_t)clock() / ((mi_msecs_t)CLOCKS_PER_SEC / 1000));
#if !defined(CLOCKS_PER_SEC) || (CLOCKS_PER_SEC == 1000) || (CLOCKS_PER_SEC == 0)
return (mi_msecs_t)clock();
#elif (CLOCKS_PER_SEC < 1000)
return (mi_msecs_t)clock() * (1000 / (mi_msecs_t)CLOCKS_PER_SEC);
#else
return (mi_msecs_t)clock() / ((mi_msecs_t)CLOCKS_PER_SEC / 1000);
#endif
}
#endif

View file

@ -408,6 +408,10 @@ mi_msecs_t _mi_prim_clock_now(void) {
}
//----------------------------------------------------------------
// Process Info
//----------------------------------------------------------------
#include <windows.h>
#include <psapi.h>
@ -470,7 +474,7 @@ void _mi_prim_out_stderr( const char* msg )
hcon = GetStdHandle(STD_ERROR_HANDLE);
hconIsConsole = ((hcon != INVALID_HANDLE_VALUE) && GetConsoleScreenBufferInfo(hcon, &sbi));
}
const size_t len = strlen(msg);
const size_t len = _mi_strlen(msg);
if (len > 0 && len < UINT32_MAX) {
DWORD written = 0;
if (hconIsConsole) {
@ -501,4 +505,4 @@ bool _mi_prim_getenv(const char* name, char* result, size_t result_size) {
result[0] = 0;
size_t len = GetEnvironmentVariableA(name, result, (DWORD)result_size);
return (len > 0 && len < result_size);
}
}

View file

@ -9,9 +9,9 @@ terms of the MIT license. A copy of the license can be found in the file
#define MIMALLOC_PRIM_H
// note: on all primitive functions, we always get:
// addr != NULL and page aligned
// size > 0 and page aligned
//
// addr != NULL and page aligned
// size > 0 and page aligned
// OS memory configuration
typedef struct mi_os_mem_config_s {
@ -26,12 +26,10 @@ typedef struct mi_os_mem_config_s {
void _mi_prim_mem_init( mi_os_mem_config_t* config );
// Free OS memory
// pre: addr != NULL, size > 0
void _mi_prim_free(void* addr, size_t size );
// Allocate OS memory.
// Allocate OS memory. Return NULL on error.
// The `try_alignment` is just a hint and the returned pointer does not have to be aligned.
// return NULL on error.
// pre: !commit => !allow_large
// try_alignment >= _mi_os_page_size() and a power of 2
void* _mi_prim_alloc(size_t size, size_t try_alignment, bool commit, bool allow_large, bool* is_large);
@ -58,23 +56,20 @@ size_t _mi_prim_numa_node(void);
// Return the number of logical NUMA nodes
size_t _mi_prim_numa_node_count(void);
// High resolution clock
// Clock ticks
mi_msecs_t _mi_prim_clock_now(void);
// Return process information
// Return process information (only for statistics)
void _mi_prim_process_info(mi_msecs_t* utime, mi_msecs_t* stime,
size_t* current_rss, size_t* peak_rss,
size_t* current_commit, size_t* peak_commit, size_t* page_faults);
// Default stderr output.
// msg != NULL && strlen(msg) > 0
// Default stderr output. (only for warnings etc. with verbose enabled)
// msg != NULL && _mi_strlen(msg) > 0
void _mi_prim_out_stderr( const char* msg );
// Get an environment variable.
// Get an environment variable. (only for options)
// name != NULL, result != NULL, result_size >= 64
bool _mi_prim_getenv(const char* name, char* result, size_t result_size);
#endif // MIMALLOC_PRIM_H