From: Narcisa Vasile <navas...@microsoft.com> Add functions for barrier init, destroy, wait.
Signed-off-by: Narcisa Vasile <navas...@microsoft.com> --- lib/librte_eal/common/rte_thread.c | 16 +++++++ lib/librte_eal/include/rte_thread.h | 46 +++++++++++++++++++ lib/librte_eal/include/rte_thread_types.h | 2 + .../include/rte_windows_thread_types.h | 3 ++ lib/librte_eal/windows/rte_thread.c | 27 +++++++++++ 5 files changed, 94 insertions(+) diff --git a/lib/librte_eal/common/rte_thread.c b/lib/librte_eal/common/rte_thread.c index 6e0f970af..0295bf874 100644 --- a/lib/librte_eal/common/rte_thread.c +++ b/lib/librte_eal/common/rte_thread.c @@ -244,6 +244,22 @@ rte_thread_mutex_destroy(rte_thread_mutex_t *mutex) return pthread_mutex_destroy(mutex); } +int +rte_thread_barrier_init(rte_thread_barrier_t *barrier, int count) +{ + return pthread_barrier_init(barrier, NULL, count); +} + +int rte_thread_barrier_wait(rte_thread_barrier_t *barrier) +{ + return pthread_barrier_wait(barrier); +} + +int rte_thread_barrier_destroy(rte_thread_barrier_t *barrier) +{ + return pthread_barrier_destroy(barrier); +} + int rte_thread_cancel(rte_thread_t thread_id) { /* diff --git a/lib/librte_eal/include/rte_thread.h b/lib/librte_eal/include/rte_thread.h index 6710216d6..159c440a2 100644 --- a/lib/librte_eal/include/rte_thread.h +++ b/lib/librte_eal/include/rte_thread.h @@ -295,6 +295,52 @@ int rte_thread_mutex_unlock(rte_thread_mutex_t *mutex); __rte_experimental int rte_thread_mutex_destroy(rte_thread_mutex_t *mutex); +/** + * Initializes a synchronization barrier. + * + * @param barrier + * A pointer that references the newly created 'barrier' object. + * + * @param count + * The number of threads that must enter the barrier before + * the threads can continue execution. + * + * @return + * On success, return 0. + * On failure, return a positive errno-style error number. + */ +__rte_experimental +int rte_thread_barrier_init(rte_thread_barrier_t *barrier, int count); + +/** + * Causes the calling thread to wait at the synchronization barrier 'barrier'. + * + * @param barrier + * The barrier used for synchronizing the threads. + * + * @return + * Return RTE_THREAD_BARRIER_SERIAL_THREAD for the thread synchronized + * at the barrier. + * Return 0 for all other threads. + * Return a positive errno-style error number, in case of failure. + */ +__rte_experimental +int rte_thread_barrier_wait(rte_thread_barrier_t *barrier); + +/** + * Releases all resources used by a synchronization barrier + * and uninitializes it. + * + * @param barrier + * The barrier to be destroyed. + * + * @return + * On success, return 0. + * On failure, return a positive errno-style error number. + */ +__rte_experimental +int rte_thread_barrier_destroy(rte_thread_barrier_t *barrier); + /** * Terminates a thread. * diff --git a/lib/librte_eal/include/rte_thread_types.h b/lib/librte_eal/include/rte_thread_types.h index 37bc7af2b..b055bbf67 100644 --- a/lib/librte_eal/include/rte_thread_types.h +++ b/lib/librte_eal/include/rte_thread_types.h @@ -7,6 +7,7 @@ #include <pthread.h> +#define RTE_THREAD_BARRIER_SERIAL_THREAD PTHREAD_BARRIER_SERIAL_THREAD #define RTE_THREAD_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER #define EAL_THREAD_PRIORITY_NORMAL 0 @@ -14,5 +15,6 @@ typedef pthread_t rte_thread_t; typedef pthread_mutex_t rte_thread_mutex_t; +typedef pthread_barrier_t rte_thread_barrier_t; #endif /* _RTE_THREAD_TYPES_H_ */ diff --git a/lib/librte_eal/windows/include/rte_windows_thread_types.h b/lib/librte_eal/windows/include/rte_windows_thread_types.h index 47c6b2664..b6209e6eb 100644 --- a/lib/librte_eal/windows/include/rte_windows_thread_types.h +++ b/lib/librte_eal/windows/include/rte_windows_thread_types.h @@ -7,10 +7,13 @@ #include <rte_windows.h> +#define RTE_THREAD_BARRIER_SERIAL_THREAD TRUE + #define EAL_THREAD_PRIORITY_NORMAL THREAD_PRIORITY_NORMAL #define EAL_THREAD_PRIORITY_REALTIME_CIRTICAL THREAD_PRIORITY_TIME_CRITICAL typedef DWORD rte_thread_t; typedef CRITICAL_SECTION rte_thread_mutex_t; +typedef SYNCHRONIZATION_BARRIER rte_thread_barrier_t; #endif /* _RTE_THREAD_TYPES_H_ */ diff --git a/lib/librte_eal/windows/rte_thread.c b/lib/librte_eal/windows/rte_thread.c index 8a2c7691a..0d7cae254 100644 --- a/lib/librte_eal/windows/rte_thread.c +++ b/lib/librte_eal/windows/rte_thread.c @@ -445,6 +445,33 @@ rte_thread_mutex_destroy(rte_thread_mutex_t *mutex) return 0; } +int +rte_thread_barrier_init(rte_thread_barrier_t *barrier, int count) +{ + int ret = 0; + + if (!InitializeSynchronizationBarrier(barrier, count, -1)) { + ret = rte_thread_translate_win32_error(GetLastError()); + RTE_LOG_WIN32_ERR("InitializeSynchronizationBarrier()"); + return ret; + } + return 0; +} + +int +rte_thread_barrier_wait(rte_thread_barrier_t *barrier) +{ + return EnterSynchronizationBarrier(barrier, + SYNCHRONIZATION_BARRIER_FLAGS_BLOCK_ONLY); +} + +int +rte_thread_barrier_destroy(rte_thread_barrier_t *barrier) +{ + DeleteSynchronizationBarrier(barrier); + return 0; +} + int rte_thread_cancel(rte_thread_t thread_id) { -- 2.30.0.vfs.0.2