当前位置: 首页>>代码示例>>C++>>正文


C++ SignalSema函数代码示例

本文整理汇总了C++中SignalSema函数的典型用法代码示例。如果您正苦于以下问题:C++ SignalSema函数的具体用法?C++ SignalSema怎么用?C++ SignalSema使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了SignalSema函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: NetManRpcNetIFSendPacket

int NetManRpcNetIFSendPacket(const void *packet, unsigned int length){
	struct PacketTag *PacketTag;

	WaitSema(NetManTxSemaID);

	NetmanTxWaitingThread=GetThreadId();

	WaitSema(TxBankAccessSema);

	//Check is there is space in the current Tx FIFO. If not, wait for the Tx thread to empty out the other FIFO. */
	while(CurrentTxFIFOData->PacketReqs.NumPackets>=NETMAN_RPC_BLOCK_SIZE){
		SignalSema(TxBankAccessSema);
		WakeupThread(TxThreadID);
		SleepThread();
		WaitSema(TxBankAccessSema);
	}

	memcpy(&CurrentTxFIFOData->FrameBuffer[CurrentTxFIFOData->PacketReqs.TotalLength], packet, length);
	PacketTag=&CurrentTxFIFOData->PacketReqs.tags[CurrentTxFIFOData->PacketReqs.NumPackets];
	PacketTag->offset=CurrentTxFIFOData->PacketReqs.TotalLength;
	PacketTag->length=length;

	CurrentTxFIFOData->PacketReqs.TotalLength+=(length+3)&~3;
	CurrentTxFIFOData->PacketReqs.NumPackets++;

	WakeupThread(TxThreadID);

	SignalSema(TxBankAccessSema);

	NetmanTxWaitingThread=-1;

	SignalSema(NetManTxSemaID);

	return 0;
}
开发者ID:JoseEduardo,项目名称:ps2sdk,代码行数:35,代码来源:rpc_client.c

示例2: WaitSema

Ps2File *findInCache(int64 id) {
	if (id <= 0)
		return NULL;
	WaitSema(cacheListSema);
	FioHandleCache *node = cacheListStart;
	while (node) {
		if (node->file->_cacheId == id) {
			if (node == cacheListStart)
				cacheListStart = node->next;
			if (node == cacheListEnd)
				cacheListEnd = node->prev;
			if (node->prev)
				node->prev->next = node->next;
			if (node->next)
				node->next->prev = node->prev;
			Ps2File *ret = node->file;
			delete node;
			cacheListLen--;
			SignalSema(cacheListSema);
			return ret;
		} else
			node = node->next;
	}
	SignalSema(cacheListSema);
	return NULL;
}
开发者ID:iPodLinux-Community,项目名称:iScummVM,代码行数:26,代码来源:fileio.cpp

示例3: ntpbserverEndReply

//--------------------------------------------------------------
int ntpbserverEndReply(void)
{
	int rcvSize, sndSize, recv_size, sent_size, ntpbpktSize, packetSize;

	// Waiting io semaphore
	WaitSema(ntpbserver_io_sema);

	// Build up ntpb packet
	memcpy(&ntpb_buf[0], ntpb_hdrmagic, ntpb_MagicSize); //copying NTPB Magic
	*((u16 *)&ntpb_buf[ntpb_MagicSize]) = 0;
	*((u16 *)&ntpb_buf[ntpb_MagicSize+2]) = 0xffff;

	packetSize = ntpb_hdrSize;

	// Send ntpb packet to client
	sent_size = 0;
	// fragmented packet handling
	while (sent_size < packetSize) {
		sndSize = lwip_send(client_socket, &ntpb_buf[sent_size], packetSize - sent_size, 0);
		if (sndSize < 0)
			return -1;

		sent_size += sndSize;
	}

	// receive the response packet from client
	rcvSize = recv_noblock(client_socket, &ntpb_buf[0], sizeof(ntpb_buf));
	if (rcvSize <= 0)
		return -1;

	ntpbpktSize = *((u16 *)&ntpb_buf[ntpb_MagicSize]);
	packetSize = ntpbpktSize + ntpb_hdrSize;

	recv_size = rcvSize;

	// fragmented packet handling
	while (recv_size < packetSize) {
		rcvSize = recv_noblock(client_socket, &ntpb_buf[recv_size], sizeof(ntpb_buf) - recv_size);
		if (rcvSize <= 0)
			return -1;

		recv_size += rcvSize;
	}

	// parses packet
	if (!check_ntpb_header(ntpb_buf))
		return -2;

	// check client reply
	if (*((u16 *)&ntpb_buf[ntpb_hdrSize]) != 1)
		return -2;

	// Posting semaphore for server Thread so it's able to wait for requests again
	SignalSema(ntpbserver_cmd_sema);

	// posting io semaphore
	SignalSema(ntpbserver_io_sema);

	return 0;
}
开发者ID:effection,项目名称:ps2rd,代码行数:61,代码来源:ntpbserver.c

