You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-12-15 12:09:09 +03:00
87 lines
1.3 KiB
C++
87 lines
1.3 KiB
C++
#include "Utilities.h"
|
|
#include "IOCoordinator.h"
|
|
|
|
namespace storagemanager
|
|
{
|
|
|
|
ScopedReadLock::ScopedReadLock(IOCoordinator *i, const std::string &k) : ioc(i), key(k), locked(false)
|
|
{
|
|
lock();
|
|
}
|
|
ScopedReadLock::~ScopedReadLock()
|
|
{
|
|
unlock();
|
|
}
|
|
|
|
void ScopedReadLock::lock()
|
|
{
|
|
assert(!locked);
|
|
ioc->readLock(key);
|
|
locked = true;
|
|
}
|
|
|
|
void ScopedReadLock::unlock()
|
|
{
|
|
if (locked)
|
|
{
|
|
ioc->readUnlock(key);
|
|
locked = false;
|
|
}
|
|
}
|
|
|
|
ScopedWriteLock::ScopedWriteLock(IOCoordinator *i, const std::string &k) : ioc(i), key(k), locked(false)
|
|
{
|
|
lock();
|
|
}
|
|
ScopedWriteLock::~ScopedWriteLock()
|
|
{
|
|
unlock();
|
|
}
|
|
|
|
void ScopedWriteLock::lock()
|
|
{
|
|
assert(!locked);
|
|
ioc->writeLock(key);
|
|
locked = true;
|
|
}
|
|
|
|
void ScopedWriteLock::unlock()
|
|
{
|
|
if (locked)
|
|
{
|
|
ioc->writeUnlock(key);
|
|
locked = false;
|
|
}
|
|
}
|
|
|
|
ScopedCloser::ScopedCloser(int f) : fd(f) { }
|
|
ScopedCloser::~ScopedCloser() {
|
|
int s_errno = errno;
|
|
::close(fd);
|
|
errno = s_errno;
|
|
}
|
|
|
|
SharedCloser::SharedCloser(int f)
|
|
{
|
|
block = new CtrlBlock();
|
|
block->fd = f;
|
|
block->refCount = 1;
|
|
}
|
|
|
|
SharedCloser::SharedCloser(const SharedCloser &s) : block(s.block)
|
|
{
|
|
block->refCount++;
|
|
}
|
|
|
|
SharedCloser::~SharedCloser()
|
|
{
|
|
block->refCount--;
|
|
if (block->refCount == 0)
|
|
{
|
|
::close(block->fd);
|
|
delete block;
|
|
}
|
|
}
|
|
|
|
}
|