* [dpdk-dev] [PATCH] eal/windows: add pthread TLS function support
@ 2020-12-13 20:00 Tal Shnaiderman
0 siblings, 0 replies; only message in thread
From: Tal Shnaiderman @ 2020-12-13 20:00 UTC (permalink / raw)
To: dev; +Cc: thomas, pallavi.kadam, dmitry.kozliuk, navasile, dmitrym
Add the following functions to the pthread shim implementation
for Windows as they are needed for thread safe rte_flow functions.
pthread_key_create.
pthread_key_delete.
pthread_getspecific.
pthread_setspecific.
Signed-off-by: Tal Shnaiderman <talshn@nvidia.com>
---
lib/librte_eal/windows/include/pthread.h | 42 ++++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)
diff --git a/lib/librte_eal/windows/include/pthread.h b/lib/librte_eal/windows/include/pthread.h
index fb11a07ce6..e0c08fe5d6 100644
--- a/lib/librte_eal/windows/include/pthread.h
+++ b/lib/librte_eal/windows/include/pthread.h
@@ -34,6 +34,8 @@ typedef CRITICAL_SECTION pthread_mutex_t;
typedef SYNCHRONIZATION_BARRIER pthread_barrier_t;
+typedef DWORD pthread_key_t;
+
#define pthread_barrier_init(barrier, attr, count) \
InitializeSynchronizationBarrier(barrier, count, -1)
#define pthread_barrier_wait(barrier) EnterSynchronizationBarrier(barrier, \
@@ -179,6 +181,46 @@ pthread_mutex_destroy(pthread_mutex_t *mutex)
return 0;
}
+static inline int
+pthread_key_create(pthread_key_t *key,
+ __rte_unused void (*destructor)(void*))
+{
+ if (((*key) = TlsAlloc()) == TLS_OUT_OF_INDEXES) {
+ RTE_LOG_WIN32_ERR("TlsAlloc()");
+ return ENOMEM;
+ }
+ return 0;
+}
+
+static inline int
+pthread_key_delete(pthread_key_t key)
+{
+ if (!TlsFree(key)) {
+ RTE_LOG_WIN32_ERR("TlsFree()");
+ return -1;
+ }
+ return 0;
+}
+
+static inline void *
+pthread_getspecific(pthread_key_t key)
+{
+ return TlsGetValue(key);
+}
+
+static inline int
+pthread_setspecific(pthread_key_t key, const void *value)
+{
+ /* discard const qualifier */
+ char *p = (char *) (uintptr_t) value;
+
+ if (!TlsSetValue(key, p)) {
+ RTE_LOG_WIN32_ERR("TlsSetValue()");
+ return -1;
+ }
+ return 0;
+}
+
#ifdef __cplusplus
}
#endif
--
2.16.1.windows.4
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-12-13 20:02 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-13 20:00 [dpdk-dev] [PATCH] eal/windows: add pthread TLS function support Tal Shnaiderman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).