1 Star 0 Fork 2

zhaoyao / shm_hash

forked from wuyi / shm_hash 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
shared_mutex.h 959 Bytes
一键复制 编辑 原始数据 按行查看 历史
wuyi 提交于 2022-02-21 19:38 . add
#ifndef _shared_mutex_h_
#define _shared_mutex_h_
#include <sys/shm.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/syscall.h>
#include <sys/mman.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <pthread.h>
class SharedMutex
{
public:
SharedMutex();
~SharedMutex();
public:
int create(bool new_flag);
bool lock();
void unlock();
protected:
bool isInited();
bool init();
protected:
char m_mutexBeginTag[16];
unsigned long m_flag;
pthread_mutexattr_t m_attr;
pthread_mutex_t m_mutex;
char m_mutexEndTag[16];
};
class MyShareAutoLock{
public:
MyShareAutoLock(SharedMutex* mutex) :
m_mutex(mutex){
m_mutex->lock();
}
~MyShareAutoLock(){
m_mutex->unlock();
}
protected:
SharedMutex* m_mutex;
};
void* getmemory(int shmkey, size_t shmsize, int& new_falag);
#endif
C++
1
https://gitee.com/zhaoyao219/shm_hash.git
git@gitee.com:zhaoyao219/shm_hash.git
zhaoyao219
shm_hash
shm_hash
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891