1 Star 0 Fork 0

trff/MyTinyWebserver

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
locker.h 1.32 KB
一键复制 编辑 原始数据 按行查看 历史
trff 提交于 2024-08-29 09:00 . 线程池
#pragma once
#include <pthread.h>
#include <semaphore.h>
// 文件名称:locker.h
// 类:locker、condition、semaphore
// 功能:线程同步机制封装类
// 作者:TRF
// 互斥锁类
class Locker
{
private:
pthread_mutex_t m_mutex;
public:
Locker(); // 构造函数
~Locker(); // 析构函数
bool lock(); // 上锁
bool unlock(); // 解锁
pthread_mutex_t *get(); // 获取互斥锁
};
// 条件变量类
class Condition
{
private:
pthread_cond_t m_cond;
public:
Condition(); // 构造函数
~Condition(); // 析构函数
bool wait(pthread_mutex_t *mutex); // 等待条件
bool timedwait(pthread_mutex_t *mutex, struct timespec t); // 带超时时间的等待条件
bool signal(); // 通知条件
bool broadcast(); // 广播条件
};
// 信号量类
class Semaphore
{
private:
sem_t m_sem;
public:
Semaphore(); // 构造函数
Semaphore(int value); // 带参构造函数
~Semaphore(); // 析构函数
bool wait(); // 等待信号量
bool post(); // 释放信号量
};
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/trff/MyTinyWebserver.git
git@gitee.com:trff/MyTinyWebserver.git
trff
MyTinyWebserver
MyTinyWebserver
master

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385