1 Star 2 Fork 0

InnovatorNZ/CppGCPtr

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
MutexReadWriteLock.cpp 624 Bytes
一键复制 编辑 原始数据 按行查看 历史
#include "MutexReadWriteLock.h"
thread_local int MutexReadWriteLock::read_locked_cnt = 0;
void MutexReadWriteLock::lockRead() {
if (read_locked_cnt == 0)
sharedMutex.lock_shared();
++read_locked_cnt;
}
void MutexReadWriteLock::unlockRead() {
if (read_locked_cnt <= 0)
throw std::runtime_error("MutexReadWriteLock: read_locked_cnt is 0");
--read_locked_cnt;
if (read_locked_cnt == 0)
sharedMutex.unlock_shared();
}
void MutexReadWriteLock::lockWrite() {
sharedMutex.lock();
}
void MutexReadWriteLock::lockWrite(bool) {
sharedMutex.lock();
}
void MutexReadWriteLock::unlockWrite() {
sharedMutex.unlock();
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/innovatornz/CppGCPtr.git
git@gitee.com:innovatornz/CppGCPtr.git
innovatornz
CppGCPtr
CppGCPtr
master

搜索帮助