X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2FSynchronized.h;h=6984c30267a8fb518e9eab9ce72e206e6e60377a;hb=764261c12ab059cd15607a1c2d2a7ff015dfe7ce;hp=d632a772c5e8ba140f2341d78298eaf06c57ce5b;hpb=ca5621faf0871fa56f16754f03032cd03e03d4b1;p=folly.git diff --git a/folly/Synchronized.h b/folly/Synchronized.h index d632a772..6984c302 100644 --- a/folly/Synchronized.h +++ b/folly/Synchronized.h @@ -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 struct HasLockUnlock { enum { value = IsOneOf::value }; @@ -108,7 +108,12 @@ typename std::enable_if< IsOneOf::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))); } /**