File tree Expand file tree Collapse file tree
include/vsync/thread/internal Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11/*
2- * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025 . All rights reserved.
2+ * Copyright (C) Huawei Technologies Co., Ltd. 2024-2026 . All rights reserved.
33 * SPDX-License-Identifier: MIT
44 */
55
99 * futex syscalls
1010 *
1111 * If the macros are not defined, we mock the futex syscall with a simple
12- * spinning mechanism.
12+ * spinning mechanism. Define `FUTEX_CUSTOM` to provide `vfutex_wait` and
13+ * `vfutex_wake` in user code, even on Linux.
1314 *
1415 * @note on linux compile with `-D_GNU_SOURCE`.
1516 ******************************************************************************/
2526 #define FUTEX_USERSPACE
2627#endif
2728
28- #if defined(VSYNC_VERIFICATION ) || defined(FUTEX_USERSPACE )
29+ #if defined(FUTEX_CUSTOM )
30+
31+ void vfutex_wait (vatomic32_t * m , vuint32_t v );
32+ void vfutex_wake (vatomic32_t * m , vuint32_t v );
33+
34+ #elif defined(VSYNC_VERIFICATION ) || defined(FUTEX_USERSPACE )
2935
3036 #if defined(VFUTEX_LIVENESS )
3137 #include <vsync/thread/internal/futex_mock_liveness.h>
Original file line number Diff line number Diff line change @@ -19,13 +19,19 @@ if [ "${STYLE}" != "" ]; then
1919 STYLE=" :${STYLE} "
2020fi
2121
22+ if which clang-format-14 > /dev/null 2>&1 ; then
23+ CLANG_FORMAT=clang-format-14
24+ else
25+ CLANG_FORMAT=clang-format
26+ fi
27+
2228# Apply clang-format to all *.h and *.c files in src folder.
2329find " $@ " \( -name ' *.h' -o -name ' *.c' -o -name ' *.cpp' -o -name ' *.hpp' -o -name ' *.cxx' \) \
2430 -not -path ' */build/*' \
2531 -not -path ' */deps/*' \
2632 -not -path ' */vatomic/*' \
2733 -type f \
28- -exec clang-format -style=file${STYLE} -i {} +
34+ -exec ${CLANG_FORMAT} -style=file${STYLE} -i {} +
2935
3036if [ " ${SILENT} " != " true" ]; then
3137 # Display changed files and exit with 1 if there were differences.
Original file line number Diff line number Diff line change 1+ file (GLOB SRCS *.c )
2+ foreach (SRC ${SRCS} )
3+ get_filename_component (TEST ${SRC} NAME_WE )
4+
5+ add_executable (${TEST} ${SRC} )
6+ target_link_libraries (${TEST} vsync pthread )
7+ v_add_bin_test (NAME ${TEST} COMMAND ${TEST} )
8+ endforeach ()
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright (C) Huawei Technologies Co., Ltd. 2026. All rights reserved.
3+ * SPDX-License-Identifier: MIT
4+ */
5+
6+ #define FUTEX_CUSTOM
7+ #include <vsync/thread/internal/futex.h>
8+
9+ static vatomic32_t g_word = VATOMIC_INIT (0 );
10+ static vuint32_t g_wait_count ;
11+ static vuint32_t g_wake_count ;
12+ static vuint32_t g_wait_value ;
13+ static vuint32_t g_wake_value ;
14+
15+ void
16+ vfutex_wait (vatomic32_t * m , vuint32_t v )
17+ {
18+ ASSERT (m == & g_word );
19+ g_wait_count ++ ;
20+ g_wait_value = v ;
21+ }
22+
23+ void
24+ vfutex_wake (vatomic32_t * m , vuint32_t v )
25+ {
26+ ASSERT (m == & g_word );
27+ g_wake_count ++ ;
28+ g_wake_value = v ;
29+ }
30+
31+ int
32+ main (void )
33+ {
34+ vfutex_wait (& g_word , 7U );
35+ vfutex_wake (& g_word , FUTEX_WAKE_ONE );
36+
37+ ASSERT (g_wait_count == 1U );
38+ ASSERT (g_wake_count == 1U );
39+ ASSERT (g_wait_value == 7U );
40+ ASSERT (g_wake_value == FUTEX_WAKE_ONE );
41+
42+ return 0 ;
43+ }
You can’t perform that action at this time.
0 commit comments