Skip to contentSkip to conversation

Use pthread_self instead of thr_self on BSD

PATCH In review Bruce Cran 2 participants 6 messages Jul 30, 2011

lore
Share & tools
lore

Bruce Cran

author
#0 lore raw

PATCH 1/1 Use pthread_self instead of thr_self on BSD

The attached patch uses pthread_self to get the thread ID instead of the non-POSIX thr_self This fixes a compiler warning on FreeBSD.

Signature · 1 line
Bruce Cran
os/os-freebsd.h +2 -4
index fad051f..9da792e 100644
@@ -2,6 +2,7 @@
 #define FIO_OS_FREEBSD_H
 
 #include <errno.h>
+#include <pthread.h>
 #include <sys/sysctl.h>
 #include <sys/disk.h>
 
@@ -54,10 +55,7 @@ static inline unsigned long long os_phys_mem(void)
 
 static inline int gettid(void)
 {
-       long lwpid;
-
-       thr_self(&lwpid);
-       return (int) lwpid;
+       return (int) pthread_self();
 }
 
 #ifdef MADV_FREE
os/os-netbsd.h +2 -4
index 7f5f484..c4a923f 100644
@@ -2,6 +2,7 @@
 #define FIO_OS_NETBSD_H
 
 #include <errno.h>
+#include <pthread.h>
 #include <sys/param.h>
 /* XXX hack to avoid confilcts between rbtree.h and <sys/rb.h> */
 #define        rb_node _rb_node
@@ -48,10 +49,7 @@ static inline unsigned long long os_phys_mem(void)
 
 static inline int gettid(void)
 {
-       long lwpid;
-
-       thr_self(&lwpid);
-       return (int) lwpid;
+       return (int) pthread_self();
 }
 
 #ifdef MADV_FREE
#1 lore raw
Quoted 2 lines · Bruce Cran

The attached patch uses pthread_self to get the thread ID instead of the non-POSIX thr_self This fixes a compiler warning on FreeBSD.

Does pthread_self() return a thread ID in the PID name space, so to speak?

Signature · 1 line
Jens Axboe
author
#2 lore raw
Quoted 6 lines · Jens Axboe
Quoted 2 lines · Bruce Cran

The attached patch uses pthread_self to get the thread ID instead of the non-POSIX thr_self This fixes a compiler warning on FreeBSD.

Does pthread_self() return a thread ID in the PID name space, so to speak?

Hmm no, it doesn't seem to. In that case <sys/thr.h> should probably be included to get the definition of thr_self().

Signature · 1 line
Bruce Cran
#3 lore raw
Quoted 10 lines · Bruce Cran
Quoted 6 lines · Jens Axboe
Quoted 2 lines · Bruce Cran

The attached patch uses pthread_self to get the thread ID instead of the non-POSIX thr_self This fixes a compiler warning on FreeBSD.

Does pthread_self() return a thread ID in the PID name space, so to speak?

Hmm no, it doesn't seem to. In that case <sys/thr.h> should probably be included to get the definition of thr_self().

I suspected as much, most OS' will return a unique ID but not something you can otherwise use. How about the below?

os/os-freebsd.h +1 -0
index fad051f..317d403 100644
@@ -4,6 +4,7 @@
 #include <errno.h>
 #include <sys/sysctl.h>
 #include <sys/disk.h>
+#include <sys/thr.h>
 
 #include "../file.h"
 
os/os-netbsd.h +1 -0
index 7f5f484..e03866d 100644
@@ -3,6 +3,7 @@
 
 #include <errno.h>
 #include <sys/param.h>
+#include <sys/thr.h>
 /* XXX hack to avoid confilcts between rbtree.h and <sys/rb.h> */
 #define	rb_node	_rb_node
 #include <sys/sysctl.h>
Signature · 1 line
Jens Axboe
author
#4 lore raw
Quoted 1 line · Jens Axboe

I suspected as much, most OS' will return a unique ID but not something you can otherwise use. How about the below?

That should work.

Signature · 1 line
Bruce Cran
#5 lore raw
Quoted 5 lines · Bruce Cran
Quoted 2 lines · Jens Axboe

I suspected as much, most OS' will return a unique ID but not something you can otherwise use. How about the below?

That should work.

Great, pushing that out, too.

Signature · 1 line
Jens Axboe