代码拉取完成,页面将自动刷新
#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(); // 释放信号量
};
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。