void listener_thread(void *unused) { sys_ppu_thread_t id; struct sockaddr_in sa; memset(&sa, 0, sizeof(sa)); sa.sin_family = AF_INET; sa.sin_port = htons(2002); sa.sin_addr.s_addr = htonl(INADDR_ANY); int list_s = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); // only 1 socket connection is allowed at once if(bind(list_s, (struct sockaddr *)&sa, sizeof(sa)) == -1 || listen(list_s, 1) == -1) { sysThreadExit(0); } int conn_s; while (!user_requested_exit()) { if((conn_s = accept(list_s, NULL, NULL)) > 0) { sysThreadCreate(&id, client_thread, (void *)&conn_s, 1337, 0x2000, 0, "client"); sysThreadYield(); } } closesocket(list_s); sysThreadExit(0); }
void listener_thread(void *unused) { struct sockaddr_in sa; memset(&sa, 0, sizeof(sa)); sa.sin_family = AF_INET; sa.sin_port = htons(ftp_port); sa.sin_addr.s_addr = htonl(INADDR_ANY); int list_s = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); if(bind(list_s, (struct sockaddr *)&sa, sizeof(sa)) == -1 || listen(list_s, OFTP_LISTEN_BACKLOG) == -1) { appstate = 1; } int conn_s; sys_ppu_thread_t id; while(appstate != 1) { if((conn_s = accept(list_s, NULL, NULL)) > 0) { sysThreadCreate(&id, client_thread, (void *)&conn_s, 1337, 0x2000, THREAD_JOINABLE, "client"); sysThreadYield(); } else sysUsleep(250000); } closesocket(list_s); sysThreadExit(0); }
void thread_exit() { sysMutexLock(thread_mutex, TIMEOUT_MUTEX); THREADS_RUNNING--; sysMutexUnlock(thread_mutex); sysThreadExit(0); }
/* video worker thread */ void videoWorker ( void *arg ) { static s32 frames ; static time_t starttime ; dbgprintf ( "video thread starting" ) ; /* cast the void *arg to rsxData */ videoData* vdata = ( videoData* )arg ; /* signal main thread is ready */ sysCondSignal ( vdata->cond ) ; /* lock mutex */ sysMutexLock ( vdata->mutex, NO_TIMEOUT ) ; dbgprintf ( "video thread waiting" ) ; /* wait for main to be ready */ sysCondWait ( vdata->cond, NO_TIMEOUT ) ; /* release lock */ sysMutexUnlock ( vdata->mutex ) ; starttime = time( NULL ) ; dbgprintf ( "video thread entering loop" ) ; /* render frames until exit */ while ( *vdata->exitapp ) { /* render frame */ videoDrawFrame ( vdata ) ; frames++ ; } dbgprintf ( "video thread left loop" ) ; /* lock mutex */ sysMutexLock ( vdata->mutex, NO_TIMEOUT ) ; /* signal main before exit */ sysCondSignal ( vdata->cond ) ; /* release lock */ sysMutexUnlock ( vdata->mutex ) ; argprintf ( "frame rate: %g frames/sec", ( ( double ) frames ) / difftime ( time ( NULL ) , starttime ) ) ; dbgprintf ( "video thread exiting" ) ; /* exit thread */ sysThreadExit ( 0 ) ; }
/* pad worker thread */ void padWorker ( void *arg ) { dbgprintf ( "pad thread starting" ) ; /* cast the void *arg to rsxData */ padBtnData* pdata = ( padBtnData* )arg ; /* signal main thread is ready */ sysCondSignal ( pdata->cond ) ; /* lock mutex */ sysMutexLock ( pdata->mutex, NO_TIMEOUT ) ; dbgprintf ( "pad thread waiting" ) ; /* wait for main to be ready */ sysCondWait ( pdata->cond, NO_TIMEOUT ) ; /* release lock */ sysMutexUnlock ( pdata->mutex ) ; dbgprintf ( "pad thread entering loop" ) ; /* render frames until exit */ while ( *pdata->exitapp ) { /* check pads */ padCheckState ( pdata ) ; } dbgprintf ( "pad thread left loop" ) ; /* lock mutex */ sysMutexLock ( pdata->mutex, NO_TIMEOUT ) ; /* signal main before exit */ sysCondSignal ( pdata->cond ) ; /* release lock */ sysMutexUnlock ( pdata->mutex ) ; dbgprintf ( "pad thread exiting" ) ; /* exit thread */ sysThreadExit ( 0 ) ; }
static void control_thread(void *a) { int n = 0; while(appstate != 1) { sysUsleep(100000); n++; if(ftp_working == 2) { ftp_working = 3; n = 0; } if(n >= 100) { if(ftp_working == 3) ftp_working = 0; n = 0; } } sysThreadExit(0); }
static void thread_start(void *arg) { s32 running = 0; sys_ppu_thread_t id; sys_ppu_thread_stack_t stackinfo; sysThreadGetId(&id); sysThreadGetStackInformation(&stackinfo); printf("stack\naddr: %p, size: %d\n",stackinfo.addr,stackinfo.size); while(running<5) { printf("Thread: %08llX\n",(unsigned long long int)id); sysThreadYield(); sleep(2); running++; } sysThreadExit(0); }
static void RunThread(void *arg) { SDL_RunThread(arg); sysThreadExit(0); }
void pte_osThreadExit() { sysThreadExit (0); }
static void client_thread(void *userdata) { p_socket client = (p_socket) userdata; ServerRequest request; ServerResponse response; uint8_t zero = 0; uint8_t *output_buf = (uint8_t *) malloc(MAX_PROCESSING_BLOCK_SIZE * SACD_LSN_SIZE + 1024); pb_istream_t input = pb_istream_from_socket(client); pb_ostream_t output; sacd_reader_t *sacd_reader = 0; scarletbook_handle_t *handle = 0; int non_encrypted_disc = 0; int checked_for_non_encrypted_disc = 0; uint32_t encrypted_start_1 = 0; uint32_t encrypted_start_2 = 0; uint32_t encrypted_end_1 = 0; uint32_t encrypted_end_2 = 0; uint32_t block_size = 0; uint32_t end_lsn = 0; client_connected = 1; response.data.bytes = (uint8_t *) malloc(MAX_PROCESSING_BLOCK_SIZE * SACD_LSN_SIZE); for (;;) { if (!pb_decode(&input, ServerRequest_fields, &request)) { break; } response.has_data = false; response.data.size = 0; response.result = -1; switch(request.type) { case ServerRequest_Type_DISC_READ: { response.type = ServerResponse_Type_DISC_READ; if (handle && sacd_reader) { int encrypted = 0; end_lsn = request.sector_offset + request.sector_count; // check what block ranges are encrypted.. if (request.sector_offset < encrypted_start_1) { block_size = min(encrypted_start_1 - request.sector_offset, MAX_PROCESSING_BLOCK_SIZE); encrypted = 0; } else if (request.sector_offset >= encrypted_start_1 && request.sector_offset <= encrypted_end_1) { block_size = min(encrypted_end_1 + 1 - request.sector_offset, MAX_PROCESSING_BLOCK_SIZE); encrypted = 1; } else if (request.sector_offset > encrypted_end_1 && request.sector_offset < encrypted_start_2) { block_size = min(encrypted_start_2 - request.sector_offset, MAX_PROCESSING_BLOCK_SIZE); encrypted = 0; } else if (request.sector_offset >= encrypted_start_2 && request.sector_offset <= encrypted_end_2) { block_size = min(encrypted_end_2 + 1 - request.sector_offset, MAX_PROCESSING_BLOCK_SIZE); encrypted = 1; } block_size = min(end_lsn - request.sector_offset, block_size); response.result = sacd_read_block_raw(sacd_reader, request.sector_offset, block_size, response.data.bytes); response.has_data = response.result > 0; response.data.size = response.result * SACD_LSN_SIZE; // the ATAPI call which returns the flag if the disc is encrypted or not is unknown at this point. // user reports tell me that the only non-encrypted discs out there are DSD 3 14/16 discs. // this is a quick hack/fix for these discs. if (encrypted && checked_for_non_encrypted_disc == 0) { switch (handle->area[0].area_toc->frame_format) { case FRAME_FORMAT_DSD_3_IN_14: case FRAME_FORMAT_DSD_3_IN_16: non_encrypted_disc = *(uint64_t *)(response.data.bytes + 16) == 0; break; } checked_for_non_encrypted_disc = 1; } // encrypted blocks need to be decrypted first if (encrypted && non_encrypted_disc == 0) { sacd_decrypt(sacd_reader, response.data.bytes, block_size); } } } break; case ServerRequest_Type_DISC_OPEN: response.type = ServerResponse_Type_DISC_OPENED; sacd_reader = sacd_open("/dev_bdvd"); if (sacd_reader) { handle = scarletbook_open(sacd_reader, 0); checked_for_non_encrypted_disc = 0; non_encrypted_disc = 0; if (handle) { // set the encryption range if (handle->area[0].area_toc != 0) { encrypted_start_1 = handle->area[0].area_toc->track_start; encrypted_end_1 = handle->area[0].area_toc->track_end; } if (handle->area[1].area_toc != 0) { encrypted_start_2 = handle->area[1].area_toc->track_start; encrypted_end_2 = handle->area[1].area_toc->track_end; } response.result = sacd_authenticate(sacd_reader); } } break; case ServerRequest_Type_DISC_CLOSE: { response.type = ServerResponse_Type_DISC_CLOSED; if (handle) { scarletbook_close(handle); handle = 0; } if (sacd_reader) { sacd_close(sacd_reader); sacd_reader = 0; } response.result = 0; } break; case ServerRequest_Type_DISC_SIZE: response.type = ServerResponse_Type_DISC_SIZE; if (sacd_reader) { response.result = sacd_get_total_sectors(sacd_reader); } break; } // reset output stream output = pb_ostream_from_buffer(output_buf, MAX_PROCESSING_BLOCK_SIZE * SACD_LSN_SIZE + 1024); if (!pb_encode(&output, ServerResponse_fields, &response)) { break; } /* We signal the end of a request with a 0 tag. */ pb_write(&output, &zero, 1); // write the output buffer to the opened socket { bool ret; size_t written; ret = (socket_send(client, (char *) output_buf, output.bytes_written, &written, 0, 0) == IO_DONE && written == output.bytes_written); if (!ret) break; } if (request.type == ServerRequest_Type_DISC_CLOSE) { break; } } if (handle) scarletbook_close(handle); if (sacd_reader) sacd_close(sacd_reader); free(response.data.bytes); free(output_buf); closesocket((int) *client); client_connected = 0; sysThreadExit(0); }