proxygen
AtomicStructTest.cpp File Reference

Go to the source code of this file.

Classes

struct  TwoBy32
 
struct  S< I >
 

Functions

 TEST (AtomicStruct, two_by_32)
 
 TEST (AtomicStruct, size_selection)
 

Function Documentation

TEST ( AtomicStruct  ,
two_by_32   
)

Definition at line 28 of file AtomicStructTest.cpp.

References a, b, c, EXPECT_EQ, EXPECT_FALSE, EXPECT_TRUE, folly::AtomicStruct< T, Atom >::load(), and TwoBy32::right.

28  {
30  TwoBy32 av = a;
31  EXPECT_EQ(av.left, 10);
32  EXPECT_EQ(av.right, 20);
33  EXPECT_TRUE(a.compare_exchange_strong(av, TwoBy32{30, 40}));
34  EXPECT_FALSE(a.compare_exchange_weak(av, TwoBy32{31, 41}));
35  EXPECT_EQ(av.left, 30);
36  EXPECT_TRUE(a.is_lock_free());
37  auto b = a.exchange(TwoBy32{50, 60});
38  EXPECT_EQ(b.left, 30);
39  EXPECT_EQ(b.right, 40);
40  EXPECT_EQ(a.load().left, 50);
41  a = TwoBy32{70, 80};
42  EXPECT_EQ(a.load().right, 80);
43  a.store(TwoBy32{90, 100});
44  av = a;
45  EXPECT_EQ(av.left, 90);
47  c = b;
48  EXPECT_EQ(c.load().right, 40);
49 }
char b
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
T load(std::memory_order mo=std::memory_order_seq_cst) const noexcept
Definition: AtomicStruct.h:141
char a
uint32_t right
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
char c
TEST ( AtomicStruct  ,
size_selection   
)

Definition at line 56 of file AtomicStructTest.cpp.

References EXPECT_EQ.

56  {
57  EXPECT_EQ(sizeof(AtomicStruct<S<1>>), 1);
58  EXPECT_EQ(sizeof(AtomicStruct<S<2>>), 2);
59  EXPECT_EQ(sizeof(AtomicStruct<S<3>>), 4);
60  EXPECT_EQ(sizeof(AtomicStruct<S<4>>), 4);
61  EXPECT_EQ(sizeof(AtomicStruct<S<5>>), 8);
62  EXPECT_EQ(sizeof(AtomicStruct<S<6>>), 8);
63  EXPECT_EQ(sizeof(AtomicStruct<S<7>>), 8);
64  EXPECT_EQ(sizeof(AtomicStruct<S<8>>), 8);
65 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922