⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shmobjlinkeq.h

📁 uclinux的进程间通信例子
💻 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"
struct eqint
{
  bool operator()(const int c1, const int c2) const
  {
    return c1 == c2;
  }
};


template <class st, class eq> class shmobjlinkeq
{

	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
		shmobjlinkeq(int ipckey, unsigned int count);
		~shmobjlinkeq();
		//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 shmobjlinkeq<int,eqint>;
//template class shmobjlinkeq<int>;
//template class shmobjlinkeq<testObj>;
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -