From patchwork Thu Oct 15 01:07:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suanming Mou X-Patchwork-Id: 80814 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id AB13DA04DB; Thu, 15 Oct 2020 03:08:20 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id BB0871DB6D; Thu, 15 Oct 2020 03:08:01 +0200 (CEST) Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by dpdk.org (Postfix) with ESMTP id 097C11DB6C for ; Thu, 15 Oct 2020 03:07:59 +0200 (CEST) Received: from Internal Mail-Server by MTLPINE1 (envelope-from suanmingm@nvidia.com) with SMTP; 15 Oct 2020 04:07:55 +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 09F17qNs027350; Thu, 15 Oct 2020 04:07:53 +0300 From: Suanming Mou To: Dmitry Kozlyuk , Narcisa Ana Maria Vasile , Dmitry Malloy , Pallavi Kadam Cc: dev@dpdk.org, thomas@monjalon.net Date: Thu, 15 Oct 2020 09:07:46 +0800 Message-Id: <1602724067-390536-2-git-send-email-suanmingm@nvidia.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1602724067-390536-1-git-send-email-suanmingm@nvidia.com> References: <1601194817-208834-1-git-send-email-suanmingm@nvidia.com> <1602724067-390536-1-git-send-email-suanmingm@nvidia.com> Subject: [dpdk-dev] [PATCH v5 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 Tested-by: Tal Shnaiderman Acked-by: Dmitry Kozlyuk Acked-by: Ranjit Menon Acked-by: Narcisa Vasile --- v5: - Remove PTHREAD_MUTEX_INITIALIZER macro added in v4. v4: - Add PTHREAD_MUTEX_INITIALIZER macro. v3: - No updates. v2: - Using critical section for windows pthread mutex. --- lib/librte_eal/windows/include/pthread.h | 33 ++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/lib/librte_eal/windows/include/pthread.h b/lib/librte_eal/windows/include/pthread.h index 99013dc..644fd49 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 CRITICAL_SECTION pthread_mutex_t; + typedef SYNCHRONIZATION_BARRIER pthread_barrier_t; #define pthread_barrier_init(barrier, attr, count) \ @@ -139,6 +143,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