📄 shmobjvector.h
字号:
/*
* this file provide obj pool realization
* composed by antony
* 2003-3-24
* copyright reserved
*/
/*
* last modified 2003-3-25
*/
#ifndef __SHMBOJVECTOR_H_
#define __SHMBOJVECTOR_H_
#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/sem.h>
template <class st> class shmobjvector
{
private:
union semun {
int val;
struct semid_ds *buf;
ushort *array;
} arg;
typedef struct container
{
bool status;
st obj;
};
typedef struct
{
unsigned int maxPoolSize;
unsigned int actPoolSize;
container *shmStart;
container *shmEnd;
}shmHead;
char *m_pShm;
shmHead *m_pShmHead;
container *m_pCurContainer;
int m_iSemid;
char *shmcreate(int ipckey, unsigned int count);
void asynInit(int ipckey);
void asynStart();
void asynEnd();
public:
//create memory to contain num st obj
shmobjvector(int ipckey, unsigned int count);
~shmobjvector();
//get first obj from pool
bool setId(unsigned int) ;
//put a obj to pool
bool update(st *);
//put a obj to pool
bool put(st *);
bool get(st *);
bool isEmpty();
//detach from shm
void detach();
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -