Skip to content

Commit 05613d2

Browse files
committedMay 20, 2015
Platform-specific gettid. Closes #3404, #3405.
1 parent a0f2fa5 commit 05613d2

File tree

4 files changed

+36
-6
lines changed

4 files changed

+36
-6
lines changed
 

Diff for: ‎configure

+4
Original file line numberDiff line numberDiff line change
@@ -1220,6 +1220,10 @@ int main() { return tgetnum(""); }
12201220
@defines << "HAVE_INOTIFY"
12211221
end
12221222

1223+
if has_function("gettid", ["unistd.d", "sys/types.h"])
1224+
@defines << "HAVE_GETTID"
1225+
end
1226+
12231227
# glibc has useless lchmod() so we don't try to use lchmod() on linux
12241228
if !@linux and has_function("lchmod", ["sys/stat.h", "unistd.h"])
12251229
@have_lchmod = true

Diff for: ‎vm/builtin/thread.cpp

+2-6
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include "metrics.hpp"
2121
#include "util/logger.hpp"
2222

23-
#include <sys/syscall.h>
23+
#include "missing/gettid.h"
2424

2525
/* HACK: returns a value that should identify a native thread
2626
* for debugging threading issues. The winpthreads library
@@ -291,11 +291,7 @@ namespace rubinius {
291291

292292
NativeMethod::init_thread(state);
293293

294-
#ifdef __APPLE__
295-
vm->thread->pid(state, Fixnum::from(syscall(SYS_thread_selfid)));
296-
#else
297-
vm->thread->pid(state, Fixnum::from(syscall(SYS_gettid)));
298-
#endif
294+
vm->thread->pid(state, Fixnum::from(gettid()));
299295

300296
// Lock the thread object and unlock it at __run__ in the ruby land.
301297
vm->thread->alive(state, cTrue);

Diff for: ‎vm/missing/gettid.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include "vm/missing/gettid.h"
2+
3+
#ifndef HAVE_GETTID
4+
#include <sys/syscall.h>
5+
6+
pid_t gettid(void) {
7+
#if defined(__APPLE__)
8+
return (pid_t)syscall(SYS_thread_selfid);
9+
#elif defined(__FreeBSD__)
10+
long tid;
11+
syscall(SYS_thr_self, &tid);
12+
return (pid_t)(tid);
13+
#elif defined(SYS_gettid)
14+
return (pid_t)syscall(SYS_gettid);
15+
#else
16+
return 0;
17+
#endif
18+
}
19+
#endif

Diff for: ‎vm/missing/gettid.h

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include "vm/config.h"
2+
3+
#include <unistd.h>
4+
5+
#ifdef HAVE_GETTID
6+
#include <sys/types.h>
7+
#else
8+
extern "C" {
9+
pid_t gettid(void);
10+
}
11+
#endif

0 commit comments

Comments
 (0)
Please sign in to comment.