Remove disallowed &* of FwdIterator
[folly.git] / folly / Synchronized.h
index d632a772c5e8ba140f2341d78298eaf06c57ce5b..6984c30267a8fb518e9eab9ce72e206e6e60377a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2013 Facebook, Inc.
+ * Copyright 2014 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -48,9 +48,9 @@ template <class T>
 struct HasLockUnlock {
   enum { value = IsOneOf<T,
          std::mutex, std::recursive_mutex,
-         boost::mutex, boost::recursive_mutex, boost::shared_mutex,
+         boost::mutex, boost::recursive_mutex, boost::shared_mutex
 #ifndef __APPLE__ // OSX doesn't have timed mutexes
-         std::timed_mutex, std::recursive_timed_mutex,
+        ,std::timed_mutex, std::recursive_timed_mutex,
          boost::timed_mutex, boost::recursive_timed_mutex
 #endif
          >::value };
@@ -108,7 +108,12 @@ typename std::enable_if<
   IsOneOf<T, std::timed_mutex, std::recursive_timed_mutex>::value, bool>::type
 acquireReadWrite(T& mutex,
                  unsigned int milliseconds) {
-  return mutex.try_lock_for(std::chrono::milliseconds(milliseconds));
+  // work around try_lock_for bug in some gcc versions, see
+  // http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54562
+  return mutex.try_lock()
+      || (milliseconds > 0 &&
+          mutex.try_lock_until(std::chrono::system_clock::now() +
+                               std::chrono::milliseconds(milliseconds)));
 }
 
 /**