folly::Init, RAII variant of folly::init
[folly.git] / folly / executors / IOThreadPoolExecutor.cpp
index 1cf9bc5e336d24fbc530df8b68d2eb9366dd1ec8..63601fdc9b2c0e37c91ce2e7da894e761100fd8a 100644 (file)
@@ -47,9 +47,9 @@ class MemoryIdlerTimeout : public AsyncTimeout, public EventBase::LoopCallback {
 
       idleTimeout = MemoryIdler::getVariationTimeout(idleTimeout);
 
-      scheduleTimeout(
+      scheduleTimeout(static_cast<uint32_t>(
           std::chrono::duration_cast<std::chrono::milliseconds>(idleTimeout)
-              .count());
+              .count()));
     }
 
     // reschedule this callback for the next event loop.
@@ -119,11 +119,12 @@ IOThreadPoolExecutor::pickThread() {
   if (n == 0) {
     return me;
   }
-  auto thread = ths[nextThread_++ % n];
+  auto thread = ths[nextThread_.fetch_add(1, std::memory_order_relaxed) % n];
   return std::static_pointer_cast<IOThread>(thread);
 }
 
 EventBase* IOThreadPoolExecutor::getEventBase() {
+  RWSpinLock::ReadHolder r{&threadListLock_};
   return pickThread()->eventBase;
 }