shmobjvector.h

来自「uclinux的进程间通信例子」· C头文件 代码 · 共 70 行

H
70
字号
/*
 * 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 + =
减小字号Ctrl + -
显示快捷键?