Skip to content
Draft
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
33 changes: 33 additions & 0 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,39 @@ jobs:
changed:
- 'test/**'

dispatch-selection:
name: Dispatch backend selection
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Compile dispatch with gnu99
run: >
cc -std=gnu99 -Wall -Wextra -Werror -Iinclude
-DVSYNC_EXPECT_DISPATCH_BACKEND=VSYNC_DISPATCH_BACKEND_GNU
-c test/dispatch/dispatch_backend_probe.c
-o /tmp/dispatch_gnu.o
- name: Compile dispatch with c11 (_Generic)
run: >
cc -std=c11 -Wall -Wextra -Werror -Iinclude
-DVSYNC_EXPECT_DISPATCH_BACKEND=VSYNC_DISPATCH_BACKEND_C11
-c test/dispatch/dispatch_backend_probe.c
-o /tmp/dispatch_c11.o
- name: Ensure strict c99 dispatch include fails
run: |
set +e
cc -std=c99 -Werror -Iinclude \
-DVSYNC_EXPECT_DISPATCH_BACKEND=VSYNC_DISPATCH_BACKEND_DISABLED \
-c test/dispatch/dispatch_backend_probe.c \
-o /tmp/dispatch_c99.o 2> /tmp/dispatch_c99.log
status=$?
if [ $status -eq 0 ]; then
echo "Expected dispatch include to fail under strict ISO C99"
exit 1
fi
grep -q "requires -std=gnu99 or -std=c11+" /tmp/dispatch_c99.log

test-install:
strategy:
matrix:
Expand Down
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ project(
VERSION 2.3.1
DESCRIPTION "VSync atomics")

set(CMAKE_EXPORT_COMMANDS ON)
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)
# Dispatch macros require GNU extensions when building as C99.
set(CMAKE_C_EXTENSIONS ON)

include(GNUInstallDirs)
include(CheckSymbolExists)
Expand Down
3 changes: 2 additions & 1 deletion include/vsync/atomic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

