2018-05-30 09:14:07 +02:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice is present in all copies. The
|
|
|
|
// full license for this software is available in the LICENSE file.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#define HAVE_IRCD_DB_DATABASE_ENV_PORT_H
|
|
|
|
|
|
|
|
// This file is not part of the standard include stack because it requires
|
|
|
|
// RocksDB symbols which we cannot forward declare. It is used internally
|
|
|
|
// and does not need to be included by general users of IRCd.
|
|
|
|
|
|
|
|
// !!! EXPERIMENTAL !!!
|
|
|
|
//
|
|
|
|
// This file is special; even within the context of embedding RocksDB through
|
|
|
|
// its env interface. The functionality provided here is NOT done via
|
|
|
|
// overriding virtual interfaces called by RocksDB like with the rest of env.
|
|
|
|
// This functionality is deemed too critical for runtime virtual interfaces.
|
|
|
|
//
|
|
|
|
// Instead, the definitions we provide override those that RocksDB uses at
|
|
|
|
// link-time during the compilation of libircd. Interface declarations are not
|
|
|
|
// provided by RocksDB in its include path either, thus our interface here must
|
|
|
|
// match the rocksdb::port interface.
|
|
|
|
//
|
|
|
|
// Unfortunately if the rocksdb::port interface partially changes and we leave
|
|
|
|
// unresolved symbols at link time that may be bad, and go silently unnoticed.
|
|
|
|
//
|
|
|
|
// !!! EXPERIMENTAL !!!
|
|
|
|
|
|
|
|
namespace rocksdb::port
|
|
|
|
{
|
2018-06-01 20:31:46 +02:00
|
|
|
using namespace ircd;
|
|
|
|
|
2018-05-30 09:14:07 +02:00
|
|
|
struct Mutex;
|
|
|
|
struct CondVar;
|
|
|
|
struct RWMutex;
|
|
|
|
}
|
|
|
|
|
|
|
|
class rocksdb::port::Mutex
|
|
|
|
{
|
|
|
|
friend class CondVar;
|
|
|
|
|
2018-06-01 20:31:46 +02:00
|
|
|
ctx::mutex mu;
|
2018-05-30 09:14:07 +02:00
|
|
|
|
|
|
|
public:
|
2018-12-16 23:09:05 +01:00
|
|
|
void Lock() noexcept;
|
|
|
|
void Unlock() noexcept;
|
|
|
|
void AssertHeld() noexcept;
|
2018-05-30 09:14:07 +02:00
|
|
|
|
2018-12-16 23:09:05 +01:00
|
|
|
Mutex() noexcept;
|
|
|
|
Mutex(bool adaptive) noexcept;
|
2018-05-30 09:14:07 +02:00
|
|
|
Mutex(const Mutex &) = delete;
|
|
|
|
Mutex &operator=(const Mutex &) = delete;
|
2018-12-16 23:09:05 +01:00
|
|
|
~Mutex() noexcept;
|
2018-05-30 09:14:07 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class rocksdb::port::CondVar
|
|
|
|
{
|
|
|
|
Mutex *mu;
|
2018-06-01 20:31:46 +02:00
|
|
|
ctx::condition_variable cv;
|
2018-05-30 09:14:07 +02:00
|
|
|
|
|
|
|
public:
|
2018-12-16 23:09:05 +01:00
|
|
|
void Wait() noexcept;
|
|
|
|
bool TimedWait(uint64_t abs_time_us) noexcept; // Returns true if timeout occurred
|
|
|
|
void Signal() noexcept;
|
|
|
|
void SignalAll() noexcept;
|
2018-05-30 09:14:07 +02:00
|
|
|
|
2018-12-16 23:09:05 +01:00
|
|
|
CondVar(Mutex *mu) noexcept;
|
|
|
|
~CondVar() noexcept;
|
2018-05-30 09:14:07 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class rocksdb::port::RWMutex
|
|
|
|
{
|
2018-06-01 20:31:46 +02:00
|
|
|
ctx::shared_mutex mu;
|
2018-05-30 09:14:07 +02:00
|
|
|
|
|
|
|
public:
|
2018-12-16 23:09:05 +01:00
|
|
|
void ReadLock() noexcept;
|
|
|
|
void WriteLock() noexcept;
|
|
|
|
void ReadUnlock() noexcept;
|
|
|
|
void WriteUnlock() noexcept;
|
2018-05-30 09:14:07 +02:00
|
|
|
|
2018-12-16 23:09:05 +01:00
|
|
|
RWMutex() noexcept;
|
2018-05-30 09:14:07 +02:00
|
|
|
RWMutex(const RWMutex &) = delete;
|
|
|
|
RWMutex &operator=(const RWMutex &) = delete;
|
2018-12-16 23:09:05 +01:00
|
|
|
~RWMutex() noexcept;
|
2018-05-30 09:14:07 +02:00
|
|
|
};
|