示例4: sceCdSearchFile

s32 sceCdSearchFile(sceCdlFILE * file, const char *name)
{
	s32 i;

	sceCdSemaInit();
	if (PollSema(nCmdSemaId) != nCmdSemaId)
		return 0;
	nCmdNum = CD_SERVER_SEARCHFILE;
	ReferThreadStatus(sceCdThreadId, &sceCdThreadParam);
	if (sceCdSync(1)) {
		SignalSema(nCmdSemaId);
		return 0;
	}
	SifInitRpc(0);
	if (bindSearchFile < 0) {
		while (1) {
			if (SifBindRpc(&clientSearchFile, CD_SERVER_SEARCHFILE, 0) < 0) {
				if (sceCdDebug > 0)
					printf("libsceCdvd bind err sceCdSearchFile\n");
			}
			if (clientSearchFile.server != 0)
				break;

			i = 0x10000;
			while (i--);
		}
		bindSearchFile = 0;
	}

	strncpy(searchFileSendBuff.name, name, 255);
	searchFileSendBuff.name[255] = '\0';
	searchFileSendBuff.dest = &searchFileSendBuff;

	if (sceCdDebug > 0)
		printf("ee call cmd search %s\n", searchFileSendBuff.name);
	if (SifCallRpc(&clientSearchFile, 0, 0, &searchFileSendBuff, sizeof(SearchFilePkt), nCmdRecvBuff, 4, 0, 0) < 0) {
		SignalSema(nCmdSemaId);
		return 0;
	}

	memcpy(file, UNCACHED_SEG(&searchFileSendBuff), 32);

	if (sceCdDebug > 0) {
		printf("search name %s\n", file->name);
		printf("search size %d\n", file->size);
		printf("search loc lnn %d\n", file->lsn);
		printf("search loc date %02X %02X %02X %02X %02X %02X %02X %02X\n",
		       file->date[0], file->date[1], file->date[2], file->date[3],
		       file->date[4], file->date[5], file->date[6], file->date[7]);
		printf("search loc date %02d %02d %02d %02d %02d %02d %02d %02d\n",
		       file->date[0], file->date[1], file->date[2], file->date[3],
		       file->date[4], file->date[5], file->date[6], file->date[7]);
	}

	SignalSema(nCmdSemaId);
//	return 1;
	return *(s32*)UNCACHED_SEG(nCmdRecvBuff);
}
开发者ID:przemekh,项目名称:ps2sdk,代码行数:58,代码来源:libcdvd.c

示例5: apaRename

// Unofficial helper for renaming APA partitions.
static int apaRename(s32 device, const apa_params_t *oldParams, const apa_params_t *newParams)
{
	apa_cache_t *clink;
	int i, rv;

	// look to see if can make(newname) or not...
	if((clink = apaFindPartition(device, newParams->id, &rv)) != NULL)
	{
		apaCacheFree(clink);
		SignalSema(fioSema);
		return -EEXIST;	// File exists
	}

	// look to see if open(oldname)
	for(i=0;i<apaMaxOpen;i++)
	{
		if(hddFileSlots[i].f!=NULL)
		{
			if(memcmp(hddFileSlots[i].id, oldParams->id, APA_IDMAX)==0)
			{
				SignalSema(fioSema);
				return -EBUSY;
			}
		}
	}

	// Do not allow system partitions (__*) to be renamed.
	if(oldParams->id[0]=='_' && oldParams->id[1]=='_')
		return -EACCES;

	// find :)
	if((clink = apaFindPartition(device, oldParams->id, &rv)) == NULL)
	{
		SignalSema(fioSema);
		return rv;
	}

	// Check for access rights.
	if(apaPassCmp(clink->header->fpwd, oldParams->fpwd) != 0)
	{
		apaCacheFree(clink);
		return -EACCES;
	}

	// do the renaming :) note: subs have no names!!
	memcpy(clink->header->id, newParams->id, APA_IDMAX);

	// Update passwords
	memcpy(clink->header->rpwd, newParams->rpwd, APA_PASSMAX);
	memcpy(clink->header->fpwd, newParams->fpwd, APA_PASSMAX);

	clink->flags|=APA_CACHE_FLAG_DIRTY;

	apaCacheFlushAllDirty(device);
	apaCacheFree(clink);

	return 0;
}
开发者ID:ps2dev,项目名称:ps2sdk,代码行数:59,代码来源:hdd_fio.c