#include <cassert>
extern "C" {
#include <vsync/atomic.h>
#include <vsync/atomic/await.h>
#include <vsync/atomic/core.h>
}
namespace vsync
{
Expand Down
2 changes: 1 addition & 1 deletion include/vsync/atomic/core_bool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#define VATOMIC_CORE_BOOL_HPP
/*!!!Warning: File generated by tmplr; DO NOT EDIT.!!!*/
extern "C" {
#include <vsync/atomic.h>
#include <vsync/atomic/core.h>
}
namespace vsync
{
Expand Down
2 changes: 1 addition & 1 deletion include/vsync/atomic/core_ptr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#define VATOMIC_CORE_PTR_HPP
/*!!!Warning: File generated by tmplr; DO NOT EDIT.!!!*/
extern "C" {
#include <vsync/atomic.h>
#include <vsync/atomic/core.h>
}
namespace vsync
{
Expand Down
2 changes: 1 addition & 1 deletion include/vsync/atomic/core_s16.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: MIT
*/
extern "C" {
#include <vsync/atomic.h>
#include <vsync/atomic/core.h>
}
namespace vsync
{
Expand Down
2 changes: 1 addition & 1 deletion include/vsync/atomic/core_s32.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: MIT
*/
extern "C" {
#include <vsync/atomic.h>
#include <vsync/atomic/core.h>
}
namespace vsync
{
Expand Down
2 changes: 1 addition & 1 deletion include/vsync/atomic/core_s64.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: MIT
*/
extern "C" {
#include <vsync/atomic.h>
#include <vsync/atomic/core.h>
}
namespace vsync
{
Expand Down
2 changes: 1 addition & 1 deletion include/vsync/atomic/core_s8.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: MIT
*/
extern "C" {
#include <vsync/atomic.h>
#include <vsync/atomic/core.h>
}
namespace vsync
{
Expand Down
2 changes: 1 addition & 1 deletion include/vsync/atomic/core_sz.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#define VATOMIC_CORE_SZ_HPP
/*!!!Warning: File generated by tmplr; DO NOT EDIT.!!!*/
extern "C" {
#include <vsync/atomic.h>
#include <vsync/atomic/core.h>
}
namespace vsync
{
Expand Down
2 changes: 1 addition & 1 deletion include/vsync/atomic/core_u16.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#define VATOMIC_CORE_U16_HPP
/*!!!Warning: File generated by tmplr; DO NOT EDIT.!!!*/
extern "C" {
#include <vsync/atomic.h>
#include <vsync/atomic/core.h>
}
namespace vsync
{
Expand Down
2 changes: 1 addition & 1 deletion include/vsync/atomic/core_u32.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#define VATOMIC_CORE_U32_HPP
/*!!!Warning: File generated by tmplr; DO NOT EDIT.!!!*/
extern "C" {
#include <vsync/atomic.h>
#include <vsync/atomic/core.h>
}
namespace vsync
{
Expand Down
2 changes: 1 addition & 1 deletion include/vsync/atomic/core_u64.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#define VATOMIC_CORE_U64_HPP
/*!!!Warning: File generated by tmplr; DO NOT EDIT.!!!*/
extern "C" {
#include <vsync/atomic.h>
#include <vsync/atomic/core.h>
}
namespace vsync
{
Expand Down
2 changes: 1 addition & 1 deletion include/vsync/atomic/core_u8.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#define VATOMIC_CORE_U8_HPP
/*!!!Warning: File generated by tmplr; DO NOT EDIT.!!!*/
extern "C" {
#include <vsync/atomic.h>
#include <vsync/atomic/core.h>
}
namespace vsync
{
Expand Down
60 changes: 38 additions & 22 deletions include/vsync/atomic/dispatch.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) Huawei Technologies Co., Ltd. 2022-2024. All rights reserved.
* Copyright (C) Huawei Technologies Co., Ltd. 2022-2025. All rights reserved.
* SPDX-License-Identifier: MIT
*/

Expand Down Expand Up @@ -48,7 +48,7 @@
* @return current value
* @memord seq_cst
*/
#define vatomic_read(a) V_DISPATCH(ALL_RET, read, mo_seq, a)
#define vatomic_read(a) V_DISPATCH_CONST(ALL_RET, read, mo_seq, a)
/**
* @def vatomic_read_acq(a)
* @brief Dispatches read calls with acquire memory order.
Expand All @@ -59,7 +59,7 @@
* @return current value
* @memord acquire
*/
#define vatomic_read_acq(a) V_DISPATCH(ALL_RET, read, mo_acq, a)
#define vatomic_read_acq(a) V_DISPATCH_CONST(ALL_RET, read, mo_acq, a)
/**
* @def vatomic_read_rlx(a)
* @brief Dispatches read calls with relaxed memory order.
Expand All @@ -70,7 +70,7 @@
* @return current value
* @memord relaxed
*/
#define vatomic_read_rlx(a) V_DISPATCH(ALL_RET, read, mo_rlx, a)
#define vatomic_read_rlx(a) V_DISPATCH_CONST(ALL_RET, read, mo_rlx, a)

/**
* @def vatomic_write(a, v)
Expand Down Expand Up @@ -1250,7 +1250,8 @@
* @return previously read value
* @memord seq_cst
*/
#define vatomic_await_eq(a, c) V_DISPATCH32(ALL_RET, await_eq, mo_seq, a, c)
#define vatomic_await_eq(a, c) \
V_DISPATCH32_CONST(ALL_RET, await_eq, mo_seq, a, c)
/**
* @def vatomic_await_eq_acq(a, c)
* @brief Dispatches await_eq calls with acquire memory order.
Expand All @@ -1262,7 +1263,8 @@
* @return previously read value
* @memord acquire
*/
#define vatomic_await_eq_acq(a, c) V_DISPATCH32(ALL_RET, await_eq, mo_acq, a, c)
#define vatomic_await_eq_acq(a, c) \
V_DISPATCH32_CONST(ALL_RET, await_eq, mo_acq, a, c)
/**
* @def vatomic_await_eq_rlx(a, c)
* @brief Dispatches await_eq calls with relaxed memory order.
Expand All @@ -1274,7 +1276,8 @@
* @return previously read value
* @memord relaxed
*/
#define vatomic_await_eq_rlx(a, c) V_DISPATCH32(ALL_RET, await_eq, mo_rlx, a, c)
#define vatomic_await_eq_rlx(a, c) \
V_DISPATCH32_CONST(ALL_RET, await_eq, mo_rlx, a, c)
/**
* @def vatomic_await_neq(a, c)
* @brief Dispatches await_neq calls with seq_cst memory order.
Expand All @@ -1286,7 +1289,8 @@
* @return value satisfying condition
* @memord seq_cst
*/
#define vatomic_await_neq(a, c) V_DISPATCH32(ALL_RET, await_neq, mo_seq, a, c)
#define vatomic_await_neq(a, c) \
V_DISPATCH32_CONST(ALL_RET, await_neq, mo_seq, a, c)
/**
* @def vatomic_await_neq_acq(a, c)
* @brief Dispatches await_neq calls with acquire memory order.
Expand All @@ -1299,7 +1303,7 @@
* @memord acquire
*/
#define vatomic_await_neq_acq(a, c) \
V_DISPATCH32(ALL_RET, await_neq, mo_acq, a, c)
V_DISPATCH32_CONST(ALL_RET, await_neq, mo_acq, a, c)
/**
* @def vatomic_await_neq_rlx(a, c)
* @brief Dispatches await_neq calls with relaxed memory order.
Expand All @@ -1312,7 +1316,7 @@
* @memord relaxed
*/
#define vatomic_await_neq_rlx(a, c) \
V_DISPATCH32(ALL_RET, await_neq, mo_rlx, a, c)
V_DISPATCH32_CONST(ALL_RET, await_neq, mo_rlx, a, c)
/**
* @def vatomic_await_le(a, c)
* @brief Dispatches await_le calls with seq_cst memory order.
Expand All @@ -1324,7 +1328,8 @@
* @return value satisfying condition
* @memord seq_cst
*/
#define vatomic_await_le(a, c) V_DISPATCH32(INT_RET, await_le, mo_seq, a, c)
#define vatomic_await_le(a, c) \
V_DISPATCH32_CONST(INT_RET, await_le, mo_seq, a, c)
/**
* @def vatomic_await_le_acq(a, c)
* @brief Dispatches await_le calls with acquire memory order.
Expand All @@ -1336,7 +1341,8 @@
* @return value satisfying condition
* @memord acquire
*/
#define vatomic_await_le_acq(a, c) V_DISPATCH32(INT_RET, await_le, mo_acq, a, c)
#define vatomic_await_le_acq(a, c) \
V_DISPATCH32_CONST(INT_RET, await_le, mo_acq, a, c)
/**
* @def vatomic_await_le_rlx(a, c)
* @brief Dispatches await_le calls with relaxed memory order.
Expand All @@ -1348,7 +1354,8 @@
* @return value satisfying condition
* @memord relaxed
*/
#define vatomic_await_le_rlx(a, c) V_DISPATCH32(INT_RET, await_le, mo_rlx, a, c)
#define vatomic_await_le_rlx(a, c) \
V_DISPATCH32_CONST(INT_RET, await_le, mo_rlx, a, c)
/**
* @def vatomic_await_lt(a, c)
* @brief Dispatches await_lt calls with seq_cst memory order.
Expand All @@ -1360,7 +1367,8 @@
* @return value satisfying condition
* @memord seq_cst
*/
#define vatomic_await_lt(a, c) V_DISPATCH32(INT_RET, await_lt, mo_seq, a, c)
#define vatomic_await_lt(a, c) \
V_DISPATCH32_CONST(INT_RET, await_lt, mo_seq, a, c)
/**
* @def vatomic_await_lt_acq(a, c)
* @brief Dispatches await_lt calls with acquire memory order.
Expand All @@ -1372,7 +1380,8 @@
* @return value satisfying condition
* @memord acquire
*/
#define vatomic_await_lt_acq(a, c) V_DISPATCH32(INT_RET, await_lt, mo_acq, a, c)
#define vatomic_await_lt_acq(a, c) \
V_DISPATCH32_CONST(INT_RET, await_lt, mo_acq, a, c)
/**
* @def vatomic_await_lt_rlx(a, c)
* @brief Dispatches await_lt calls with relaxed memory order.
Expand All @@ -1384,7 +1393,8 @@
* @return value satisfying condition
* @memord relaxed
*/
#define vatomic_await_lt_rlx(a, c) V_DISPATCH32(INT_RET, await_lt, mo_rlx, a, c)
#define vatomic_await_lt_rlx(a, c) \
V_DISPATCH32_CONST(INT_RET, await_lt, mo_rlx, a, c)
/**
* @def vatomic_await_gt(a, c)
* @brief Dispatches await_gt calls with seq_cst memory order.
Expand All @@ -1396,7 +1406,8 @@
* @return value satisfying condition
* @memord seq_cst
*/
#define vatomic_await_gt(a, c) V_DISPATCH32(INT_RET, await_gt, mo_seq, a, c)
#define vatomic_await_gt(a, c) \
V_DISPATCH32_CONST(INT_RET, await_gt, mo_seq, a, c)
/**
* @def vatomic_await_gt_acq(a, c)
* @brief Dispatches await_gt calls with acquire memory order.
Expand All @@ -1408,7 +1419,8 @@
* @return value satisfying condition
* @memord acquire
*/
#define vatomic_await_gt_acq(a, c) V_DISPATCH32(INT_RET, await_gt, mo_acq, a, c)
#define vatomic_await_gt_acq(a, c) \
V_DISPATCH32_CONST(INT_RET, await_gt, mo_acq, a, c)
/**
* @def vatomic_await_gt_rlx(a, c)
* @brief Dispatches await_gt calls with relaxed memory order.
Expand All @@ -1420,7 +1432,8 @@
* @return value satisfying condition
* @memord relaxed
*/
#define vatomic_await_gt_rlx(a, c) V_DISPATCH32(INT_RET, await_gt, mo_rlx, a, c)
#define vatomic_await_gt_rlx(a, c) \
V_DISPATCH32_CONST(INT_RET, await_gt, mo_rlx, a, c)
/**
* @def vatomic_await_ge(a, c)
* @brief Dispatches await_ge calls with seq_cst memory order.
Expand All @@ -1432,7 +1445,8 @@
* @return value satisfying condition
* @memord seq_cst
*/
#define vatomic_await_ge(a, c) V_DISPATCH32(INT_RET, await_ge, mo_seq, a, c)
#define vatomic_await_ge(a, c) \
V_DISPATCH32_CONST(INT_RET, await_ge, mo_seq, a, c)
/**
* @def vatomic_await_ge_acq(a, c)
* @brief Dispatches await_ge calls with acquire memory order.
Expand All @@ -1444,7 +1458,8 @@
* @return value satisfying condition
* @memord acquire
*/
#define vatomic_await_ge_acq(a, c) V_DISPATCH32(INT_RET, await_ge, mo_acq, a, c)
#define vatomic_await_ge_acq(a, c) \
V_DISPATCH32_CONST(INT_RET, await_ge, mo_acq, a, c)
/**
* @def vatomic_await_ge_rlx(a, c)
* @brief Dispatches await_ge calls with relaxed memory order.
Expand All @@ -1456,7 +1471,8 @@
* @return value satisfying condition
* @memord relaxed
*/
#define vatomic_await_ge_rlx(a, c) V_DISPATCH32(INT_RET, await_ge, mo_rlx, a, c)
#define vatomic_await_ge_rlx(a, c) \
V_DISPATCH32_CONST(INT_RET, await_ge, mo_rlx, a, c)

/**
* @def vatomic_await_eq_set(a, c, v)
Expand Down
Loading
Loading