mirror of
https://github.com/matrix-construct/construct
synced 2024-11-28 17:52:54 +01:00
ircd::db::port: Improve punned object size matching; in-bounds initialization.
This commit is contained in:
parent
198049615b
commit
d5c2ff0e99
2 changed files with 37 additions and 6 deletions
|
@ -24,7 +24,13 @@ static_assert
|
||||||
rocksdb::port::Mutex::Mutex()
|
rocksdb::port::Mutex::Mutex()
|
||||||
noexcept
|
noexcept
|
||||||
{
|
{
|
||||||
memset(this, 0x0, sizeof(pthread_mutex_t));
|
static_assert
|
||||||
|
(
|
||||||
|
sizeof(mu_) >= sizeof(mu),
|
||||||
|
"Mutex is not fully initialized."
|
||||||
|
);
|
||||||
|
|
||||||
|
memset(&mu_, 0x0, sizeof(mu_));
|
||||||
|
|
||||||
if constexpr(RB_DEBUG_DB_PORT > 1)
|
if constexpr(RB_DEBUG_DB_PORT > 1)
|
||||||
{
|
{
|
||||||
|
@ -125,7 +131,13 @@ static_assert
|
||||||
rocksdb::port::RWMutex::RWMutex()
|
rocksdb::port::RWMutex::RWMutex()
|
||||||
noexcept
|
noexcept
|
||||||
{
|
{
|
||||||
memset(this, 0x0, sizeof(pthread_rwlock_t));
|
static_assert
|
||||||
|
(
|
||||||
|
sizeof(mu_) >= sizeof(mu),
|
||||||
|
"RWMutex is not fully initialized."
|
||||||
|
);
|
||||||
|
|
||||||
|
memset(&mu_, 0x0, sizeof(mu_));
|
||||||
|
|
||||||
if constexpr(RB_DEBUG_DB_PORT > 1)
|
if constexpr(RB_DEBUG_DB_PORT > 1)
|
||||||
{
|
{
|
||||||
|
@ -252,7 +264,13 @@ static_assert
|
||||||
rocksdb::port::CondVar::CondVar(Mutex *mu)
|
rocksdb::port::CondVar::CondVar(Mutex *mu)
|
||||||
noexcept
|
noexcept
|
||||||
{
|
{
|
||||||
memset(this, 0x0, sizeof(pthread_cond_t) + sizeof(Mutex *));
|
static_assert
|
||||||
|
(
|
||||||
|
sizeof(cv_) >= sizeof(cv),
|
||||||
|
"CondVar is not fully initialized."
|
||||||
|
);
|
||||||
|
|
||||||
|
memset(&cv_, 0x0, sizeof(cv_));
|
||||||
this->mu = mu;
|
this->mu = mu;
|
||||||
|
|
||||||
if constexpr(RB_DEBUG_DB_PORT > 1)
|
if constexpr(RB_DEBUG_DB_PORT > 1)
|
||||||
|
|
|
@ -41,7 +41,11 @@ class rocksdb::port::Mutex
|
||||||
{
|
{
|
||||||
friend class CondVar;
|
friend class CondVar;
|
||||||
|
|
||||||
ctx::mutex mu;
|
union
|
||||||
|
{
|
||||||
|
ctx::mutex mu;
|
||||||
|
pthread_mutex_t mu_;
|
||||||
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void Lock() noexcept;
|
void Lock() noexcept;
|
||||||
|
@ -57,8 +61,13 @@ class rocksdb::port::Mutex
|
||||||
|
|
||||||
class rocksdb::port::CondVar
|
class rocksdb::port::CondVar
|
||||||
{
|
{
|
||||||
|
union
|
||||||
|
{
|
||||||
|
ctx::condition_variable cv;
|
||||||
|
pthread_cond_t cv_;
|
||||||
|
};
|
||||||
|
|
||||||
Mutex *mu;
|
Mutex *mu;
|
||||||
ctx::condition_variable cv;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void Wait() noexcept;
|
void Wait() noexcept;
|
||||||
|
@ -72,7 +81,11 @@ class rocksdb::port::CondVar
|
||||||
|
|
||||||
class rocksdb::port::RWMutex
|
class rocksdb::port::RWMutex
|
||||||
{
|
{
|
||||||
ctx::shared_mutex mu;
|
union
|
||||||
|
{
|
||||||
|
ctx::shared_mutex mu;
|
||||||
|
pthread_rwlock_t mu_;
|
||||||
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void ReadLock() noexcept;
|
void ReadLock() noexcept;
|
||||||
|
|
Loading…
Reference in a new issue