Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add windows atomic #304

Merged
merged 9 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ elseif(CMAKE_SYSTEM_NAME MATCHES "Emscripten")
elseif(CMAKE_SYSTEM_NAME MATCHES "Windows")
add_definition(ZENOH_WINDOWS)
add_definition(_CRT_SECURE_NO_WARNINGS)
add_definition(ZENOH_NO_STDATOMIC)
elseif(CMAKE_SYSTEM_NAME MATCHES "Generic")
if(WITH_ZEPHYR)
add_definition(ZENOH_ZEPHYR)
Expand Down Expand Up @@ -158,6 +157,8 @@ if(CMAKE_BUILD_TYPE MATCHES "DEBUG")
if(UNIX)
add_compile_options(-c -Wall -Wextra -Werror -Wshadow -Wpedantic -Wunused -Wstrict-prototypes -pipe -g -O0)
elseif(MSVC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /std:c11 /experimental:c11atomics")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++latest /experimental:c11atomics")
add_compile_options(/W4 /WX /Od)
elseif(CMAKE_SYSTEM_NAME MATCHES "Generic")
add_compile_options(-Wall -Wextra -Wno-unused-parameter -Wmissing-prototypes -pipe -g -O0)
Expand All @@ -166,7 +167,8 @@ elseif(CMAKE_BUILD_TYPE MATCHES "RELEASE")
if(UNIX)
add_compile_options(-pipe -O3)
elseif(MSVC)
# add_compile_options(/O2)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /std:c11 /experimental:c11atomics")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++latest /experimental:c11atomics")
elseif(CMAKE_SYSTEM_NAME MATCHES "Generic")
add_compile_options(-pipe -O3)
endif()
Expand Down
16 changes: 8 additions & 8 deletions include/zenoh-pico/collections/pointer.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
#include <stdbool.h>
#include <stdint.h>

#if ZENOH_C_STANDARD != 99 && !defined(ZENOH_NO_STDATOMIC)
#if ZENOH_C_STANDARD != 99

#ifndef __cplusplus
#include <stdatomic.h>
#define z_atomic(X) _Atomic X
#define _z_atomic(X) _Atomic X
#define _z_atomic_store_explicit atomic_store_explicit
#define _z_atomic_fetch_add_explicit atomic_fetch_add_explicit
#define _z_atomic_fetch_sub_explicit atomic_fetch_sub_explicit
Expand All @@ -31,26 +31,26 @@
#define _z_memory_order_relaxed memory_order_relaxed
#else
#include <atomic>
#define z_atomic(X) std::atomic<X>
#define _z_atomic(X) std::atomic<X>
#define _z_atomic_store_explicit std::atomic_store_explicit
#define _z_atomic_fetch_add_explicit std::atomic_fetch_add_explicit
#define _z_atomic_fetch_sub_explicit std::atomic_fetch_sub_explicit
#define _z_memory_order_acquire std::memory_order_acquire
#define _z_memory_order_release std::memory_order_release
#define _z_memory_order_relaxed std::memory_order_relaxed
#endif
#endif // __cplusplus

/*------------------ Internal Array Macros ------------------*/
#define _Z_POINTER_DEFINE(name, type) \
typedef struct { \
type##_t *ptr; \
z_atomic(unsigned int) * _cnt; \
_z_atomic(unsigned int) * _cnt; \
} name##_sptr_t; \
static inline name##_sptr_t name##_sptr_new(type##_t val) { \
name##_sptr_t p; \
p.ptr = (type##_t *)z_malloc(sizeof(type##_t)); \
if (p.ptr != NULL) { \
p._cnt = (z_atomic(unsigned int) *)z_malloc(sizeof(z_atomic(unsigned int) *)); \
p._cnt = (_z_atomic(unsigned int) *)z_malloc(sizeof(_z_atomic(unsigned int) *)); \
if (p._cnt != NULL) { \
*p.ptr = val; \
_z_atomic_store_explicit(p._cnt, 1, _z_memory_order_relaxed); \
Expand Down Expand Up @@ -89,7 +89,7 @@
if (p->ptr != NULL) { \
type##_clear(p->ptr); \
z_free(p->ptr); \
z_free(p->_cnt); \
z_free((void *)p->_cnt); \
} \
} \
} \
Expand Down Expand Up @@ -150,6 +150,6 @@
} \
return dropped; \
}
#endif
#endif // ZENOH_C_STANDARD != 99

#endif /* ZENOH_PICO_COLLECTIONS_POINTER_H */
Loading