memrchr and *timed_mutex are platform-specific
authorSean Cannella <seanc@fb.com>
Wed, 3 Jul 2013 20:36:28 +0000 (13:36 -0700)
committerSara Golemon <sgolemon@fb.com>
Tue, 9 Jul 2013 19:05:34 +0000 (12:05 -0700)
Summary:
- conditionally compile rfind overrides
- conditionally add support for timed_mutex/recursive_timed_mutex

Test Plan:
- compiled on OSX
- unit tests

Reviewed By: andrei.alexandrescu@fb.com

FB internal diff: D872272

folly/Range.h
folly/Synchronized.h

index 2c26db07537da0ee1c52a7d4286c9bcec2bce997..85a554c5919d9289555e7df437de2c80c869683a 100644 (file)
@@ -705,12 +705,14 @@ inline size_t qfind(const Range<const char*>& haystack, const char& needle) {
   return pos == nullptr ? std::string::npos : pos - haystack.data();
 }
 
+#ifdef _GNU_SOURCE // memrchr is a GNU extension
 template <>
 inline size_t rfind(const Range<const char*>& haystack, const char& needle) {
   auto pos = static_cast<const char*>(
     ::memrchr(haystack.data(), needle, haystack.size()));
   return pos == nullptr ? std::string::npos : pos - haystack.data();
 }
+#endif
 
 // specialization for ByteRange
 template <>
@@ -721,6 +723,7 @@ inline size_t qfind(const Range<const unsigned char*>& haystack,
   return pos == nullptr ? std::string::npos : pos - haystack.data();
 }
 
+#ifdef _GNU_SOURCE // memrchr is a GNU extension
 template <>
 inline size_t rfind(const Range<const unsigned char*>& haystack,
                     const unsigned char& needle) {
@@ -728,6 +731,7 @@ inline size_t rfind(const Range<const unsigned char*>& haystack,
     ::memrchr(haystack.data(), needle, haystack.size()));
   return pos == nullptr ? std::string::npos : pos - haystack.data();
 }
+#endif
 
 template <class T>
 size_t qfind_first_of(const Range<T>& haystack,
index ea1cb84d08be0113c2653a3e3404827af61277a5..cc43071aa865deeb0ffec1b75fe95621d572c59f 100644 (file)
@@ -48,9 +48,11 @@ template <class T>
 struct HasLockUnlock {
   enum { value = IsOneOf<T,
          std::mutex, std::recursive_mutex,
-         std::timed_mutex, std::recursive_timed_mutex,
          boost::mutex, boost::recursive_mutex, boost::shared_mutex,
+#ifndef __APPLE__ // OSX doesn't have timed mutexes
+         std::timed_mutex, std::recursive_timed_mutex,
          boost::timed_mutex, boost::recursive_timed_mutex
+#endif
          >::value };
 };
 
@@ -95,6 +97,7 @@ acquireReadWrite(T& mutex) {
   mutex.lock();
 }
 
+#ifndef __APPLE__ // OSX doesn't have timed mutexes
 /**
  * Acquires a mutex for reading and writing with timeout by calling
  * .try_lock_for(). This applies to two of the std mutex classes as
@@ -121,6 +124,7 @@ acquireReadWrite(T& mutex,
                  unsigned int milliseconds) {
   return mutex.timed_lock(boost::posix_time::milliseconds(milliseconds));
 }
+#endif // __APPLE__
 
 /**
  * Releases a mutex previously acquired for reading by calling