PROFILE_MUTEX_START_LOCK();
struct timespec ts;
- Util::toTimespec(ts, milliseconds);
+ Util::toTimespec(ts, milliseconds + Util::currentTime());
int ret = pthread_mutex_timedlock(&pthread_mutex_, &ts);
if (ret == 0) {
PROFILE_MUTEX_LOCKED();
PROFILE_MUTEX_NOT_LOCKED();
return false;
#else
- (void)milliseconds;
- // If pthread_mutex_timedlock isn't supported, the safest thing to do
- // is just do a nonblocking trylock.
- return trylock();
+ /* Otherwise follow solution used by Mono for Android */
+ struct timespec sleepytime, now, to;
+
+ /* This is just to avoid a completely busy wait */
+ sleepytime.tv_sec = 0;
+ sleepytime.tv_nsec = 10000000L; /* 10ms */
+
+ Util::toTimespec(to, milliseconds + Util::currentTime());
+
+ while ((trylock()) == false) {
+ Util::toTimespec(now, Util::currentTime());
+ if (now.tv_sec >= to.tv_sec && now.tv_nsec >= to.tv_nsec) {
+ return false;
+ }
+ nanosleep(&sleepytime, NULL);
+ }
+
+ return true;
#endif
}
#include <sys/param.h>
#endif
-#ifndef __BYTE_ORDER
+#ifndef __THRIFT_BYTE_ORDER
# if defined(BYTE_ORDER) && defined(LITTLE_ENDIAN) && defined(BIG_ENDIAN)
-# define __BYTE_ORDER BYTE_ORDER
-# define __LITTLE_ENDIAN LITTLE_ENDIAN
-# define __BIG_ENDIAN BIG_ENDIAN
+# define __THRIFT_BYTE_ORDER BYTE_ORDER
+# define __THRIFT_LITTLE_ENDIAN LITTLE_ENDIAN
+# define __THRIFT_BIG_ENDIAN BIG_ENDIAN
# else
# include <boost/config.hpp>
# include <boost/detail/endian.hpp>
-# define __BYTE_ORDER BOOST_BYTE_ORDER
+# define __THRIFT_BYTE_ORDER BOOST_BYTE_ORDER
# ifdef BOOST_LITTLE_ENDIAN
-# define __LITTLE_ENDIAN __BYTE_ORDER
-# define __BIG_ENDIAN 0
+# define __THRIFT_LITTLE_ENDIAN __THRIFT_BYTE_ORDER
+# define __THRIFT_BIG_ENDIAN 0
# else
-# define __LITTLE_ENDIAN 0
-# define __BIG_ENDIAN __BYTE_ORDER
+# define __THRIFT_LITTLE_ENDIAN 0
+# define __THRIFT_BIG_ENDIAN __THRIFT_BYTE_ORDER
# endif
# endif
#endif
-#if __BYTE_ORDER == __BIG_ENDIAN
+#if __THRIFT_BYTE_ORDER == __THRIFT_BIG_ENDIAN
# define ntohll(n) (n)
# define htonll(n) (n)
# if defined(__GNUC__) && defined(__GLIBC__)
# define htolell(n) bswap_64(n)
# define letohll(n) bswap_64(n)
# endif /* GNUC & GLIBC */
-#elif __BYTE_ORDER == __LITTLE_ENDIAN
+#elif __THRIFT_BYTE_ORDER == __THRIFT_LITTLE_ENDIAN
# define htolell(n) (n)
# define letohll(n) (n)
# if defined(__GNUC__) && defined(__GLIBC__)
# define ntohll(n) ( (((uint64_t)ntohl(n)) << 32) + ntohl(n >> 32) )
# define htonll(n) ( (((uint64_t)htonl(n)) << 32) + htonl(n >> 32) )
# endif /* GNUC & GLIBC */
-#else /* __BYTE_ORDER */
+#else /* __THRIFT_BYTE_ORDER */
# error "Can't define htonll or ntohll!"
#endif