Versioning for Thrift, remove thrift/lib/cpp/config.h
[folly.git] / folly / Synchronized.h
index 965372531db20caf7021934cfa7930c6429e36f0..0e69278958a13f8074cf0fb9ed5347695a59fd84 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.
@@ -27,8 +27,8 @@
 #include <type_traits>
 #include <mutex>
 #include <boost/thread.hpp>
-#include "folly/Preprocessor.h"
-#include "folly/Traits.h"
+#include <folly/Preprocessor.h>
+#include <folly/Traits.h>
 
 namespace folly {
 
@@ -49,7 +49,8 @@ struct HasLockUnlock {
   enum { value = IsOneOf<T,
          std::mutex, std::recursive_mutex,
          boost::mutex, boost::recursive_mutex, boost::shared_mutex
-#ifndef __APPLE__ // OSX doesn't have timed mutexes
+// OSX and Cygwin don't have timed mutexes
+#if !defined(__APPLE__) && !defined(__CYGWIN__)
         ,std::timed_mutex, std::recursive_timed_mutex,
          boost::timed_mutex, boost::recursive_timed_mutex
 #endif
@@ -97,7 +98,8 @@ acquireReadWrite(T& mutex) {
   mutex.lock();
 }
 
-#ifndef __APPLE__ // OSX doesn't have timed mutexes
+// OSX and Cygwin don't have timed mutexes
+#if !defined(__APPLE__) && !defined(__CYGWIN__)
 /**
  * Acquires a mutex for reading and writing with timeout by calling
  * .try_lock_for(). This applies to two of the std mutex classes as
@@ -315,7 +317,7 @@ struct Synchronized {
         return;
       }
       // Could not acquire the resource, pointer is null
-      parent_ = NULL;
+      parent_ = nullptr;
     }
 
     /**
@@ -363,7 +365,7 @@ struct Synchronized {
      * SYNCHRONIZED below.
      */
     T* operator->() {
-      return parent_ ? &parent_->datum_ : NULL;
+      return parent_ ? &parent_->datum_ : nullptr;
     }
 
     /**
@@ -427,13 +429,13 @@ struct Synchronized {
       acquire();
     }
     ConstLockedPtr(const Synchronized* parent, unsigned int milliseconds) {
-      if (parent->mutex_.timed_lock(
+      if (parent->mutex_.timed_lock_shared(
             boost::posix_time::milliseconds(milliseconds))) {
         parent_ = parent;
         return;
       }
       // Could not acquire the resource, pointer is null
-      parent_ = NULL;
+      parent_ = nullptr;
     }
 
     ConstLockedPtr& operator=(const ConstLockedPtr& rhs) {
@@ -449,7 +451,7 @@ struct Synchronized {
     }
 
     const T* operator->() const {
-      return parent_ ? &parent_->datum_ : NULL;
+      return parent_ ? &parent_->datum_ : nullptr;
     }
 
     struct Unsynchronizer {