示例6: hddReName

int hddReName(iop_file_t *f, const char *oldname, const char *newname)
{
	int rv;
	int i;
	apa_cache	*clink;
	char tmpBuf[APA_IDMAX];

	if(f->unit >= 2 || hddDeviceBuf[f->unit].status!=0)
		return -ENODEV;// No such device

	WaitSema(fioSema);
	// look to see if can make(newname) or not...
	memset(tmpBuf, 0, APA_IDMAX);
	strncpy(tmpBuf, newname, APA_IDMAX - 1);
	tmpBuf[APA_IDMAX - 1] = '\0';
	if((clink=apaFindPartition(f->unit, tmpBuf, &rv))){
		cacheAdd(clink);
		SignalSema(fioSema);
		return -EEXIST;	// File exists
	}

	// look to see if open(oldname)
	memset(tmpBuf, 0, APA_IDMAX);
	strncpy(tmpBuf, oldname, APA_IDMAX - 1);
	tmpBuf[APA_IDMAX - 1] = '\0';
	for(i=0;i<maxOpen;i++)
	{
		if(fileSlots[i].f!=0)
			if(fileSlots[i].f->unit==f->unit)
				if(memcmp(fileSlots[i].id, oldname, APA_IDMAX)==0)
				{
					SignalSema(fioSema);
					return -EBUSY;
				}
	}

	// find :)
	if(!(clink=apaFindPartition(f->unit, tmpBuf, &rv)))
	{
		SignalSema(fioSema);
		return -ENOENT;
	}

	// do the renameing :) note: subs have no names!!
	memset(clink->header->id, 0, APA_IDMAX);		// all cmp are done with memcmp!
	strncpy(clink->header->id, newname, APA_IDMAX - 1);
	clink->header->id[APA_IDMAX - 1] = '\0';

	clink->flags|=CACHE_FLAG_DIRTY;
	cacheFlushAllDirty(f->unit);
	cacheAdd(clink);
	SignalSema(fioSema);
	return 0;
}
开发者ID:darkseedzero,项目名称:open-ps2-loader,代码行数:54,代码来源:hdd_fio.c

示例7: WaitSema

void OSystem_PS2::unlockMutex(MutexRef mutex) {
	WaitSema(_mutexSema);
	Ps2Mutex *sysMutex = (Ps2Mutex*)mutex;
	int tid = GetThreadId();

	if (sysMutex->owner && sysMutex->count && (sysMutex->owner == tid))
		sysMutex->count--;
	else {
		assert(sysMutex->count == 0);
		SignalSema(sysMutex->sema);
		sysMutex->owner = 0;
	}
	SignalSema(_mutexSema);
}
开发者ID:St0rmcrow,项目名称:scummvm,代码行数:14,代码来源:ps2mutex.cpp

示例8: ioWorkerThread

