[dpdk-dev] [PATCH 1/2] eal/windows: add pthread mutex lock
Suanming Mou
suanmingm at nvidia.com
Sun Sep 27 10:20:16 CEST 2020
Add pthread mutex lock as it is needed for the thread safe rte flow
functions.
Signed-off-by: Suanming Mou <suanmingm at nvidia.com>
---
lib/librte_eal/windows/include/pthread.h | 46 ++++++++++++++++++++++++++++++++
1 file changed, 46 insertions(+)
diff --git a/lib/librte_eal/windows/include/pthread.h b/lib/librte_eal/windows/include/pthread.h
index 99013dc..4e2e0b3 100644
--- a/lib/librte_eal/windows/include/pthread.h
+++ b/lib/librte_eal/windows/include/pthread.h
@@ -28,6 +28,10 @@
/* 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 HANDLE pthread_mutex_t;
+
typedef SYNCHRONIZATION_BARRIER pthread_barrier_t;
#define pthread_barrier_init(barrier, attr, count) \
@@ -139,6 +143,48 @@
return 0;
}
+static inline int
+pthread_mutex_init(pthread_mutex_t *mutex,
+ __rte_unused pthread_mutexattr_t *attr)
+{
+ *mutex = CreateMutex(NULL, FALSE, NULL);
+ if (*mutex == NULL) {
+ RTE_LOG_WIN32_ERR("CreateMutex()");
+ return -1;
+ }
+ return 0;
+}
+
+static inline int
+pthread_mutex_lock(pthread_mutex_t *mutex)
+{
+ if (WaitForSingleObject(*mutex, INFINITE) != WAIT_OBJECT_0) {
+ RTE_LOG_WIN32_ERR("WaitForSingleObject()");
+ return -1;
+ }
+ return 0;
+}
+
+static inline int
+pthread_mutex_unlock(pthread_mutex_t *mutex)
+{
+ if (!ReleaseMutex(*mutex)) {
+ RTE_LOG_WIN32_ERR("ReleaseMutex()");
+ return -1;
+ }
+ return 0;
+}
+
+static inline int
+pthread_mutex_destroy(pthread_mutex_t *mutex)
+{
+ if (!CloseHandle(*mutex)) {
+ RTE_LOG_WIN32_ERR("CloseHandle()");
+ return -1;
+ }
+ return 0;
+}
+
#ifdef __cplusplus
}
#endif
--
1.8.3.1
More information about the dev
mailing list