X-Git-Url: http://plrg.eecs.uci.edu/git/?p=folly.git;a=blobdiff_plain;f=folly%2FPackedSyncPtr.h;h=a49b0270d0c25a23b699ab9b7701ee3cbfb927a7;hp=f7b753b8f062b30304d8286c510d851a53417819;hb=dcf8a19c8d08d7e730d3862c88396fdcdfa2813f;hpb=ff878dc12e3f7d7234f21b0b4b3251595c031b4c diff --git a/folly/PackedSyncPtr.h b/folly/PackedSyncPtr.h index f7b753b8..a49b0270 100644 --- a/folly/PackedSyncPtr.h +++ b/folly/PackedSyncPtr.h @@ -1,5 +1,5 @@ /* - * Copyright 2014 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. @@ -14,13 +14,17 @@ * limitations under the License. */ -#ifndef FOLLY_PACKEDSYNCPTR_H_ -#define FOLLY_PACKEDSYNCPTR_H_ +#pragma once + +#include + +#include #include +#include -#if !FOLLY_X64 -# error "PackedSyncPtr is x64-specific code." +#if !FOLLY_X64 && !FOLLY_PPC64 && !FOLLY_AARCH64 +#error "PackedSyncPtr is x64, ppc64 or aarch64 specific code." #endif /* @@ -53,20 +57,16 @@ * @author Jordan DeLong */ -#include -#include -#include - namespace folly { -template +template class PackedSyncPtr { // This just allows using this class even with T=void. Attempting // to use the operator* or operator[] on a PackedSyncPtr will // still properly result in a compile error. typedef typename std::add_lvalue_reference::type reference; -public: + public: /* * If you default construct one of these, you must call this init() * function before using it. @@ -74,7 +74,7 @@ public: * (We are avoiding a constructor to ensure gcc allows us to put * this class in packed structures.) */ - void init(T* initialPtr = 0, uint16_t initialExtra = 0) { + void init(T* initialPtr = nullptr, uint16_t initialExtra = 0) { auto intPtr = reinterpret_cast(initialPtr); CHECK(!(intPtr >> 48)); data_.init(intPtr); @@ -134,18 +134,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 data_; -}; +} FOLLY_PACK_ATTR; +static_assert( + std::is_pod>::value, + "PackedSyncPtr must be kept a POD type."); static_assert(sizeof(PackedSyncPtr) == 8, "PackedSyncPtr should be only 8 bytes---something is " "messed up"); +template +std::ostream& operator<<(std::ostream& os, const PackedSyncPtr& ptr) { + os << "PackedSyncPtr(" << ptr.get() << ", " << ptr.extra() << ")"; + return os; } - -#endif +} // namespace folly