static void ioWorkerThread(void) {
	while (!gIOTerminate) {
		SleepThread();

		// no processing when io is blocked
		if (isIOBlocked)
			continue;
			
		// if term requested exit immediately from the loop
		if (gIOTerminate)
			break;
		
		// do we have a request in the queue?
		while (gReqList) {
			WaitSema(gProcSemaId);
			
			struct io_request_t* req = gReqList;
			ioProcessRequest(req);

			// lock the queue tip as well now
			WaitSema(gEndSemaId);
			
			// can't be sure if the request was
			gReqList = req->next;
			free(req);
						
			if (!gReqList)
				gReqEnd = NULL;

			SignalSema(gProcSemaId);
			SignalSema(gEndSemaId);
		}
	}
	
	// delete the pending requests
	while (gReqList) {
		struct io_request_t* req = gReqList;
		gReqList = gReqList->next;
		free(req); // TODO: Leak over here - we need a propper flag to free/not the user data
	}
	
	// delete the semaphores
	DeleteSema(gProcSemaId);
	DeleteSema(gEndSemaId);
	
	isIORunning = 0;

	ExitDeleteThread();
}
开发者ID:darkseedzero,项目名称:open-ps2-loader,代码行数:49,代码来源:ioman.c

示例9: TxThread

static void TxThread(void *arg){
	struct TxFIFOData *TxFIFODataToTransmit;
	SifDmaTransfer_t dmat;
	int dmat_id, ThreadToWakeUp;

	while(1){
		SleepThread();

		WaitSema(TxBankAccessSema);

		if(CurrentTxFIFOData->PacketReqs.NumPackets>0){
			// Switch banks
			TxFIFODataToTransmit=CurrentTxFIFOData;
			if(TxActiveBankID==0){
				CurrentTxFIFOData=&TxFIFOData2;
				TxActiveBankID=1;
			}
			else{
				CurrentTxFIFOData=&TxFIFOData1;
				TxActiveBankID=0;
			}

			SignalSema(TxBankAccessSema);

			SifWriteBackDCache(&TxFIFODataToTransmit->PacketReqs, sizeof(TxFIFODataToTransmit->PacketReqs));

			dmat.src=&TxFIFODataToTransmit->PacketReqs;
			dmat.dest=TxFrameTagBuffer;
			dmat.size=8+sizeof(struct PacketTag)*TxFIFODataToTransmit->PacketReqs.NumPackets;
			dmat.attr=0;

			while((dmat_id=SifSetDma(&dmat, 1))==0){};

			WaitSema(NetManIOSemaID);
			SifCallRpc(&NETMAN_rpc_cd, NETMAN_IOP_RPC_FUNC_SEND_PACKETS, 0, TxFIFODataToTransmit->FrameBuffer, TxFIFODataToTransmit->PacketReqs.TotalLength, NULL, 0, NULL, NULL);
			SignalSema(NetManIOSemaID);

			TxFIFODataToTransmit->PacketReqs.NumPackets=0;
			TxFIFODataToTransmit->PacketReqs.TotalLength=0;
		}
		else SignalSema(TxBankAccessSema);

		if(NetmanTxWaitingThread>=0){
			ThreadToWakeUp=NetmanTxWaitingThread;
			NetmanTxWaitingThread=-1;	//To prevent a race condition from occurring, invalidate NetmanTxWaitingThread before invoking WakeupThread.
			WakeupThread(ThreadToWakeUp);
		}
	}
}
开发者ID:JoseEduardo,项目名称:ps2sdk,代码行数:49,代码来源:rpc_client.c

示例10: ioWorkerThread

static void ioWorkerThread(void *arg) {
	while (!gIOTerminate) {
		SleepThread();

		// if term requested exit immediately from the loop
		if (gIOTerminate)
			break;

		// do we have a request in the queue?
		WaitSema(gProcSemaId);
		while (gReqList) {
			// if term requested exit immediately from the loop
			if (gIOTerminate)
				break;

			struct io_request_t* req = gReqList;
			ioProcessRequest(req);

			// lock the queue tip as well now
			WaitSema(gEndSemaId);

			// can't be sure if the request was
			gReqList = req->next;
			free(req);

			if (!gReqList)
				gReqEnd = NULL;

			SignalSema(gEndSemaId);
		}
		SignalSema(gProcSemaId);
	}

	// delete the pending requests
	while (gReqList) {
		struct io_request_t* req = gReqList;
		gReqList = gReqList->next;
		free(req);
	}

	// delete the semaphores
	DeleteSema(gProcSemaId);
	DeleteSema(gEndSemaId);

	isIORunning = 0;

	ExitDeleteThread();
}
开发者ID:doctorxyz,项目名称:open-ps2-loader,代码行数:48,代码来源:ioman.c

