Commit b1463f8f authored by Sean Cannella's avatar Sean Cannella Committed by Sara Golemon

memrchr and *timed_mutex are platform-specific

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
parent bd4c2f96
......@@ -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,
......
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment