static int WaitValidNetState(int (*checkingFunction)(void)){ int SemaID, retry_cycles; ee_sema_t SemaData; // Wait for a valid network status; SemaData.option = SemaData.attr = 0; SemaData.init_count = 0; SemaData.max_count = 1; if((SemaID = CreateSema(&SemaData)) < 0) return SemaID; for(retry_cycles = 0; checkingFunction() == 0; retry_cycles++) { SetAlarm(1000 * rmGetHsync(), &EthStatusCheckCb, &SemaID); WaitSema(SemaID); if(retry_cycles >= 30) //30s = 30*1000ms { DeleteSema(SemaID); return -1; } } DeleteSema(SemaID); return 0; }
void sceCdSemaExit(void) { if (callbackThreadId) { sceCdCallbackNum = -1; SignalSema(callbackSemaId); } DeleteSema(nCmdSemaId); DeleteSema(sCmdSemaId); DeleteSema(callbackSemaId); }
void NetManDeinitRPCClient(void){ WaitSema(NetManIOSemaID); SifCallRpc(&NETMAN_rpc_cd, NETMAN_IOP_RPC_FUNC_DEINIT, 0, NULL, 0, ReceiveBuffer, sizeof(struct NetManInitResult), NULL, NULL); TerminateThread(TxThreadID); DeleteThread(TxThreadID); DeleteSema(NetManIOSemaID); DeleteSema(NetManTxSemaID); IsInitialized=0; }
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(); }
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(); }
int mass_stor_disconnect(int devId) { mass_dev* dev; dev = mass_stor_findDevice(devId, 0); printf("USBHDFSD: disconnect: devId=%i\n", devId); if (dev == NULL) { printf("USBHDFSD: Error - disconnect: no device storage!\n"); return 0; } if (dev->status & USBMASS_DEV_STAT_CONN) { mass_stor_release(dev); part_disconnect(dev); scache_kill(dev->cache); dev->cache = NULL; dev->devId = -1; DeleteSema(dev->ioSema); if(dev->callback != NULL) dev->callback(USBMASS_DEV_EV_DISCONN); } return 0; }
int poweroffInit() { int res; static int _init_count = -1; if(_init_count == _iop_reboot_count) return 0; _init_count = _iop_reboot_count; while(((res = SifBindRpc(&cd0, PWROFF_IRX, 0)) >= 0) && (cd0.server == NULL)) nopdelay(); ee_thread_t thread; ee_thread_status_t thisThread; ee_sema_t sema; // Terminate and delete any previously created threads if (powerOffThreadId >= 0) { TerminateThread(powerOffThreadId); DeleteThread(powerOffThreadId); powerOffThreadId = -1; } // Delete any previously created semaphores if (PowerOffSema >= 0) { DeleteSema(PowerOffSema); PowerOffSema = -1; } sema.init_count = 0; sema.max_count = 1; sema.option = 0; PowerOffSema = CreateSema(&sema); ReferThreadStatus(GetThreadId(), &thisThread); if (thisThread.current_priority == 0) { ChangeThreadPriority(GetThreadId(), 51); thread.initial_priority = 50; } else thread.initial_priority = thisThread.current_priority - 1; thread.stack_size = 512 * 16; thread.gp_reg = &_gp; thread.func = PowerOffThread; thread.stack = (void *)poffThreadStack; powerOffThreadId = CreateThread(&thread); StartThread(powerOffThreadId, NULL); DIntr(); SifAddCmdHandler(POFF_SIF_CMD, _poff_intr_callback, NULL); EIntr(); int autoShutdown = 0; SifCallRpc(&cd0, PWROFF_ENABLE_AUTO_SHUTOFF, 0, NULL, 0, &autoShutdown, sizeof(autoShutdown), 0, 0); return res; }
void usb_bulk_command(mass_dev* dev, cbw_packet* packet ) { int ret; iop_sema_t s; usb_callback_data cb_data; s.initial = 0; s.max = 1; s.option = 0; s.attr = 0; cb_data.semh = CreateSema(&s); ret = UsbBulkTransfer( dev->bulkEpO, //bulk output pipe packet, //data ptr 31, //data length usb_callback, (void*)&cb_data ); if (ret != USB_RC_OK) { printf("USBHDFSD: Error - sending bulk command %d\n", ret); } else { WaitSema(cb_data.semh); } DeleteSema(cb_data.semh); }
int usb_bulk_get_max_lun(mass_dev* dev) { int ret; usb_callback_data cb_data; iop_sema_t s; char max_lun; s.initial = 0; s.max = 1; s.option = 0; s.attr = 0; cb_data.semh = CreateSema(&s); //Call Bulk only mass storage reset ret = UsbControlTransfer( dev->controlEp, //default pipe 0xA1, 0xFE, 0, dev->interfaceNumber, //interface number 1, //length &max_lun, //data usb_callback, (void*) &cb_data ); if (ret != USB_RC_OK) { printf("USBHDFSD: Error - get_max_lun %d\n", ret); max_lun = -ret; } else { WaitSema(cb_data.semh); } DeleteSema(cb_data.semh); return max_lun; }
int InitThread(void) { ee_sema_t sema; ee_thread_t thread; sema.max_count = 255; sema.init_count = 0; sema.option = (u32)"KernelTopThread"; if((topSema = CreateSema(&sema)) < 0) return -1; thread.func = &topThread; thread.stack = stack; thread.stack_size = sizeof(stack); thread.gp_reg = &_gp; thread.option = (u32)"KernelTopThread"; thread.initial_priority = 0; if((topId = CreateThread(&thread)) < 0) { DeleteSema(topSema); return -1; } topArg.requestOut = 0; topArg.requestIn = 0; StartThread(topId, &topArg); ChangeThreadPriority(GetThreadId(), 1); return topId; }
void usb_bulk_clear_halt(mass_dev* dev, int direction) { int ret; usb_callback_data cb_data; iop_sema_t s; int endpoint; s.initial = 0; s.max = 1; s.option = 0; s.attr = 0; cb_data.semh = CreateSema(&s); if (direction == 0) { endpoint = dev->bulkEpIAddr; //endpoint = dev->bulkEpI; } else { endpoint = dev->bulkEpOAddr; } ret = UsbClearEndpointFeature( dev->controlEp, //Config pipe 0, //HALT feature endpoint, usb_callback, (void*)&cb_data ); if (ret != USB_RC_OK) { printf("USBHDFSD: Error - sending clear halt %d\n", ret); } else { WaitSema(cb_data.semh); } DeleteSema(cb_data.semh); }
int SifCallRpc(SifRpcClientData_t *cd, int rpc_number, int mode, void *sendbuf, int ssize, void *recvbuf, int rsize, SifRpcEndFunc_t endfunc, void *efarg) { ee_sema_t sema; SifRpcCallPkt_t *call; call = (SifRpcCallPkt_t *)_rpc_get_packet(&_sif_rpc_data); if (!call) return -E_SIF_PKT_ALLOC; cd->hdr.pkt_addr = call; cd->hdr.rpc_id = call->rpc_id; cd->hdr.sema_id = -1; cd->end_function = endfunc; cd->end_param = efarg; call->rpc_number = rpc_number; call->send_size = ssize; call->receive = recvbuf; call->recv_size = rsize; call->rmode = 1; call->pkt_addr = call; call->client = cd; call->server = cd->server; if (!(mode & SIF_RPC_M_NOWBDC)) { if (ssize > 0) SifWriteBackDCache(sendbuf, ssize); if (rsize > 0) SifWriteBackDCache(recvbuf, rsize); } if (mode & SIF_RPC_M_NOWAIT) { if (!endfunc) call->rmode = 0; if (!SifSendCmd(0x8000000a, call, RPC_PACKET_SIZE, sendbuf, cd->buff, ssize)) return -E_SIF_PKT_SEND; return 0; } sema.max_count = 1; sema.init_count = 0; cd->hdr.sema_id = CreateSema(&sema); if (cd->hdr.sema_id < 0) return -E_LIB_SEMA_CREATE; if (!SifSendCmd(0x8000000a, call, RPC_PACKET_SIZE, sendbuf, cd->buff, ssize)) return -E_SIF_PKT_SEND; WaitSema(cd->hdr.sema_id); DeleteSema(cd->hdr.sema_id); return 0; }
Ps2ReadFile::~Ps2ReadFile(void) { if (_cacheOpRunning) cacheReadSync(); free(_cacheBuf); if (_fd >= 0) fio.close(_fd); DeleteSema(_sema); }
void OSystem_PS2::deleteMutex(MutexRef mutex) { WaitSema(_mutexSema); Ps2Mutex *sysMutex = (Ps2Mutex*)mutex; if (sysMutex->owner || sysMutex->count) printf("WARNING: Deleting LOCKED mutex!\n"); DeleteSema(sysMutex->sema); sysMutex->sema = -1; SignalSema(_mutexSema); }
//--------------------------------------------------------------------------- static void fs_reset(void) { int i; for (i = 0; i < MAX_FILES; i++) { fsRec[i].dirent.file_flag = -1; } #ifndef WIN32 if(_lock_sema_id >= 0) { DeleteSema(_lock_sema_id); } #endif _fs_init_lock(); }
/** Shutdowns audsrv @returns AUDSRV_ERR_NOERROR */ int audsrv_quit() { WaitSema(completion_sema); SifCallRpc(&cd0, AUDSRV_QUIT, 0, sbuff, 1*4, sbuff, 4, _audsrv_intr, NULL); set_error(AUDSRV_ERR_NOERROR); DeleteSema(completion_sema); return 0; }
int shutdown() { if (alloc_sema >= 0) { DeleteSema(alloc_sema); } FreeSysMemory(heap_start); return 0; }
static void deinitCleanup(void) { if(TxThreadID >= 0) { TerminateThread(TxThreadID); DeleteThread(TxThreadID); TxThreadID = -1; } if(NetManIOSemaID >= 0) { DeleteSema(NetManIOSemaID); NetManIOSemaID = -1; } if(NetManTxSemaID >= 0) { DeleteSema(NetManTxSemaID); NetManTxSemaID = -1; } }
void fioExit(void) { if(_fio_init) { _fio_init = 0; memset(&_fio_cd, 0, sizeof _fio_cd); if (_fio_completion_sema >= 0) { DeleteSema(_fio_completion_sema); } } }
int usb_bulk_status(mass_dev* dev, csw_packet* csw, int tag) { int ret; iop_sema_t s; usb_callback_data cb_data; s.initial = 0; s.max = 1; s.option = 0; s.attr = 0; cb_data.semh = CreateSema(&s); csw->signature = CSW_TAG; csw->tag = tag; csw->dataResidue = 0; csw->status = 0; ret = UsbBulkTransfer( dev->bulkEpI, //bulk input pipe csw, //data ptr 13, //data length usb_callback, (void*)&cb_data ); if (ret != USB_RC_OK) { printf("USBHDFSD: Error - sending bulk status %d\n", ret); DeleteSema(cb_data.semh); return -1; } else { WaitSema(cb_data.semh); DeleteSema(cb_data.semh); if (cb_data.returnSize != 13) printf("USBHDFSD: bulk csw.status returnSize: %i\n", cb_data.returnSize); if (csw->dataResidue != 0) printf("USBHDFSD: bulk csw.status residue: %i\n", csw->dataResidue); XPRINTF("USBHDFSD: bulk csw.status: %i\n", csw->status); return csw->status; } }
void sys_sem_free(sys_sem_t Sema) { dbgprintf("sys_sem_free: Sema: %d (TID: %d)\n",Sema,GetThreadId()); if(Sema==SYS_SEM_NULL) { printf("sys_sem_free: Trying to delete illegal sema: %d\n",Sema); return; } DeleteSema(Sema); --sema_count; }
int poweroffInit(void) { ee_thread_t thread; ee_sema_t sema; int res; static int _init_count = -1; if(_init_count == _iop_reboot_count) return 0; _init_count = _iop_reboot_count; while(((res = SifBindRpc(&cd0, PWROFF_IRX, 0)) >= 0) && (cd0.server == NULL)) nopdelay(); // Terminate and delete any previously created threads if (powerOffThreadId >= 0) { TerminateThread(powerOffThreadId); DeleteThread(powerOffThreadId); powerOffThreadId = -1; } // Delete any previously created semaphores if (PowerOffSema >= 0) { DeleteSema(PowerOffSema); PowerOffSema = -1; } sema.init_count = 0; sema.max_count = 1; sema.option = 0; PowerOffSema = CreateSema(&sema); thread.initial_priority = POWEROFF_THREAD_PRIORITY; thread.stack_size = sizeof(poffThreadStack); thread.gp_reg = &_gp; thread.func = PowerOffThread; thread.stack = (void *)poffThreadStack; powerOffThreadId = CreateThread(&thread); StartThread(powerOffThreadId, NULL); DI(); SifAddCmdHandler(POFF_SIF_CMD, _poff_intr_callback, NULL); EI(); int autoShutdown = 0; SifCallRpc(&cd0, PWROFF_ENABLE_AUTO_SHUTOFF, 0, NULL, 0, &autoShutdown, sizeof(autoShutdown), NULL, NULL); return res; }
static void deinitCleanup(void){ if(TxThreadID >= 0){ TerminateThread(TxThreadID); DeleteThread(TxThreadID); TxThreadID = -1; } if(NetManIOSemaID >= 0){ DeleteSema(NetManIOSemaID); NetManIOSemaID = -1; } if(NetManTxSemaID >= 0){ DeleteSema(NetManTxSemaID); NetManTxSemaID = -1; } if(TxFIFOData1.FrameBuffer != NULL){ free(TxFIFOData1.FrameBuffer); TxFIFOData1.FrameBuffer = NULL; } if(TxFIFOData2.FrameBuffer != NULL){ free(TxFIFOData2.FrameBuffer); TxFIFOData2.FrameBuffer = NULL; } }
int audsrv_quit() { WaitSema(completion_sema); SifCallRpc(&cd0, AUDSRV_QUIT, 0, sbuff, 1*4, sbuff, 4, NULL, NULL); set_error(AUDSRV_ERR_NOERROR); SifRemoveRpc(&cb_srv, &cb_queue); SifRemoveRpcQueue(&cb_queue); TerminateThread(rpc_server_thread_id); DeleteThread(rpc_server_thread_id); DeleteSema(completion_sema); return 0; }
void ethDeinitModules(void) { if(ethInitSemaID >=0) WaitSema(ethInitSemaID); HttpDeinit(); nbnsDeinit(); NetManDeinit(); ethModulesLoaded = 0; gNetworkStartup = ERROR_ETH_NOT_STARTED; if(ethInitSemaID >=0) { DeleteSema(ethInitSemaID); ethInitSemaID = -1; } }
unsigned int sleep(unsigned int seconds) { ee_sema_t sema; struct sleep_data sd; sema.init_count = 0; sema.max_count = 1; sema.option = 0; sd.wait = clock() + seconds * CLOCKS_PER_SEC; sd.s = CreateSema(&sema); SetAlarm(HSYNC_COUNT, _sleep_waker, &sd); WaitSema(sd.s); DeleteSema(sd.s); return 0; }
int fioInit() { int res; ee_sema_t compSema; static int _rb_count = 0; if(_rb_count != _iop_reboot_count) { _rb_count = _iop_reboot_count; if (_fio_completion_sema >= 0) { DeleteSema(_fio_completion_sema); } memset(&_fio_cd, 0, sizeof _fio_cd); _fio_init = 0; } if (_fio_init) return 0; SifInitRpc(0); while (((res = SifBindRpc(&_fio_cd, 0x80000001, 0)) >= 0) && (_fio_cd.server == NULL)) nopdelay(); if (res < 0) return res; compSema.init_count = 1; compSema.max_count = 1; compSema.option = 0; _fio_completion_sema = CreateSema(&compSema); if (_fio_completion_sema < 0) return -E_LIB_SEMA_CREATE; _fio_init = 1; _fio_block_mode = FIO_WAIT; return 0; }
int usb_bulk_transfer(int pipe, void* buffer, int transferSize) { int ret; char* buf = (char*) buffer; int blockSize = transferSize; int offset = 0; iop_sema_t s; usb_callback_data cb_data; s.initial = 0; s.max = 1; s.option = 0; s.attr = 0; cb_data.semh = CreateSema(&s); while (transferSize > 0) { if (transferSize < blockSize) { blockSize = transferSize; } ret = UsbBulkTransfer( pipe, //bulk pipe epI(Read) epO(Write) (buf + offset), //data ptr blockSize, //data length usb_callback, (void*)&cb_data ); if (ret != USB_RC_OK) { printf("USBHDFSD: Error - sending bulk data transfer %d\n", ret); cb_data.returnCode = -1; break; } else { WaitSema(cb_data.semh); //XPRINTF("USBHDFSD: retCode=%i retSize=%i \n", cb_data.returnCode, cb_data.returnSize); if (cb_data.returnCode > 0) { break; } offset += cb_data.returnSize; transferSize-= cb_data.returnSize; } } DeleteSema(cb_data.semh); return cb_data.returnCode; }
void usb_bulk_reset(mass_dev* dev, int mode) { int ret; usb_callback_data cb_data; iop_sema_t s; s.initial = 0; s.max = 1; s.option = 0; s.attr = 0; cb_data.semh = CreateSema(&s); //Call Bulk only mass storage reset ret = UsbControlTransfer( dev->controlEp, //default pipe 0x21, //bulk reset 0xFF, 0, dev->interfaceNumber, //interface number 0, //length NULL, //data usb_callback, (void*) &cb_data ); if (ret != USB_RC_OK) { printf("USBHDFSD: Error - sending reset %d\n", ret); } else { WaitSema(cb_data.semh); //clear bulk-in endpoint if (mode & 0x01) { usb_bulk_clear_halt(dev, 0); } //clear bulk-out endpoint if (mode & 0x02) { usb_bulk_clear_halt(dev, 1); } } DeleteSema(cb_data.semh); }
void usb_set_device_feature(mass_dev* dev, int feature) { int ret; usb_callback_data cb_data; iop_sema_t s; s.initial = 0; s.max = 1; s.option = 0; s.attr = 0; cb_data.semh = CreateSema(&s); XPRINTF("USBHDFSD: setting device feature controlEp=%i, feature=%i\n", dev->controlEp, feature); ret = UsbSetDeviceFeature(dev->controlEp, feature, usb_callback, (void*)&cb_data); if (ret != USB_RC_OK) { printf("USBHDFSD: Error - sending set_device feature %d\n", ret); } else { WaitSema(cb_data.semh); } DeleteSema(cb_data.semh); }