Replace thread_local with FOLLY_TLS
authorHans Fugal <fugalh@fb.com>
Thu, 11 Jun 2015 20:53:21 +0000 (13:53 -0700)
committerSara Golemon <sgolemon@fb.com>
Thu, 11 Jun 2015 21:50:32 +0000 (14:50 -0700)
commit36ca845043259977fac1e8cddec7427d711e1126
treed0047ba3b0098c16b453ccd3b3e76ae7475001b9
parentbb400ba01a116628a230cabbc1c472d0c7c06905
Replace thread_local with FOLLY_TLS

Summary: OSX doesn't support C++11's `thread_local`. :-/ (yet? http://stackoverflow.com/questions/28094794/why-does-apple-clang-disallow-c11-thread-local-when-official-clang-supports/29929949#29929949)
We have `FOLLY_TLS` in `Portability.h` https://github.com/facebook/folly/blob/master/folly/Portability.h#L163-L175

So replace the usages of `thread_local` with `FOLLY_TLS`. But `__thread` is not drop-in compatible with `thread_local`, specifically the former requires global storage and needs a constexpr initializer, and a trivial destructor.

`futures/QueuedImmediateExecutor` now uses `folly::ThreadLocal` (because `std::queue` has a non-trivial destructor). It might end up in one more alloc, per thread. I also rearranged the code to clarify the fact that although there may be many `QueuedImmediateExecutor`s, they all share the same queue per thread.

I didn't use `folly::ThreadLocal` for fibers, because I thought it might be too expensive. But now I'm not so sure. I had to do the "check for default and then initialize" thing because of the requirement for constexpr initialization for `__thread` (and therefore `FOLLY_TLS`).

Reviewed By: @jsedgwick

Differential Revision: D2140369
folly/experimental/fibers/Fiber.cpp
folly/experimental/fibers/FiberManager-inl.h
folly/futures/QueuedImmediateExecutor.cpp
folly/futures/QueuedImmediateExecutor.h