[dpdk-dev] [PATCH v4 1/2] eal/windows: add pthread mutex lock
Tal Shnaiderman
talshn at nvidia.com
Fri Oct 9 11:19:10 CEST 2020
> Subject: [dpdk-dev] [PATCH v4 1/2] eal/windows: add pthread mutex lock
>
> Add pthread mutex lock as it is needed for the thread safe rte_flow
> functions.
>
> Signed-off-by: Suanming Mou <suanmingm at nvidia.com>
> Acked-by: Dmitry Kozlyuk <dmitry.kozliuk at gmail.com>
> ---
>
> v4:
> - Add PTHREAD_MUTEX_INITIALIZER macro.
>
> v3:
> - No updates.
>
> v2:
> - Using critical section for windows pthread mutex.
>
> ---
>
> lib/librte_eal/windows/include/pthread.h | 35
> ++++++++++++++++++++++++++++++++
> 1 file changed, 35 insertions(+)
>
> diff --git a/lib/librte_eal/windows/include/pthread.h
> b/lib/librte_eal/windows/include/pthread.h
> index 99013dc..c62251f 100644
> --- a/lib/librte_eal/windows/include/pthread.h
> +++ b/lib/librte_eal/windows/include/pthread.h
> @@ -28,6 +28,12 @@
> /* defining pthread_attr_t type on Windows since there is no in Microsoft
> libc*/ typedef void *pthread_attr_t;
>
> +typedef void *pthread_mutexattr_t;
> +
> +typedef CRITICAL_SECTION pthread_mutex_t;
> +
> +#define PTHREAD_MUTEX_INITIALIZER {(void *)-1, -1, 0, 0, 0, 0}
> +
> typedef SYNCHRONIZATION_BARRIER pthread_barrier_t;
>
> #define pthread_barrier_init(barrier, attr, count) \ @@ -139,6 +145,35 @@
> return 0;
> }
>
> +static inline int
> +pthread_mutex_init(pthread_mutex_t *mutex,
> + __rte_unused pthread_mutexattr_t *attr) {
> + InitializeCriticalSection(mutex);
> + return 0;
> +}
> +
> +static inline int
> +pthread_mutex_lock(pthread_mutex_t *mutex) {
> + EnterCriticalSection(mutex);
> + return 0;
> +}
> +
> +static inline int
> +pthread_mutex_unlock(pthread_mutex_t *mutex) {
> + LeaveCriticalSection(mutex);
> + return 0;
> +}
> +
> +static inline int
> +pthread_mutex_destroy(pthread_mutex_t *mutex) {
> + DeleteCriticalSection(mutex);
> + return 0;
> +}
> +
> #ifdef __cplusplus
> }
> #endif
> --
> 1.8.3.1
Tested-by: Tal Shnaiderman <talshn at nvidia.com>
Acked-by: Tal Shnaiderman <talshn at nvidia.com>
More information about the dev
mailing list