gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [libmicrohttpd] 01/05: mhd_threads: Fixed thread ID data ra


From: gnunet
Subject: [GNUnet-SVN] [libmicrohttpd] 01/05: mhd_threads: Fixed thread ID data races on pthreads
Date: Wed, 22 Nov 2017 12:46:35 +0100

This is an automated email from the git hooks/post-receive script.

karlson2k pushed a commit to branch master
in repository libmicrohttpd.

commit 11e15b46f05352932e2682d7664648f717aa979a
Author: Evgeny Grin (Karlson2k) <address@hidden>
AuthorDate: Tue Nov 21 23:10:18 2017 +0300

    mhd_threads: Fixed thread ID data races on pthreads
---
 src/microhttpd/mhd_threads.h | 32 ++++++++++++++++++++++++++++----
 1 file changed, 28 insertions(+), 4 deletions(-)

diff --git a/src/microhttpd/mhd_threads.h b/src/microhttpd/mhd_threads.h
index 1a06c64a..3778ad09 100644
--- a/src/microhttpd/mhd_threads.h
+++ b/src/microhttpd/mhd_threads.h
@@ -91,18 +91,34 @@
   typedef DWORD MHD_thread_ID_;
 #endif
 
+/* Depending on implementation, pthread_create() MAY set thread ID into
+ * provided pointer and after it start thread OR start thread and after
+ * if set thread ID. In latter case, to avoid data races, additional
+ * pthread_self() call is required in thread routine. Is some platform
+ * is known for setting thread ID BEFORE starting thread macro
+ * MHD_PTHREAD_CREATE__SET_ID_BEFORE_START_THREAD could be defined
+ * to save some resources. */
 #if defined(MHD_USE_POSIX_THREADS)
+#  ifdef MHD_PTHREAD_CREATE__SET_ID_BEFORE_START_THREAD
   union _MHD_thread_handle_ID_
   {
-    MHD_thread_handle_  handle;
-    MHD_thread_ID_      ID;
+    MHD_thread_handle_  handle; /**< To be used in other threads */
+    MHD_thread_ID_      ID;     /**< To be used in thread itself */
   };
   typedef union _MHD_thread_handle_ID_ MHD_thread_handle_ID_;
+#  else  /* ! MHD_PTHREAD_CREATE__SET_ID_BEFORE_START_THREAD */
+  struct _MHD_thread_handle_ID_
+  {
+    MHD_thread_handle_  handle; /**< To be used in other threads */
+    MHD_thread_ID_      ID;     /**< To be used in thread itself */
+  };
+  typedef struct _MHD_thread_handle_ID_ MHD_thread_handle_ID_;
+#  endif /* ! MHD_PTHREAD_CREATE__SET_ID_BEFORE_START_THREAD */
 #elif defined(MHD_USE_W32_THREADS)
   struct _MHD_thread_handle_ID_
   {
-    MHD_thread_handle_  handle;
-    MHD_thread_ID_      ID;
+    MHD_thread_handle_  handle; /**< To be used in other threads */
+    MHD_thread_ID_      ID;     /**< To be used in thread itself */
   };
   typedef struct _MHD_thread_handle_ID_ MHD_thread_handle_ID_;
 #endif
@@ -140,11 +156,19 @@
 #endif
 
 #if defined(MHD_USE_POSIX_THREADS)
+#  ifdef MHD_PTHREAD_CREATE__SET_ID_BEFORE_START_THREAD
 /**
  * Initialise thread ID.
  * @param thread_handle_ID_ptr pointer to thread handle-ID
  */
 #define MHD_thread_init_(thread_handle_ID_ptr) (void)0
+#  else  /* ! MHD_PTHREAD_CREATE__SET_ID_BEFORE_START_THREAD */
+/**
+ * Initialise thread ID.
+ * @param thread_handle_ID_ptr pointer to thread handle-ID
+ */
+#define MHD_thread_init_(thread_handle_ID_ptr) 
((thread_handle_ID_ptr)->ID=pthread_self())
+#  endif /* ! MHD_PTHREAD_CREATE__SET_ID_BEFORE_START_THREAD */
 #elif defined(MHD_USE_W32_THREADS)
 /**
  * Initialise thread ID.

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]