コード例 #1
0
ファイル: mvipc_boost.cpp プロジェクト: exodusdb/exodusdb
//this function is started as a thread by startipc()
int MVipc(const int environmentn, var& pgconnparams)
{

	//TODO prevent or handle SELECT in dictionary functions

	//flag to connect NOT to be recursive and open yet another ipc thread
	tss_ipcstarted.reset(new bool(true));

	//clone the postgres connection because the parent thread is running a select with it
	if (!var().connect(pgconnparams))
	{
		throw var(L"MVipc Cannot connect additional thread to postgres");
		return false;
	}

	//set the threads environment number (same as and provided by the parent thread)
	//AFTER opening the database connection
	setenvironmentn(environmentn);
	var processn=getprocessn();
		
	//this is a dict library caller
	//TODO check if possible to have no environment;
	//*COPY in mvipc_posix.cpp mvipc_boost.cpp mvipc_win.cpp
	MvEnvironment standalone_mv;
	MvEnvironment* mv=global_environments[environmentn];
	if (not mv)
	{
#if TRACING >= 2
		std::clog<<"MVipc() Using a standalone MvEnvironment"<<std::endl;
#endif
		mv=&standalone_mv;
		mv->init(environmentn);
	}
	ExodusFunctorBase exodusfunctorbase(*mv);
	
	//"\\\\.\\pipe\\exoduspipexyz"
	//strings of MS tchars
	//typedef basic_string<TCHAR> tstring;
	//wchar_t* exoduspipename="\\\\.\\pipe\\exoduspipexyz";
	var temp="requestexodusservice-"^processn^L"."^environmentn;
	std::string requestqueuename=temp.toString();
	var temp2="responseexodusservice-"^processn^L"."^environmentn;
	std::string responsequeuename=temp2.toString();
	//string requestqueuename="requestexodusqueue";
	//requestqueuename+=environmentn;
	//string responsequeuename="responseexodusqueue";
	//responsequeuename+=environmentn;

	closeipcqueues(requestqueuename, responsequeuename);

	try
	{
		//open request queue
		boost::interprocess::message_queue request_queue
		(
			boost::interprocess::open_or_create	//only create
			,requestqueuename.c_str()	//name
			,100		//max message number
			,BUFSIZ		//max message size
		);

		try
		{
			//open response queue
			boost::interprocess::message_queue response_queue
			(
				boost::interprocess::open_or_create	//only create
				,responsequeuename.c_str()			//name
				,100		//max message number
				,BUFSIZ		//max message size
			);

			//indicate to waiting/paused parent thread that the pipe is open
			//(the pipe is not actually waiting until the next step)
			//scoped so that the scoped_lock is automatically released after the notification
			{
				boost::mutex::scoped_lock lock(global_ipcmutex);
				#if TRACING >= 3
				std::clog<<"MVipc() Notifying that pipe has been opened\n";
				#endif
				//TODO make sure notifies CORRECT parent thread by using an array of ipcmutexes and tss_environmentn
				global_ipccondition.notify_one();
				#if TRACING >= 3
				std::clog<<L"MVipc() Notified that pipe has been opened\n";
				#endif
			}

			respondToRequests(request_queue,response_queue,exodusfunctorbase);
			
			std::clog << "finished responding to queue " << requestqueuename<<std::endl;

		}
		catch(boost::interprocess::interprocess_exception &ex)
		{
			global_ipccondition.notify_one();
			std::cerr << "cannot open " << responsequeuename << " " << ex.what() << std::endl;
			closeipcqueues(requestqueuename, responsequeuename);
			return 0;
		}

	}
	catch(boost::interprocess::interprocess_exception &ex)
	{
		global_ipccondition.notify_one();
		std::cerr << "cannot open " << requestqueuename << " " << ex.what() << std::endl;
		closeipcqueues(requestqueuename, responsequeuename);
		return 0;
	}

	closeipcqueues(requestqueuename, responsequeuename);
	return 1;
}
コード例 #2
0
ファイル: ixp4xx_crypto.c プロジェクト: cilynx/dd-wrt
static int init_sa_master(struct ix_sa_master *master)
{
	struct npe_info *npe;
	int ret = -ENODEV;

	if (! (ix_fuse() & (IX_FUSE_HASH | IX_FUSE_AES | IX_FUSE_DES))) {
		printk(KERN_ERR "ixp_crypto: No HW crypto available\n");
		return ret;
	}
	memset(master, 0, sizeof(struct ix_sa_master));
	master->npe_dev = get_npe_by_id(NPE_ID);
	if (! master->npe_dev)
		goto err;

	npe = dev_get_drvdata(master->npe_dev);

	if (npe_status(npe) & IX_NPEDL_EXCTL_STATUS_RUN) {
		switch (npe->img_info[1]) {
		case 4:
			printk(KERN_INFO "Crypto AES avaialable\n");
			break;
		case 5:
			printk(KERN_INFO "Crypto AES and CCM avaialable\n");
			break;
		default:
			printk(KERN_WARNING "Current microcode for %s has no"
				" crypto capabilities\n", npe->plat->name);
			break;
		}
	}
	rwlock_init(&master->lock);
	master->dmapool = dma_pool_create("ixp4xx_crypto", master->npe_dev,
			sizeof(struct npe_crypt_cont), 32, 0);
	if (!master->dmapool) {
		ret = -ENOMEM;
		goto err;
	}
	master->sendq = request_queue(SEND_QID, QUEUE_SIZE);
	if (IS_ERR(master->sendq)) {
		printk(KERN_ERR "ixp4xx_crypto: Error requesting Q: %d\n",
				SEND_QID);
		ret = PTR_ERR(master->sendq);
		goto err;
	}
	master->recvq = request_queue(RECV_QID, QUEUE_SIZE);
	if (IS_ERR(master->recvq)) {
		printk(KERN_ERR "ixp4xx_crypto: Error requesting Q: %d\n",
				RECV_QID);
		ret = PTR_ERR(master->recvq);
		release_queue(master->sendq);
		goto err;
	}

	master->recvq->irq_cb = irqcb_recv;
	queue_set_watermarks(master->recvq, 0, 0);
	queue_set_irq_src(master->recvq, Q_IRQ_ID_NOT_E);
	queue_enable_irq(master->recvq);
	printk(KERN_INFO "ixp4xx_crypto " MY_VERSION " registered successfully\n");

	return 0;
err:
	if (master->dmapool)
		dma_pool_destroy(master->dmapool);
	if (! master->npe_dev)
		put_device(master->npe_dev);
	return ret;

}