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