提交 1d4bc478 编写于 作者: L liaogang

support gettid() on MAC OS X

上级 5bca34ed
......@@ -209,7 +209,18 @@ __thread cudaStream_t default_stream = 0;
__thread bool g_sync_flag = true;
bool hl_start_flag = false;
#define gettid() syscall(SYS_gettid)
inline pid_t gettid() {
#if defined(__APPLE__) || defined(__OSX__)
pid_t tid = syscall(SYS_thread_selfid);
#else
#ifndef __NR_gettid
#define __NR_gettid 224
#endif
pid_t tid = syscall(__NR_gettid);
#endif
CHECK_NE(tid, -1);
return tid;
}
void hl_init(int device) {
CHECK(hl_start_flag)
......
......@@ -18,7 +18,18 @@ limitations under the License. */
#include <sys/syscall.h>
#include <unistd.h>
inline pid_t gettid() { return syscall(SYS_gettid); }
inline pid_t gettid() {
#if defined(__APPLE__) || defined(__OSX__)
pid_t tid = syscall(SYS_thread_selfid);
#else
#ifndef __NR_gettid
#define __NR_gettid 224
#endif
pid_t tid = syscall(__NR_gettid);
#endif
CHECK_NE(tid, -1);
return tid;
}
#include "Queue.h"
#include "ThreadLocal.h"
......
......@@ -156,7 +156,15 @@ private:
static void dataDestructor(void* p) { delete (T*)p; }
void updateMap(T* p) {
pid_t tid = syscall(SYS_gettid);
#if defined(__APPLE__) || defined(__OSX__)
pid_t tid = syscall(SYS_thread_selfid);
#else
#ifndef __NR_gettid
#define __NR_gettid 224
#endif
pid_t tid = syscall(__NR_gettid);
#endif
CHECK_NE(tid, -1);
std::lock_guard<std::mutex> guard(mutex_);
auto ret = threadMap_.insert(std::make_pair(tid, p));
if (!ret.second) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册