From: Michael Lee Date: Mon, 4 Jan 2016 23:35:02 +0000 (-0800) Subject: Switch back to SYS_gettid, and fix X-Git-Tag: deprecate-dynamic-initializer~169 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=3f93d7830a8cf7a3edfe13f87812b2d41825f70b;p=folly.git Switch back to SYS_gettid, and fix Summary: SYS_gettid is different on Linux vs. OSX. `__NR_gettid` is only sometimes present and `SYS_gettid` is only sometimes present, but we can pick one name and just follow that one. Reviewed By: dcolascione Differential Revision: D2800515 fb-gh-sync-id: 4245de4b9184ac4233ade9da297409c1031869a3 --- diff --git a/folly/Makefile.am b/folly/Makefile.am index 92967640..d6a46bb8 100644 --- a/folly/Makefile.am +++ b/folly/Makefile.am @@ -247,6 +247,7 @@ nobase_follyinclude_HEADERS = \ Padded.h \ PicoSpinLock.h \ Portability.h \ + portability/Syscall.h \ Preprocessor.h \ ProducerConsumerQueue.h \ Random.h \ diff --git a/folly/experimental/fibers/Fiber.cpp b/folly/experimental/fibers/Fiber.cpp index 9721e903..d5a8b1e9 100644 --- a/folly/experimental/fibers/Fiber.cpp +++ b/folly/experimental/fibers/Fiber.cpp @@ -27,6 +27,7 @@ #include #include #include +#include namespace folly { namespace fibers { @@ -38,7 +39,7 @@ pid_t localThreadId() { // OSX doesn't support thread_local. static FOLLY_TLS pid_t threadId = 0; if (UNLIKELY(threadId == 0)) { - threadId = syscall(__NR_gettid); + threadId = syscall(FOLLY_SYS_gettid); } return threadId; } diff --git a/folly/portability/Syscall.h b/folly/portability/Syscall.h new file mode 100644 index 00000000..05fae6e1 --- /dev/null +++ b/folly/portability/Syscall.h @@ -0,0 +1,30 @@ +/* + * Copyright 2016 Facebook, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FOLLY_SYSCALL_H_ +#define FOLLY_SYSCALL_H_ + +#include + +#if defined(__APPLE__) +#define FOLLY_SYS_gettid SYS_thread_selfid +#elif defined(SYS_gettid) +#define FOLLY_SYS_gettid SYS_gettid +#else +#define FOLLY_SYS_gettid __NR_gettid +#endif + +#endif