X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2FAtomicStruct.h;h=1fb151cbc25b3fc1d7ba155e2b6c74290aebe1e0;hb=839b3f3171cefdb81cd189217184975e5fdc70df;hp=2c1c8ac319561553354093175aca363194499aef;hpb=22afce906d7e98d95f8c45c3301072d9fd891d41;p=folly.git diff --git a/folly/AtomicStruct.h b/folly/AtomicStruct.h index 2c1c8ac3..1fb151cb 100644 --- a/folly/AtomicStruct.h +++ b/folly/AtomicStruct.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,8 +14,7 @@ * limitations under the License. */ -#ifndef FOLLY_ATOMIC_STRUCT_H_ -#define FOLLY_ATOMIC_STRUCT_H_ +#pragma once #include #include @@ -44,7 +43,10 @@ class AtomicStruct { folly::IsTriviallyCopyable::value, "target type must be trivially copyable"); - Atom data; + union { + Atom data; + T typedData; + }; static Raw encode(T v) noexcept { // we expect the compiler to optimize away the memcpy, but without @@ -66,7 +68,7 @@ class AtomicStruct { AtomicStruct(AtomicStruct const &) = delete; AtomicStruct& operator= (AtomicStruct const &) = delete; - constexpr /* implicit */ AtomicStruct(T v) noexcept : data(encode(v)) {} + constexpr /* implicit */ AtomicStruct(T v) noexcept : typedData(v) {} bool is_lock_free() const noexcept { return data.is_lock_free(); @@ -135,5 +137,3 @@ template <> struct AtomicStructIntPick<8> { typedef uint64_t type; }; } // namespace detail } // namespace folly - -#endif