[v4,1/2] eal/windows: add pthread mutex lock

Message ID 1602206243-157603-2-git-send-email-suanmingm@nvidia.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series ethdev: make rte_flow API thread safe |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Suanming Mou Oct. 9, 2020, 1:17 a.m. UTC
  Add pthread mutex lock as it is needed for the thread safe rte_flow
functions.

Signed-off-by: Suanming Mou <suanmingm@nvidia.com>
Acked-by: Dmitry Kozlyuk <dmitry.kozliuk@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(+)
  

Comments

Tal Shnaiderman Oct. 9, 2020, 9:19 a.m. UTC | #1
> 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@nvidia.com>
> Acked-by: Dmitry Kozlyuk <dmitry.kozliuk@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@nvidia.com>
Acked-by: Tal Shnaiderman <talshn@nvidia.com>
  
Menon, Ranjit Oct. 14, 2020, 4:45 p.m. UTC | #2
On 10/8/2020 6:17 PM, Suanming Mou wrote:
> Add pthread mutex lock as it is needed for the thread safe rte_flow
> functions.
>
> Signed-off-by: Suanming Mou <suanmingm@nvidia.com>
> Acked-by: Dmitry Kozlyuk <dmitry.kozliuk@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

Acked-by: Ranjit Menon <ranjit.menon@intel.com>
  
Narcisa Ana Maria Vasile Oct. 15, 2020, 2:15 a.m. UTC | #3
On Fri, Oct 09, 2020 at 09:17:22AM +0800, Suanming Mou wrote:
> Add pthread mutex lock as it is needed for the thread safe rte_flow
> functions.
> 
> Signed-off-by: Suanming Mou <suanmingm@nvidia.com>
> Acked-by: Dmitry Kozlyuk <dmitry.kozliuk@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}
> +

Regarding the question on the static initializer, adding the guidance from DmitryM:
"If you choose to do the static initializer, you will be relying on implementation specifics,
(which may have not changed ever, or may not ever change, or may change in the next release).
This would be a hack (although potentially long term)."

Otherwise,
Acked-by: Narcisa Vasile <navasile@linux.microsoft.com>
  
Suanming Mou Oct. 15, 2020, 2:18 a.m. UTC | #4
> -----Original Message-----
> From: Narcisa Ana Maria Vasile <navasile@linux.microsoft.com>
> Sent: Thursday, October 15, 2020 10:16 AM
> To: Suanming Mou <suanmingm@nvidia.com>
> Cc: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>; Dmitry Malloy
> <dmitrym@microsoft.com>; Pallavi Kadam <pallavi.kadam@intel.com>;
> dev@dpdk.org
> Subject: Re: [PATCH v4 1/2] eal/windows: add pthread mutex lock
> 
> On Fri, Oct 09, 2020 at 09:17:22AM +0800, Suanming Mou wrote:
> > Add pthread mutex lock as it is needed for the thread safe rte_flow
> > functions.
> >
> > Signed-off-by: Suanming Mou <suanmingm@nvidia.com>
> > Acked-by: Dmitry Kozlyuk <dmitry.kozliuk@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}
> > +
> 
> Regarding the question on the static initializer, adding the guidance from
> DmitryM:
> "If you choose to do the static initializer, you will be relying on implementation
> specifics, (which may have not changed ever, or may not ever change, or may
> change in the next release).
> This would be a hack (although potentially long term)."

Yes, thanks. So we have removed that hack in the latest v5.
https://patches.dpdk.org/patch/80814/

> 
> Otherwise,
> Acked-by: Narcisa Vasile <navasile@linux.microsoft.com>
  

Patch

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