From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 12999A034F; Tue, 30 Mar 2021 00:41:38 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6508A140EA7; Tue, 30 Mar 2021 00:40:57 +0200 (CEST) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id B30E1140E4A for ; Tue, 30 Mar 2021 00:40:45 +0200 (CEST) Received: by linux.microsoft.com (Postfix, from userid 1059) id 3718820B5687; Mon, 29 Mar 2021 15:40:43 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 3718820B5687 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1617057644; bh=eCJF6TDVx4gpse2x4gbPOl/L/9urrfR1M9mOpcIqnoM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ls4KALU3W6bRGcf2IU3E4H4f4Rhb0bFledrEXk1PWPzssf5nOiBlSkLYq6R7qYDz2 F8XxwqZ+4/8vgQssXULK/uzz7I5QQylpFo4JaqMjWM/LOSiJSUYOggBELBTBoGBk7E BvdBIIuDZ7KGB6gbBLxTnuayiu1c9OBZwaccT3vg= From: Narcisa Ana Maria Vasile To: dev@dpdk.org, thomas@monjalon.net, dmitry.kozliuk@gmail.com, khot@microsoft.com, navasile@microsoft.com, dmitrym@microsoft.com, roretzla@microsoft.com, talshn@nvidia.com, ocardona@microsoft.com Cc: bruce.richardson@intel.com, david.marchand@redhat.com, pallavi.kadam@intel.com Date: Mon, 29 Mar 2021 15:40:37 -0700 Message-Id: <1617057640-24301-8-git-send-email-navasile@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1617057640-24301-1-git-send-email-navasile@linux.microsoft.com> References: <1616802771-31578-10-git-send-email-navasile@linux.microsoft.com> <1617057640-24301-1-git-send-email-navasile@linux.microsoft.com> Subject: [dpdk-dev] [PATCH v5 07/10] eal: implement functions for mutex management X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 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" From: Narcisa Vasile Add functions for mutex init, destroy, lock, unlock. Signed-off-by: Narcisa Vasile --- lib/librte_eal/common/rte_thread.c | 24 +++++++++ lib/librte_eal/include/rte_thread.h | 53 +++++++++++++++++++ lib/librte_eal/include/rte_thread_types.h | 3 ++ .../include/rte_windows_thread_types.h | 1 + lib/librte_eal/windows/rte_thread.c | 28 ++++++++++ 5 files changed, 109 insertions(+) diff --git a/lib/librte_eal/common/rte_thread.c b/lib/librte_eal/common/rte_thread.c index 29d38d193..8e963ed65 100644 --- a/lib/librte_eal/common/rte_thread.c +++ b/lib/librte_eal/common/rte_thread.c @@ -220,6 +220,30 @@ rte_thread_join(rte_thread_t thread_id, int *value_ptr) return 0; } +int +rte_thread_mutex_init(rte_thread_mutex_t *mutex) +{ + return pthread_mutex_init(mutex, NULL); +} + +int +rte_thread_mutex_lock(rte_thread_mutex_t *mutex) +{ + return pthread_mutex_lock(mutex); +} + +int +rte_thread_mutex_unlock(rte_thread_mutex_t *mutex) +{ + return pthread_mutex_unlock(mutex); +} + +int +rte_thread_mutex_destroy(rte_thread_mutex_t *mutex) +{ + return pthread_mutex_destroy(mutex); +} + 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 24dc186f1..2b8d81005 100644 --- a/lib/librte_eal/include/rte_thread.h +++ b/lib/librte_eal/include/rte_thread.h @@ -240,6 +240,58 @@ int rte_thread_create(rte_thread_t *thread_id, __rte_experimental int rte_thread_join(rte_thread_t thread_id, int *value_ptr); +/** + * Initializes a mutex. + * + * @param mutex + * The mutex to be initialized. + * + * @return + * On success, return 0. + * On failure, return a positive errno-style error number. + */ +__rte_experimental +int rte_thread_mutex_init(rte_thread_mutex_t *mutex); + +/** + * Locks a mutex. + * + * @param mutex + * The mutex to be locked. + * + * @return + * On success, return 0. + * On failure, return a positive errno-style error number. + */ +__rte_experimental +int rte_thread_mutex_lock(rte_thread_mutex_t *mutex); + +/** + * Unlocks a mutex. + * + * @param mutex + * The mutex to be unlocked. + * + * @return + * On success, return 0. + * On failure, return a positive errno-style error number. + */ +__rte_experimental +int rte_thread_mutex_unlock(rte_thread_mutex_t *mutex); + +/** + * Releases all resources associated with a mutex. + * + * @param mutex + * The mutex to be uninitialized. + * + * @return + * On success, return 0. + * On failure, return a positive errno-style error number. + */ +__rte_experimental +int rte_thread_mutex_destroy(rte_thread_mutex_t *mutex); + /** * Terminates a thread. * @@ -259,6 +311,7 @@ int rte_thread_cancel(rte_thread_t thread_id); * * @param cpusetp * Pointer to CPU affinity to set. + * * @return * On success, return 0; otherwise return -1; */ diff --git a/lib/librte_eal/include/rte_thread_types.h b/lib/librte_eal/include/rte_thread_types.h index a884daf17..37bc7af2b 100644 --- a/lib/librte_eal/include/rte_thread_types.h +++ b/lib/librte_eal/include/rte_thread_types.h @@ -7,9 +7,12 @@ #include +#define RTE_THREAD_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER + #define EAL_THREAD_PRIORITY_NORMAL 0 #define EAL_THREAD_PRIORITY_REALTIME_CIRTICAL 99 typedef pthread_t rte_thread_t; +typedef pthread_mutex_t rte_thread_mutex_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 8cb4b3856..47c6b2664 100644 --- a/lib/librte_eal/windows/include/rte_windows_thread_types.h +++ b/lib/librte_eal/windows/include/rte_windows_thread_types.h @@ -11,5 +11,6 @@ #define EAL_THREAD_PRIORITY_REALTIME_CIRTICAL THREAD_PRIORITY_TIME_CRITICAL typedef DWORD rte_thread_t; +typedef CRITICAL_SECTION rte_thread_mutex_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 85b11c5f5..a26b8c08f 100644 --- a/lib/librte_eal/windows/rte_thread.c +++ b/lib/librte_eal/windows/rte_thread.c @@ -417,6 +417,34 @@ rte_thread_join(rte_thread_t thread_id, int *value_ptr) return ret; } +int +rte_thread_mutex_init(rte_thread_mutex_t *mutex) +{ + InitializeCriticalSection(mutex); + return 0; +} + +int +rte_thread_mutex_lock(rte_thread_mutex_t *mutex) +{ + EnterCriticalSection(mutex); + return 0; +} + +int +rte_thread_mutex_unlock(rte_thread_mutex_t *mutex) +{ + LeaveCriticalSection(mutex); + return 0; +} + +int +rte_thread_mutex_destroy(rte_thread_mutex_t *mutex) +{ + DeleteCriticalSection(mutex); + return 0; +} + int rte_thread_cancel(rte_thread_t thread_id) { -- 2.30.0.vfs.0.2