fixes while testing on Windows
This commit is contained in:
parent
d281ab3d28
commit
02f926c2c7
5 changed files with 71 additions and 30 deletions
|
@ -28,7 +28,7 @@ static atomic_bool __rcl_is_initialized = ATOMIC_VAR_INIT(false);
|
||||||
static rcl_allocator_t __rcl_allocator = {0};
|
static rcl_allocator_t __rcl_allocator = {0};
|
||||||
static int __rcl_argc = 0;
|
static int __rcl_argc = 0;
|
||||||
static char ** __rcl_argv = NULL;
|
static char ** __rcl_argv = NULL;
|
||||||
static atomic_uint_fast64_t __rcl_instance_id = ATOMIC_VAR_INIT(0);
|
static atomic_uint_least64_t __rcl_instance_id = ATOMIC_VAR_INIT(0);
|
||||||
static uint64_t __rcl_next_unique_id = 0;
|
static uint64_t __rcl_next_unique_id = 0;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -49,9 +49,7 @@ __clean_up_init()
|
||||||
rcl_ret_t
|
rcl_ret_t
|
||||||
rcl_init(int argc, char ** argv, rcl_allocator_t allocator)
|
rcl_init(int argc, char ** argv, rcl_allocator_t allocator)
|
||||||
{
|
{
|
||||||
bool was_initialized;
|
if (rcl_atomic_exchange_bool(&__rcl_is_initialized, true)) {
|
||||||
rcl_atomic_exchange(&__rcl_is_initialized, was_initialized, true);
|
|
||||||
if (was_initialized) {
|
|
||||||
RCL_SET_ERROR_MSG("rcl_init called while already initialized");
|
RCL_SET_ERROR_MSG("rcl_init called while already initialized");
|
||||||
return RCL_RET_ALREADY_INIT;
|
return RCL_RET_ALREADY_INIT;
|
||||||
}
|
}
|
||||||
|
@ -66,7 +64,7 @@ rcl_init(int argc, char ** argv, rcl_allocator_t allocator)
|
||||||
memset(__rcl_argv, 0, sizeof(char **) * argc);
|
memset(__rcl_argv, 0, sizeof(char **) * argc);
|
||||||
for (size_t i = 0; i < argc; ++i) {
|
for (size_t i = 0; i < argc; ++i) {
|
||||||
__rcl_argv[i] = (char *)__rcl_allocator.allocate(strlen(argv[i]), __rcl_allocator.state);
|
__rcl_argv[i] = (char *)__rcl_allocator.allocate(strlen(argv[i]), __rcl_allocator.state);
|
||||||
strcpy(__rcl_argv[i], argv[i]); // NOLINT(runtime/printf)
|
memcpy(__rcl_argv[i], argv[i], strlen(argv[i]));
|
||||||
}
|
}
|
||||||
rcl_atomic_store(&__rcl_instance_id, ++__rcl_next_unique_id);
|
rcl_atomic_store(&__rcl_instance_id, ++__rcl_next_unique_id);
|
||||||
if (rcl_atomic_load_uint64_t(&__rcl_instance_id) == 0) {
|
if (rcl_atomic_load_uint64_t(&__rcl_instance_id) == 0) {
|
||||||
|
|
|
@ -28,14 +28,25 @@
|
||||||
|
|
||||||
#define rcl_atomic_store(object, desired) atomic_store(object, desired)
|
#define rcl_atomic_store(object, desired) atomic_store(object, desired)
|
||||||
|
|
||||||
#else
|
#else // !defined(WIN32)
|
||||||
|
|
||||||
#endif
|
#include "./stdatomic_helper/win32/stdatomic.h"
|
||||||
|
|
||||||
|
#define rcl_atomic_load(object, out) rcl_win32_atomic_load(object, out)
|
||||||
|
|
||||||
|
#define rcl_atomic_compare_exchange_strong(object, out, expected, desired) \
|
||||||
|
rcl_win32_atomic_compare_exchange_strong(object, out, expected, desired)
|
||||||
|
|
||||||
|
#define rcl_atomic_exchange(object, out, desired) rcl_win32_atomic_exchange(object, out, desired)
|
||||||
|
|
||||||
|
#define rcl_atomic_store(object, desired) rcl_win32_atomic_store(object, desired)
|
||||||
|
|
||||||
|
#endif // !defined(WIN32)
|
||||||
|
|
||||||
static inline bool
|
static inline bool
|
||||||
rcl_atomic_load_bool(atomic_bool * a_bool)
|
rcl_atomic_load_bool(atomic_bool * a_bool)
|
||||||
{
|
{
|
||||||
bool result;
|
bool result = false;
|
||||||
rcl_atomic_load(a_bool, result);
|
rcl_atomic_load(a_bool, result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -43,7 +54,7 @@ rcl_atomic_load_bool(atomic_bool * a_bool)
|
||||||
static inline uint64_t
|
static inline uint64_t
|
||||||
rcl_atomic_load_uint64_t(atomic_uint_least64_t * a_uint64_t)
|
rcl_atomic_load_uint64_t(atomic_uint_least64_t * a_uint64_t)
|
||||||
{
|
{
|
||||||
uint64_t result;
|
uint64_t result = 0;
|
||||||
rcl_atomic_load(a_uint64_t, result);
|
rcl_atomic_load(a_uint64_t, result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -51,7 +62,7 @@ rcl_atomic_load_uint64_t(atomic_uint_least64_t * a_uint64_t)
|
||||||
static inline uintptr_t
|
static inline uintptr_t
|
||||||
rcl_atomic_load_uintptr_t(atomic_uintptr_t * a_uintptr_t)
|
rcl_atomic_load_uintptr_t(atomic_uintptr_t * a_uintptr_t)
|
||||||
{
|
{
|
||||||
uintptr_t result;
|
uintptr_t result = 0;
|
||||||
rcl_atomic_load(a_uintptr_t, result);
|
rcl_atomic_load(a_uintptr_t, result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -65,6 +76,14 @@ rcl_atomic_compare_exchange_strong_uint_least64_t(
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline bool
|
||||||
|
rcl_atomic_exchange_bool(atomic_bool * a_bool, bool desired)
|
||||||
|
{
|
||||||
|
bool result;
|
||||||
|
rcl_atomic_exchange(a_bool, result, desired);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
static inline uint64_t
|
static inline uint64_t
|
||||||
rcl_atomic_exchange_uint64_t(atomic_uint_least64_t * a_uint64_t, uint64_t desired)
|
rcl_atomic_exchange_uint64_t(atomic_uint_least64_t * a_uint64_t, uint64_t desired)
|
||||||
{
|
{
|
||||||
|
|
|
@ -188,26 +188,31 @@ typedef _Atomic (uintmax_t) atomic_uintmax_t;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define rcl_win32_atomic_compare_exchange_strong(object, out, expected, desired) \
|
#define rcl_win32_atomic_compare_exchange_strong(object, out, expected, desired) \
|
||||||
|
__pragma(warning( push )) \
|
||||||
|
__pragma(warning( disable : 4244 )) \
|
||||||
do { \
|
do { \
|
||||||
switch (sizeof(object)) { \
|
switch (sizeof(object)) { \
|
||||||
case sizeof(uint64_t): \
|
case sizeof(uint64_t): \
|
||||||
out = _InterlockedCompareExchange64((LONGLONG *) object, desired, expected); \
|
out = _InterlockedCompareExchange64((LONGLONG *) object, desired, *expected); \
|
||||||
break; \
|
break; \
|
||||||
case sizeof(uint32_t): \
|
case sizeof(uint32_t): \
|
||||||
out = _InterlockedCompareExchange((LONG *) object, desired, expected); \
|
out = _InterlockedCompareExchange((LONG *) object, desired, *expected); \
|
||||||
break; \
|
break; \
|
||||||
case sizeof(uint16_t): \
|
case sizeof(uint16_t): \
|
||||||
out = _InterlockedCompareExchange16((SHORT *) object, desired, expected); \
|
out = _InterlockedCompareExchange16((SHORT *) object, desired, *expected); \
|
||||||
break; \
|
break; \
|
||||||
default: \
|
default: \
|
||||||
break; \
|
break; \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0) \
|
||||||
|
__pragma(warning( pop ))
|
||||||
|
|
||||||
#define rcl_win32_atomic_compare_exchange_weak(object, out, expected, desired) \
|
#define rcl_win32_atomic_compare_exchange_weak(object, out, expected, desired) \
|
||||||
rcl_win32_atomic_compare_exchange_strong(object, out, expected, desired)
|
rcl_win32_atomic_compare_exchange_strong(object, out, expected, desired)
|
||||||
|
|
||||||
#define rcl_win32_atomic_exchange((object), out, desired) \
|
#define rcl_win32_atomic_exchange(object, out, desired) \
|
||||||
|
__pragma(warning( push )) \
|
||||||
|
__pragma(warning( disable : 4244 )) \
|
||||||
do { \
|
do { \
|
||||||
switch (sizeof(object)) { \
|
switch (sizeof(object)) { \
|
||||||
case sizeof(uint64_t): \
|
case sizeof(uint64_t): \
|
||||||
|
@ -222,9 +227,12 @@ typedef _Atomic (uintmax_t) atomic_uintmax_t;
|
||||||
default: \
|
default: \
|
||||||
break; \
|
break; \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0) \
|
||||||
|
__pragma(warning( pop ))
|
||||||
|
|
||||||
#define rcl_win32_atomic_fetch_add(object, out, operand) \
|
#define rcl_win32_atomic_fetch_add(object, out, operand) \
|
||||||
|
__pragma(warning( push )) \
|
||||||
|
__pragma(warning( disable : 4244 )) \
|
||||||
do { \
|
do { \
|
||||||
switch (sizeof(object)) { \
|
switch (sizeof(object)) { \
|
||||||
case sizeof(uint64_t): \
|
case sizeof(uint64_t): \
|
||||||
|
@ -239,9 +247,12 @@ typedef _Atomic (uintmax_t) atomic_uintmax_t;
|
||||||
default: \
|
default: \
|
||||||
break; \
|
break; \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0) \
|
||||||
|
__pragma(warning( pop ))
|
||||||
|
|
||||||
#define rcl_win32_atomic_fetch_and(object, out, operand) \
|
#define rcl_win32_atomic_fetch_and(object, out, operand) \
|
||||||
|
__pragma(warning( push )) \
|
||||||
|
__pragma(warning( disable : 4244 )) \
|
||||||
do { \
|
do { \
|
||||||
switch (sizeof(object)) { \
|
switch (sizeof(object)) { \
|
||||||
case sizeof(uint64_t): \
|
case sizeof(uint64_t): \
|
||||||
|
@ -256,9 +267,12 @@ typedef _Atomic (uintmax_t) atomic_uintmax_t;
|
||||||
default: \
|
default: \
|
||||||
break; \
|
break; \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0) \
|
||||||
|
__pragma(warning( pop ))
|
||||||
|
|
||||||
#define rcl_win32_atomic_fetch_or(object, out, operand) \
|
#define rcl_win32_atomic_fetch_or(object, out, operand) \
|
||||||
|
__pragma(warning( push )) \
|
||||||
|
__pragma(warning( disable : 4244 )) \
|
||||||
do { \
|
do { \
|
||||||
switch (sizeof(object)) { \
|
switch (sizeof(object)) { \
|
||||||
case sizeof(uint64_t): \
|
case sizeof(uint64_t): \
|
||||||
|
@ -273,12 +287,15 @@ typedef _Atomic (uintmax_t) atomic_uintmax_t;
|
||||||
default: \
|
default: \
|
||||||
break; \
|
break; \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0) \
|
||||||
|
__pragma(warning( pop ))
|
||||||
|
|
||||||
#define rcl_win32_atomic_fetch_sub(object, out, operand) \
|
#define rcl_win32_atomic_fetch_sub(object, out, operand) \
|
||||||
rcl_win32_atomic_fetch_add(object, out, -(operand))
|
rcl_win32_atomic_fetch_add(object, out, -(operand))
|
||||||
|
|
||||||
#define rcl_win32_atomic_fetch_xor(object, out, operand) \
|
#define rcl_win32_atomic_fetch_xor(object, out, operand) \
|
||||||
|
__pragma(warning( push )) \
|
||||||
|
__pragma(warning( disable : 4244 )) \
|
||||||
do { \
|
do { \
|
||||||
switch (sizeof(object)) { \
|
switch (sizeof(object)) { \
|
||||||
case sizeof(uint64_t): \
|
case sizeof(uint64_t): \
|
||||||
|
@ -293,9 +310,12 @@ typedef _Atomic (uintmax_t) atomic_uintmax_t;
|
||||||
default: \
|
default: \
|
||||||
break; \
|
break; \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0) \
|
||||||
|
__pragma(warning( pop ))
|
||||||
|
|
||||||
#define rcl_win32_atomic_load(object) \
|
#define rcl_win32_atomic_load(object, out) \
|
||||||
|
__pragma(warning( push )) \
|
||||||
|
__pragma(warning( disable : 4244 )) \
|
||||||
do { \
|
do { \
|
||||||
switch (sizeof(object)) { \
|
switch (sizeof(object)) { \
|
||||||
case sizeof(uint64_t): \
|
case sizeof(uint64_t): \
|
||||||
|
@ -310,12 +330,13 @@ typedef _Atomic (uintmax_t) atomic_uintmax_t;
|
||||||
default: \
|
default: \
|
||||||
break; \
|
break; \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0) \
|
||||||
|
__pragma(warning( pop ))
|
||||||
|
|
||||||
#define rcl_win32_atomic_store(object, desired) \
|
#define rcl_win32_atomic_store(object, desired) \
|
||||||
do { \
|
do { \
|
||||||
MemoryBarrier(); \
|
MemoryBarrier(); \
|
||||||
object = (desired); \
|
(object)->__val = (desired); \
|
||||||
MemoryBarrier(); \
|
MemoryBarrier(); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
|
|
@ -124,7 +124,7 @@ rcl_ret_t
|
||||||
rcl_steady_time_point_now(rcl_steady_time_point_t * now)
|
rcl_steady_time_point_now(rcl_steady_time_point_t * now)
|
||||||
{
|
{
|
||||||
RCL_CHECK_ARGUMENT_FOR_NULL(now, RCL_RET_INVALID_ARGUMENT);
|
RCL_CHECK_ARGUMENT_FOR_NULL(now, RCL_RET_INVALID_ARGUMENT);
|
||||||
WINAPI ret = QueryPerformanceFrequency();
|
// WINAPI ret = QueryPerformanceFrequency();
|
||||||
return RCL_RET_OK;
|
return RCL_RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -194,7 +194,10 @@ rcl_wait_set_get_allocator(const rcl_wait_set_t * wait_set, rcl_allocator_t * al
|
||||||
RCL_SET_ERROR_MSG("wait set is invalid"); \
|
RCL_SET_ERROR_MSG("wait set is invalid"); \
|
||||||
return RCL_RET_WAIT_SET_INVALID; \
|
return RCL_RET_WAIT_SET_INVALID; \
|
||||||
} \
|
} \
|
||||||
memset(wait_set->Type ## s, 0, sizeof(rcl_ ## Type ## _t *) * wait_set->size_of_ ## Type ## s); \
|
memset( \
|
||||||
|
(void *)wait_set->Type ## s, \
|
||||||
|
0, \
|
||||||
|
sizeof(rcl_ ## Type ## _t *) * wait_set->size_of_ ## Type ## s); \
|
||||||
wait_set->impl->Type ## _index = 0; \
|
wait_set->impl->Type ## _index = 0; \
|
||||||
|
|
||||||
#define SET_CLEAR_RMW(Type, RMWStorage, RMWCount) \
|
#define SET_CLEAR_RMW(Type, RMWStorage, RMWCount) \
|
||||||
|
@ -214,14 +217,14 @@ rcl_wait_set_get_allocator(const rcl_wait_set_t * wait_set, rcl_allocator_t * al
|
||||||
rcl_allocator_t allocator = wait_set->impl->allocator; \
|
rcl_allocator_t allocator = wait_set->impl->allocator; \
|
||||||
if (size == 0) { \
|
if (size == 0) { \
|
||||||
if (wait_set->Type ## s) { \
|
if (wait_set->Type ## s) { \
|
||||||
allocator.deallocate(wait_set->Type ## s, allocator.state); \
|
allocator.deallocate((void *)wait_set->Type ## s, allocator.state); \
|
||||||
wait_set->Type ## s = NULL; \
|
wait_set->Type ## s = NULL; \
|
||||||
} \
|
} \
|
||||||
ExtraDealloc \
|
ExtraDealloc \
|
||||||
} else { \
|
} else { \
|
||||||
wait_set->size_of_ ## Type ## s = 0; \
|
wait_set->size_of_ ## Type ## s = 0; \
|
||||||
wait_set->Type ## s = (const rcl_ ## Type ## _t * *)allocator.reallocate( \
|
wait_set->Type ## s = (const rcl_ ## Type ## _t * *)allocator.reallocate( \
|
||||||
wait_set->Type ## s, sizeof(rcl_ ## Type ## _t *) * size, allocator.state); \
|
(void *)wait_set->Type ## s, sizeof(rcl_ ## Type ## _t *) * size, allocator.state); \
|
||||||
RCL_CHECK_FOR_NULL_WITH_MSG( \
|
RCL_CHECK_FOR_NULL_WITH_MSG( \
|
||||||
wait_set->Type ## s, "allocating memory failed", return RCL_RET_BAD_ALLOC); \
|
wait_set->Type ## s, "allocating memory failed", return RCL_RET_BAD_ALLOC); \
|
||||||
wait_set->size_of_ ## Type ## s = size; \
|
wait_set->size_of_ ## Type ## s = size; \
|
||||||
|
@ -232,7 +235,7 @@ rcl_wait_set_get_allocator(const rcl_wait_set_t * wait_set, rcl_allocator_t * al
|
||||||
#define SET_RESIZE_RMW_DEALLOC(RMWStorage, RMWCount) \
|
#define SET_RESIZE_RMW_DEALLOC(RMWStorage, RMWCount) \
|
||||||
/* Also deallocate the rmw storage. */ \
|
/* Also deallocate the rmw storage. */ \
|
||||||
if (wait_set->impl->RMWStorage) { \
|
if (wait_set->impl->RMWStorage) { \
|
||||||
allocator.deallocate(wait_set->impl->RMWStorage, allocator.state); \
|
allocator.deallocate((void *)wait_set->impl->RMWStorage, allocator.state); \
|
||||||
wait_set->impl->RMWStorage = NULL; \
|
wait_set->impl->RMWStorage = NULL; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -242,7 +245,7 @@ rcl_wait_set_get_allocator(const rcl_wait_set_t * wait_set, rcl_allocator_t * al
|
||||||
wait_set->impl->RMWStorage = (void **)allocator.reallocate( \
|
wait_set->impl->RMWStorage = (void **)allocator.reallocate( \
|
||||||
wait_set->impl->RMWStorage, sizeof(rcl_ ## Type ## _t *) * size, allocator.state); \
|
wait_set->impl->RMWStorage, sizeof(rcl_ ## Type ## _t *) * size, allocator.state); \
|
||||||
if (!wait_set->impl->RMWStorage) { \
|
if (!wait_set->impl->RMWStorage) { \
|
||||||
allocator.deallocate(wait_set->Type ## s, allocator.state); \
|
allocator.deallocate((void *)wait_set->Type ## s, allocator.state); \
|
||||||
wait_set->size_of_ ## Type ## s = 0; \
|
wait_set->size_of_ ## Type ## s = 0; \
|
||||||
RCL_SET_ERROR_MSG("allocating memory failed"); \
|
RCL_SET_ERROR_MSG("allocating memory failed"); \
|
||||||
return RCL_RET_BAD_ALLOC; \
|
return RCL_RET_BAD_ALLOC; \
|
||||||
|
@ -375,7 +378,7 @@ rcl_wait(rcl_wait_set_t * wait_set, int64_t timeout)
|
||||||
if (ret != RCL_RET_OK) {
|
if (ret != RCL_RET_OK) {
|
||||||
return ret; // The rcl error state should already be set.
|
return ret; // The rcl error state should already be set.
|
||||||
}
|
}
|
||||||
if (timer_timeout < min_timeout) {
|
if ((uint64_t)timer_timeout < min_timeout) {
|
||||||
min_timeout = timer_timeout;
|
min_timeout = timer_timeout;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue