From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id A7DD5A04BC; Sun, 27 Sep 2020 10:20:55 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id B123B1D936; Sun, 27 Sep 2020 10:20:39 +0200 (CEST) Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by dpdk.org (Postfix) with ESMTP id 66F901D935 for ; Sun, 27 Sep 2020 10:20:38 +0200 (CEST) Received: from Internal Mail-Server by MTLPINE1 (envelope-from suanmingm@nvidia.com) with SMTP; 27 Sep 2020 11:20:33 +0300 Received: from nvidia.com (mtbc-r640-04.mtbc.labs.mlnx [10.75.70.9]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id 08R8KQ1R027083; Sun, 27 Sep 2020 11:20:31 +0300 From: Suanming Mou To: Dmitry Kozlyuk , Narcisa Ana Maria Vasile , Dmitry Malloy , Pallavi Kadam Cc: dev@dpdk.org Date: Sun, 27 Sep 2020 16:20:16 +0800 Message-Id: <1601194817-208834-2-git-send-email-suanmingm@nvidia.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1601194817-208834-1-git-send-email-suanmingm@nvidia.com> References: <1601194817-208834-1-git-send-email-suanmingm@nvidia.com> Subject: [dpdk-dev] [PATCH 1/2] eal/windows: add pthread mutex lock X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Add pthread mutex lock as it is needed for the thread safe rte flow functions. Signed-off-by: Suanming Mou --- 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