You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@qpid.apache.org by GitBox <gi...@apache.org> on 2020/06/11 18:36:54 UTC

[GitHub] [qpid-dispatch] kgiusti commented on a change in pull request #760: DISPATCH-1679: Add sys_thread_self()

kgiusti commented on a change in pull request #760:
URL: https://github.com/apache/qpid-dispatch/pull/760#discussion_r438992885



##########
File path: src/posix/threading.c
##########
@@ -150,19 +150,38 @@ void sys_rwlock_unlock(sys_rwlock_t *lock)
 
 struct sys_thread_t {
     pthread_t thread;
+    void *(*f)(void *);
+    void *arg;
 };
 
+static __thread sys_thread_t *_self;
+
+
+// bootstrap _self before calling main thread function
+//
+static void *_thread_init(void *arg)
+{
+    _self = (sys_thread_t *)arg;
+    return _self->f(_self->arg);
+}
+
+
 sys_thread_t *sys_thread(void *(*run_function) (void *), void *arg)
 {
     sys_thread_t *thread = NEW(sys_thread_t);
-    pthread_create(&(thread->thread), 0, run_function, arg);
+    thread->f = run_function;
+    thread->arg = arg;
+    pthread_create(&(thread->thread), 0, _thread_init, (void *)thread);
     return thread;
 }
 
-long sys_thread_id(sys_thread_t *thread) {
-    return (long) thread->thread;
+

Review comment:
       Yes and Yes!
   There were no calls to sys_thread_id() in the code... so zero risk in removing it.
   Each thread is allocated a unique sys_thread_t pointer that exists in shared memory so every thread's pointer will be globally unique.  One of the new unit tests verifies that is the case.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@qpid.apache.org
For additional commands, e-mail: dev-help@qpid.apache.org