Switch uses of <unistd.h> to <folly/portability/Unistd.h>
[folly.git] / folly / experimental / EventCount.h
index 5a11a3300666df805b7633777a15e6426c01cfac..a9feddfd83f8228320be48c305d596957e9d62fc 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2013 Facebook, Inc.
+ * Copyright 2016 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * limitations under the License.
  */
 
-#ifndef FOLLY_EXPERIMENTAL_EVENTCOUNT_H_
-#define FOLLY_EXPERIMENTAL_EVENTCOUNT_H_
+#pragma once
 
-#include <unistd.h>
 #include <syscall.h>
 #include <linux/futex.h>
-#include <sys/time.h>
-#include <cassert>
 #include <climits>
 #include <atomic>
 #include <thread>
+#include <glog/logging.h>
 
-#include "folly/Bits.h"
-#include "folly/Likely.h"
+#include <folly/Bits.h>
+#include <folly/Likely.h>
+#include <folly/portability/SysTime.h>
+#include <folly/portability/Unistd.h>
 
 
 namespace folly {
@@ -127,13 +126,7 @@ class EventCount {
   static_assert(sizeof(uint32_t) == 4, "bad platform");
   static_assert(sizeof(uint64_t) == 8, "bad platform");
 
-#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
-  static constexpr size_t kEpochOffset = 1;
-#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
-  static constexpr size_t kEpochOffset = 0;  // in units of sizeof(int)
-#else
-# error Your machine uses a weird endianness!
-#endif
+  static constexpr size_t kEpochOffset = kIsLittleEndian ? 1 : 0;
 
   // val_ stores the epoch in the most significant 32 bits and the
   // waiter count in the least significant 32 bits.
@@ -172,7 +165,7 @@ inline void EventCount::cancelWait() noexcept {
   // #waiters gets to 0, the less likely it is that we'll do spurious wakeups
   // (and thus system calls).
   uint64_t prev = val_.fetch_add(kSubWaiter, std::memory_order_seq_cst);
-  assert((prev & kWaiterMask) != 0);
+  DCHECK_NE((prev & kWaiterMask), 0);
 }
 
 inline void EventCount::wait(Key key) noexcept {
@@ -184,7 +177,7 @@ inline void EventCount::wait(Key key) noexcept {
   // #waiters gets to 0, the less likely it is that we'll do spurious wakeups
   // (and thus system calls)
   uint64_t prev = val_.fetch_add(kSubWaiter, std::memory_order_seq_cst);
-  assert((prev & kWaiterMask) != 0);
+  DCHECK_NE((prev & kWaiterMask), 0);
 }
 
 template <class Condition>
@@ -210,6 +203,3 @@ void EventCount::await(Condition condition) {
 }
 
 }  // namespace folly
-
-#endif /* FOLLY_EXPERIMENTAL_EVENTCOUNT_H_ */
-