X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2FPackedSyncPtr.h;h=e11588e8419540a32f5ff80e38749253c1f134b1;hb=37ce60726a249bb67c885236a45d50cdb781694e;hp=6e8cca53dcd8a06c61b02b8b56d9185af5471620;hpb=27494a20393fa45072e7d526d358835f3abe312a;p=folly.git diff --git a/folly/PackedSyncPtr.h b/folly/PackedSyncPtr.h index 6e8cca53..e11588e8 100644 --- a/folly/PackedSyncPtr.h +++ b/folly/PackedSyncPtr.h @@ -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. @@ -14,11 +14,12 @@ * limitations under the License. */ -#ifndef FOLLY_PACKEDSYNCPTR_H_ -#define FOLLY_PACKEDSYNCPTR_H_ +#pragma once -#ifndef __x86_64__ -# error "PackedSyncPtr is x64-specific code." +#include + +#if !FOLLY_X64 && !FOLLY_PPC64 && !FOLLY_A64 +# error "PackedSyncPtr is x64, ppc64 or aarch64 specific code." #endif /* @@ -51,7 +52,7 @@ * @author Jordan DeLong */ -#include "folly/SmallLocks.h" +#include #include #include @@ -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 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 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 -