Esempio n. 1
0
static void alloc_thread_entry(void)
{
   u32 tmp;

   svcControlMemory(&tmp, mch2.alloc_address, 0x0, mch2.alloc_size, MEMOP_ALLOC, MEMPERM_READ | MEMPERM_WRITE);
   svcExitThread();
}
Esempio n. 2
0
void aptEventHandler(void *arg)
{
	bool runThread = true;

	while(runThread)
	{
		s32 syncedID = 0;
		svcWaitSynchronizationN(&syncedID, aptEvents, 3, 0, U64_MAX);
		svcClearEvent(aptEvents[syncedID]);
		switch(syncedID)
		{
			// Event 0 means we got a signal from NS (home button, power button etc).
			case 0x0:
				__handle_notification();
				break;
			// Event 1 means we got an incoming parameter.
			case 0x1:
				runThread = __handle_incoming_parameter();
				break;
			// Event 2 means we should exit the thread.
			case 0x2:
				runThread = false;
				break;
		}
	}

	svcExitThread();
}
Esempio n. 3
0
void physicsThreadMain(u32 arg)
{
	physicsThread_s* p=(physicsThread_s*)arg;
	while(!p->exit)
	{
		svcWaitSynchronization(p->requestMutex, U64_MAX);
		appendRequestQueue(&p->privateList, &p->requestList);
		svcReleaseMutex(p->requestMutex);

		// bool debug=false;
		// u64 val=svcGetSystemTick();
		
		request_s* r=NULL;
		while((r=unqueueRequest(&p->privateList)) && !p->exit)
		{
			handleRequest(p, r);
			svcSleepThread(1000);
		}

		// if(debug)print("%d ticks\n",(int)(svcGetSystemTick()-val));
		updateOBBs();

		svcSleepThread(1000000);
	}
	svcExitThread();
}
Esempio n. 4
0
File: ndsp.c Progetto: Voka/lpp-3ds
static void ndspThreadMain(void* arg)
{
	ndspThreadRun = true;
	while (ndspThreadRun)
	{
		ndspSync();

		// Call callbacks here
		if (ndspMaster.callback)
			ndspMaster.callback(ndspMaster.callbackData);

		if (bSleeping || !bDspReady)
			continue;

		if (bNeedsSync)
			ndspSync();

		ndspUpdateMaster();
		// Call aux user callback here if enabled
		// Execute DSP effects here
		ndspiUpdateChn();

		ndspSetCounter(ndspBufferCurId, ndspFrameId++);
		svcSignalEvent(dspSem);
		ndspBufferCurId = ndspFrameId & 1;

		frameCount++;
		bNeedsSync = true;
	}

	svcExitThread();
}
Esempio n. 5
0
void Thread::entryPoint(void* userData)
{
	// The Thread instance is stored in the user data
	Thread* owner = static_cast<Thread*>(userData);

	// Forward to the owner
	owner->run();

	svcExitThread();
}
Esempio n. 6
0
void threadMain(void *arg) {

	while(1) {
		svcWaitSynchronization(threadRequest, U64_MAX);
		svcClearEvent(threadRequest);		

		if(threadExit) svcExitThread();

		threadcount++;
	}
}
Esempio n. 7
0
static void alloc_thread(void* arg)
{
	u32 tmp;
	alloc_finished = false;

	while (lock_alloc)
		svcSleepThread(100);

	svcControlMemory(&tmp, alloc_address, 0x0, alloc_size, MEMOP_ALLOC, MEMPERM_READ | MEMPERM_WRITE);
	alloc_finished = true;
	svcExitThread();
}
Esempio n. 8
0
void SPCThread(u32 blarg)
{
	while (!exitemu)
	{
		if (!pause)
			SPC_Run();
		
		svcWaitSynchronization(SPCSync, (s64)(17*1000*1000));
	}
	
	svcExitThread();
}
Esempio n. 9
0
void cmd_thread_func() {
    while(1) {
        svcWaitSynchronization(new_cmd_event, U64_MAX);
        svcClearEvent(new_cmd_event);

        if(thread_exit) svcExitThread();

        last_cmd = cmd.type;
        last_cmd_result = execute_cmd(sock, &cmd);

        svcSignalEvent(cmd_done_event);
    }
}
Esempio n. 10
0
void threadMain(void *arg)
{
	ThreadArgs *const args = arg;
	while (1)
	{
		svcWaitSynchronization(*args->threadRequest, U64_MAX);
		svcClearEvent(*args->threadRequest);

		if (*args->shouldExit)
			svcExitThread();

		(*args->count)++;
	}
}
Esempio n. 11
0
static void poll_thread(void* arg)
{
	while ((u32) svcArbitrateAddress(arbiter, alloc_address, ARBITRATION_WAIT_IF_LESS_THAN_TIMEOUT, 0, 0) == 0xD9001814)
		svcSleepThread(10000);
	__asm__ volatile("cpsid aif \n\t");
	memcpy(flush_buffer, flush_buffer + 0x8000, 0x8000);
	memcpy(flush_buffer, flush_buffer + 0x8000, 0x8000);
	memcpy(flush_buffer, flush_buffer + 0x8000, 0x8000);
	memcpy(flush_buffer, flush_buffer + 0x8000, 0x8000);
	memcpy(flush_buffer, flush_buffer + 0x8000, 0x8000);
	while (lock_thread);
	__asm__ volatile("cpsie aif \n\t");
	svcExitThread();
}
Esempio n. 12
0
void threadExit(int rc)
{
	Thread t = threadGetCurrent();
	if (!t)
		__panic();

	t->finished = true;
	if (t->detached)
		threadFree(t);
	else
		t->rc = rc;

	svcExitThread();
}
Esempio n. 13
0
// Mic thread
void threadMic(){
	while(1) {
		svcWaitSynchronization(threadRequest, U64_MAX);
		svcClearEvent(threadRequest);		

		if(threadExit) svcExitThread();
		
		touchPosition touch;
		hidTouchRead(&touch);
		u32 kDown = hidKeysDown();

		if((touchInCircle(touch, 85, 120, 35) || kDown & KEY_A) && recording == 0)
		{
			audiobuf_pos = 0;
			MIC_SetRecording(1);
			recording = 1;
		}

		if((recording == 1) && (audiobuf_pos < audiobuf_size))
		{
			audiobuf_pos+= MIC_ReadAudioData(&audiobuf[audiobuf_pos], audiobuf_size-audiobuf_pos, 0);
			if(audiobuf_pos > audiobuf_size)audiobuf_pos = audiobuf_size;
			if(audiobuf_pos >= 32704 && print == 0){
				print = 1;
			}
		}

		if((touchInCircle(touch, 165, 120, 35) || kDown & KEY_B) && recording == 1)
		{
			print = 0;
			MIC_SetRecording(0);
			recording = 2;

			//Prevent first mute second to be allocated in wav struct
			if(audiobuf_pos >= 32704){
				nomute_audiobuf =  (u8*)linearAlloc(audiobuf_pos - 32704);
				memcpy(nomute_audiobuf,&audiobuf[32704],audiobuf_pos - 32704);
				buf_size = (audiobuf_pos - 32704) / 2;
				write_wav("audio.wav", buf_size, (short int *)nomute_audiobuf, S_RATE);
			}

			GSPGPU_FlushDataCache(NULL, nomute_audiobuf, audiobuf_pos);
			recording = 0;
		}
	}
}
Esempio n. 14
0
static void check_tls_thread_entry(bool* keep)
{
   *keep = !((u32)getThreadLocalStorage() & 0xFFF);
   svcExitThread();
}
Esempio n. 15
0
static void dummy_thread_entry(Handle lock)
{
   svcWaitSynchronization(lock, U64_MAX);
   svcExitThread();
}
Esempio n. 16
0
void streamWAV(void* arg){

	// Fetching cachePackage struct from main thread
	cachePackage* pack = (cachePackage*)arg;
	while(1) {
	
		// Waiting for updateStream event
		svcWaitSynchronization(updateStream, U64_MAX);
		svcClearEvent(updateStream);
		
		// Close the thread if closeStream event received
		if(closeStream){
			closeStream = false;
			svcExitThread();
		}
		
		// Check if the current stream is paused or not
		Music* src = pack->song;
		Socket* Client = pack->client;
		if (src->isPlaying){
		
			// Check if a free buffer is available
			if (src->wavebuf2 == NULL){
			
				// Check if file reached EOF
				if (src->audio_pointer >= src->size){
				
					// Check if playback ended
					if (!ndspChnIsPlaying(src->ch)){
						src->isPlaying = false;
						src->tick = (osGetTime()-src->tick);
					}
					
					continue;
				}
				
				// Swap audiobuffers
				u8* tmp = src->audiobuf;
				src->audiobuf = src->audiobuf2;
				src->audiobuf2 = tmp;
				
				// Create a new block for DSP service
				u32 bytesRead;
				src->wavebuf2 = (ndspWaveBuf*)calloc(1,sizeof(ndspWaveBuf));
				createDspBlock(src->wavebuf2, src->bytepersample, src->mem_size, 0, (u32*)src->audiobuf);
				populatePurgeTable(src, src->wavebuf2);
				ndspChnWaveBufAdd(src->ch, src->wavebuf2);
				socketSend(Client, "exec2:0000");
				u32 processedBytes = 0;
				netSize = 0;
				while (netSize <= 0) heapRecv(Client, 2048);
				while (processedBytes < (src->mem_size / 2)){
					if (netSize <= 0){
							heapRecv(Client, 2048);
							continue;
					}
					if (strncmp((char*)netBuffer, "EOF", 3) == 0) break;
					memcpy(&streamCache[songPointer + processedBytes], netBuffer, netSize);
					processedBytes = processedBytes + netSize;
					heapRecv(Client, 2048);
				}
				memcpy(src->audiobuf, &streamCache[songPointer], src->mem_size);
				if (songPointer == 0) songPointer = src->mem_size / 2;
				else songPointer = 0;
				src->audio_pointer = src->audio_pointer + src->mem_size;
				
				// Changing endianess if Big Endian
				if (src->big_endian){
					u64 i = 0;
					while (i < src->mem_size){
						u8 tmp = src->audiobuf[i];
						src->audiobuf[i] = src->audiobuf[i+1];
						src->audiobuf[i+1] = tmp;
						i=i+2;	
					}
				}
			
			}
			
			// Check if a block playback is finished
			u32 curSample = ndspChnGetSamplePos(src->ch);
			if (src->lastCheck > curSample){
			
				// Prepare next block
				src->wavebuf = src->wavebuf2;
				src->wavebuf2 = NULL;
			
			}
			
			// Update sample position tick
			src->lastCheck = curSample;
		
		}
	}		
}