Fix the linking of various tests against GMock
[folly.git] / folly / PackedSyncPtr.h
index 6e8cca53dcd8a06c61b02b8b56d9185af5471620..64337674f5f3a53b1dca735f94db26684aaecf34 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2012 Facebook, Inc.
+ * Copyright 2017 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_PACKEDSYNCPTR_H_
-#define FOLLY_PACKEDSYNCPTR_H_
+#pragma once
 
-#ifndef __x86_64__
-# error "PackedSyncPtr is x64-specific code."
+#include <folly/Portability.h>
+
+#if !FOLLY_X64 && !FOLLY_PPC64
+# error "PackedSyncPtr is x64 and ppc64 specific code."
 #endif
 
 /*
@@ -51,7 +52,7 @@
  * @author Jordan DeLong <delong.j@fb.com>
  */
 
-#include "folly/SmallLocks.h"
+#include <folly/SmallLocks.h>
 #include <type_traits>
 #include <glog/logging.h>
 
@@ -105,7 +106,7 @@ public:
   reference operator*() const { return *get(); }
   reference operator[](std::ptrdiff_t i) const { return get()[i]; }
 
-  // Syncronization (logically const, even though this mutates our
+  // Synchronization (logically const, even though this mutates our
   // locked state: you can lock a const PackedSyncPtr<T> to read it).
   void lock() const { data_.lock(); }
   void unlock() const { data_.unlock(); }
@@ -132,19 +133,20 @@ public:
     data_.setData((uintptr_t(extra) << 48) | ptr);
   }
 
-  // Logically private, but we can't have private data members and
-  // still be considered a POD.  (In C++11 we are still a standard
-  // layout struct if this is private, but it doesn't matter, since
-  // gcc (4.6) won't let us use this with attribute packed still in
-  // that case.)
+ private:
   PicoSpinLock<uintptr_t> data_;
-};
+} FOLLY_PACK_ATTR;
 
+static_assert(
+    std::is_pod<PackedSyncPtr<void>>::value,
+    "PackedSyncPtr must be kept a POD type.");
 static_assert(sizeof(PackedSyncPtr<void>) == 8,
               "PackedSyncPtr should be only 8 bytes---something is "
               "messed up");
 
+template <typename T>
+std::ostream& operator<<(std::ostream& os, const PackedSyncPtr<T>& ptr) {
+  os << "PackedSyncPtr(" << ptr.get() << ", " << ptr.extra() << ")";
+  return os;
+}
 }
-
-#endif
-