示例11: NetManRegisterNetIF

int NetManRegisterNetIF(struct NetManNetIF *NetIF){
	unsigned int i;
	int result;
	iop_event_t EventFlag;

	WaitSema(NetManIOSemaID);

	for(i=0, result=-ENOMEM; i<NETMAN_MAX_NETIF_COUNT; i++){
		if(!(NetIFs[i].flags&NETMAN_NETIF_IN_USE)){
			if(NetIF->init()==0){
				EventFlag.attr = 0;
				EventFlag.option = 0;
				EventFlag.bits = 0;
				if((result = NetIF->EventFlagID = CreateEventFlag(&EventFlag)) >= 0){
					memcpy(&NetIFs[i], NetIF, sizeof(NetIFs[i]));
					NetIFs[i].flags|=NETMAN_NETIF_IN_USE;
					result=NetIFs[i].id=((unsigned int)NextNetIFID)<<8|i;

					UpdateNetIFStatus();
					NextNetIFID++;
				}
			}
			else result=-EIO;
			break;
		}
	}

	SignalSema(NetManIOSemaID);

	return result;
}
开发者ID:ps2dev,项目名称:ps2sdk,代码行数:31,代码来源:netman.c

示例12: PS2CamCallback

/** call back for most lowlevel usb funtions */
void PS2CamCallback(int resultCode, int bytes, void *arg)
{
	if(resultCode !=0)
		printf("callback: result= %d, bytes= %d, arg= %p \n", resultCode, bytes, arg);

	SignalSema(ps2cam_sema);
}
开发者ID:rickgaiser,项目名称:ps2sdk,代码行数:8,代码来源:ps2cam.c

示例13: sys_sem_signal

void
sys_sem_signal(sys_sem_t Sema)
{
	dbgprintf("sys_sem_signal: Sema: %d (TID: %d)\n",Sema,GetThreadId());

	SignalSema(Sema);
}
开发者ID:AzagraMac,项目名称:PS2_SDK,代码行数:7,代码来源:sys_arch.c

示例14: ps2_fclose

int ps2_fclose(FILE *stream) {
	Ps2File *file = (Ps2File*)stream;
	if (file->_cacheId > 0) { // this is a file on the CD, could be smart to cache it
		FioHandleCache *newHandle = new FioHandleCache;
		newHandle->file = file;
		file->seek(0, SEEK_SET);

		WaitSema(cacheListSema);
		if (!cacheListEnd) {
			assert(!cacheListStart);
			newHandle->prev = newHandle->next = NULL;
			cacheListEnd = cacheListStart = newHandle;
		} else {
			assert(cacheListStart);
			newHandle->prev = NULL;
			newHandle->next = cacheListStart;
			cacheListStart->prev = newHandle;
			cacheListStart = newHandle;
		}
		cacheListLen++;
		checkCacheListLen();
		SignalSema(cacheListSema);
	} else {
		openFileCount--;
		delete file;
	}
    return 0;
}
开发者ID:iPodLinux-Community,项目名称:iScummVM,代码行数:28,代码来源:fileio.cpp

示例15: audsrv_play_audio

int audsrv_play_audio(const char *chunk, int bytes)
{
	int copy, maxcopy, copied;
	int packet_size;
	int sent = 0;

	set_error(AUDSRV_ERR_NOERROR);
	maxcopy = sizeof(sbuff) - sizeof(int);
	while (bytes > 0)
	{
		WaitSema(completion_sema);

		copy = MIN(bytes, maxcopy);
		sbuff[0] = copy;
		memcpy(&sbuff[1], chunk, copy);
		packet_size = copy + sizeof(int);
		SifCallRpc(&cd0, AUDSRV_PLAY_AUDIO, 0, sbuff, packet_size, sbuff, 1*4, NULL, NULL);

		copied = sbuff[0];
		SignalSema(completion_sema);

		if (copied < 0)
		{
			/* there was an error */
			set_error(-copied);
			break;
		}

		chunk = chunk + copy;
		bytes = bytes - copy;
		sent = sent + copied;
	}

	return sent;
}
开发者ID:ps2dev,项目名称:ps2sdk,代码行数:35,代码来源:audsrv_rpc.c


注:本文中的SignalSema函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。