21 #include <boost/thread/locks.hpp> 22 #include <glog/logging.h> 31 using namespace folly;
38 typedef std::unique_lock<File> Lock;
39 typedef boost::shared_lock<File> SharedLock;
42 static constexpr
size_t pathLength = 2048;
43 char buf[pathLength + 1];
44 int r = readlink(
"/proc/self/exe", buf, pathLength);
49 auto helper_basename =
"file_test_lock_helper";
51 if (fs::exists(me.parent_path() / helper_basename)) {
52 helper = me.parent_path() / helper_basename;
54 throw std::runtime_error(
55 folly::to<std::string>(
"cannot find helper ", helper_basename));
61 enum LockMode { EXCLUSIVE,
SHARED };
62 auto testLock = [&](LockMode
mode,
bool expectedSuccess) {
64 mode == SHARED ?
"-s" :
"-x",
65 tempFile.
path().string()})
69 EXPECT_EQ(expectedSuccess ? 0 : 42, ret.exitStatus());
76 { SharedLock
lock(
f); }
79 Lock
lock(
f, std::defer_lock);
84 SharedLock
lock(
f, boost::defer_lock);
91 testLock(EXCLUSIVE,
false);
97 testLock(SHARED,
false);
103 testLock(EXCLUSIVE,
false);
109 testLock(SHARED,
true);
DEFINE_bool(s, false,"get shared lock")
#define EXPECT_EQ(val1, val2)
—— Concurrent Priority Queue Implementation ——
folly::Optional< PskKeyExchangeMode > mode
auto lock(Synchronized< D, M > &synchronized, Args &&...args)
bool wait(Waiter *waiter, bool shouldSleep, Waiter *&next)
const fs::path & path() const
TEST(ProgramOptionsTest, Errors)
#define EXPECT_TRUE(condition)