示例#1
0
文件: uaenet.c 项目: Yamakuzure/PUAE
void uaenet_close (struct uaenetdata *sd)
{
	if (!sd)
		return;
	if (sd->threadactiver) {
		sd->threadactiver = -1;
	}
	if (sd->threadactivew) {
		sd->threadactivew = -1;
// REMOVEME: win32 specific
//		SetEvent (sd->evttw);
	}
	if (sd->threadactiver) {
		while (sd->threadactiver)
			sleep_millis(10);
		write_log ("uaenet_ thread %d killed\n", sd->tidr);
		uae_kill_thread (&sd->tidr);
	}
	if (sd->threadactivew) {
		while (sd->threadactivew)
			sleep_millis(10);
// REMOVEME: win32 specific
//		CloseHandle (sd->evttw);
		write_log ("uaenet thread %d killed\n", sd->tidw);
		uae_kill_thread (&sd->tidw);
	}
	xfree (sd->readbuffer);
	xfree (sd->writebuffer);
	if (sd->fp)
		pcap_close (sd->fp);
	uaeser_initdata (sd, sd->user);
	write_log ("uaenet_win32 closed\n");
}
示例#2
0
/*
 * Sleep for ms milliseconds if and only busy-waiting would not be required
 * to do so.
 */
void sleep_millis_busy (int ms)
{
#ifndef SLEEP_DONT_BUSY_WAIT
    if (currprefs.dont_busy_wait || ms >= SLEEP_BUSY_THRESHOLD)
#endif
	sleep_millis (ms);
}
示例#3
0
文件: video.cpp 项目: eehrich/fs-uae
bool render_screen(bool immediate)
{
    bool v = false;
    int cnt;

    render_ok = false;
    if (minimized || picasso_on || monitor_off || dx_islost ())
            return render_ok;
    cnt = 0;
    while (wait_render) {
            sleep_millis (1);
            cnt++;
            if (cnt > 500)
                    return render_ok;
    }
#if 0
    flushymin = 0;
    flushymax = currentmode->amiga_height;
    //EnterCriticalSection (&screen_cs);
    if (currentmode->flags & DM_D3D) {
            v = D3D_renderframe (immediate);
#endif
    v = render_frame(immediate);
#if 0
    } else if (currentmode->flags & DM_SWSCALE) {
            S2X_render ();
            v = true;
    } else if (currentmode->flags & DM_DDRAW) {
            v = true;
    }
#endif
    render_ok = v;
    //LeaveCriticalSection (&screen_cs);
    return render_ok;
}
示例#4
0
文件: ppc.cpp 项目: adurdin/fs-uae
// sleep until interrupt (or PPC stopped)
void uae_ppc_doze(void)
{
	//TRACE(_T("uae_ppc_doze\n"));
	if (!ppc_thread_running)
		return;
	ppc_state = PPC_STATE_SLEEP;
	while (ppc_state == PPC_STATE_SLEEP) {
		sleep_millis(2);
	}
}
示例#5
0
void graphics_thread_leave(void)
{
	if(display_tid != 0) {
	  write_comm_pipe_u32 (display_pipe, DISPLAY_SIGNAL_QUIT, 1);
	  while(display_tid != 0) {
	    sleep_millis(10);
	  }
	  destroy_comm_pipe(display_pipe);
	  xfree(display_pipe);
	  display_pipe = 0;
	  uae_sem_destroy(&display_sem);
	  display_sem = 0;
	}
}
示例#6
0
文件: traps.cpp 项目: Blonder/WinUAE
TrapContext *alloc_host_main_trap_context(void)
{
	if (trap_is_indirect()) {
		int trap_slot = RTAREA_TRAP_DATA_NUM;
		if (atomic_inc(&outtrap_alloc[trap_slot - RTAREA_TRAP_DATA_NUM])) {
			while (outtrap_alloc[trap_slot - RTAREA_TRAP_DATA_NUM] > RTAREA_TRAP_DATA_SEND_NUM)
				sleep_millis(1);
		}
		TrapContext *ctx = &outtrap[trap_slot - RTAREA_TRAP_DATA_NUM];
		ctx->trap_slot = trap_slot;
		return ctx;
	} else {
		return NULL;
	}
}
示例#7
0
文件: traps.cpp 项目: Blonder/WinUAE
void free_traps(void)
{
	for (int i = 0; i < TRAP_THREADS; i++) {
		if (trap_thread_id[i]) {
			if (hardware_trap_kill[i] >= 0) {
				hardware_trap_kill[i] = 0;
				write_comm_pipe_pvoid(&trap_thread_pipe[i], NULL, 1);
				while (hardware_trap_kill[i] == 0) {
					sleep_millis(1);
				}
			}
			destroy_comm_pipe(&trap_thread_pipe[i]);
			uae_end_thread(&trap_thread_id[i]);
			trap_thread_id[i] = NULL;
		}
	}
}
示例#8
0
static void *slirp_receive_func(void *arg)
{
	slirp_thread_active = 1;
	while (slirp_thread_active) {
		// Wait for packets to arrive
		fd_set rfds, wfds, xfds;
		int nfds;
		int ret, timeout;

		// ... in the output queue
		nfds = -1;
		FD_ZERO(&rfds);
		FD_ZERO(&wfds);
		FD_ZERO(&xfds);
		uae_sem_wait (&slirp_sem2);
		timeout = slirp_select_fill(&nfds, &rfds, &wfds, &xfds);
		uae_sem_post (&slirp_sem2);
		if (nfds < 0) {
			/* Windows does not honour the timeout if there is not
			   descriptor to wait for */
			sleep_millis (timeout / 1000);
			ret = 0;
		} else {
			struct timeval tv;
			tv.tv_sec = 0;
			tv.tv_usec = timeout;
			ret = select(0, &rfds, &wfds, &xfds, &tv);
			if (ret == SOCKET_ERROR) {
				write_log(_T("SLIRP socket ERR=%d\n"), WSAGetLastError());
			}
		}
		if (ret >= 0) {
			uae_sem_wait (&slirp_sem2);
			slirp_select_poll(&rfds, &wfds, &xfds);
			uae_sem_post (&slirp_sem2);
		}
	}
	slirp_thread_active = -1;
	return 0;
}
示例#9
0
void uae_slirp_end (void)
{
#ifdef WITH_QEMU_SLIRP
	if (impl == QEMU_IMPLEMENTATION) {
		UAE_LOG_STUB("");
		return;
	}
#endif
#ifdef WITH_BUILTIN_SLIRP
	if (impl == BUILTIN_IMPLEMENTATION) {
		if (slirp_thread_active > 0) {
			slirp_thread_active = 0;
			while (slirp_thread_active == 0) {
				sleep_millis (10);
			}
			uae_end_thread (&slirp_tid);
		}
		slirp_thread_active = 0;
		return;
	}
#endif
}
示例#10
0
文件: enforcer.cpp 项目: engur/fs-uae
/*************************************************************
Display the enforcer hit
*************************************************************/
static void enforcer_display_hit (const TCHAR *addressmode, uae_u32 pc, uaecptr addr)
{
	uae_u32 a7;
	uae_u32 sysbase;
	uae_u32 this_task;
	uae_u32 task_name;
	TCHAR *native_task_name = NULL;
	int i, j;
	static TCHAR buf[256],instrcode[256];
	static TCHAR lines[INSTRUCTIONLINES/2][256];
	static uaecptr bestpc_array[INSTRUCTIONLINES/2][5];
	static int bestpc_idxs[INSTRUCTIONLINES/2];
	TCHAR *enforcer_buf_ptr = enforcer_buf;
	uaecptr bestpc, pospc, nextpc, temppc;

	if (enforcer_hit)
		return; /* our function itself generated a hit ;), avoid endless loop */
	if (regs.vbr < 0x100 && addr >= 0x0c && addr < 0x80)
		return;

	enforcer_hit = 1;

	sysbase = get_long (4);
	if (sysbase < 0x100 || !valid_address (sysbase, 1000))
		goto end;
	this_task = get_long (sysbase + 276);
	if (this_task < 0x100 || !valid_address (this_task, 1000))
		goto end;

	task_name = get_long (this_task + 10); /* ln_Name */
	native_task_name = au ((char*)amiga2native (task_name, 100));
	/*if (strcmp(native_task_name,"c:MCP")!=0)
	{
	Exception (0x2d,0);
	}*/
	_tcscpy (enforcer_buf_ptr, _T("Enforcer Hit! Bad program\n"));
	enforcer_buf_ptr += _tcslen (enforcer_buf_ptr);

	_stprintf (buf, _T("Illegal %s: %08x"), addressmode, addr);
	_stprintf (enforcer_buf_ptr, _T("%-48sPC: %08x\n"), buf, pc);
	enforcer_buf_ptr += _tcslen (enforcer_buf_ptr);

	/* Data registers */
	_stprintf (enforcer_buf_ptr, _T("Data: %08x %08x %08x %08x %08x %08x %08x %08x\n"),
		m68k_dreg (regs, 0), m68k_dreg (regs, 1), m68k_dreg (regs, 2), m68k_dreg (regs, 3),
		m68k_dreg (regs, 4), m68k_dreg (regs, 5), m68k_dreg (regs, 6), m68k_dreg (regs, 7));
	enforcer_buf_ptr += _tcslen (enforcer_buf_ptr);

	/* Address registers */
	_stprintf (enforcer_buf_ptr, _T("Addr: %08x %08x %08x %08x %08x %08x %08x %08x\n"),
		m68k_areg (regs, 0), m68k_areg (regs, 1), m68k_areg (regs, 2), m68k_areg (regs, 3),
		m68k_areg (regs, 4), m68k_areg (regs, 5), m68k_areg (regs, 6), m68k_areg (regs, 7));
	enforcer_buf_ptr += _tcslen (enforcer_buf_ptr);

	/* Stack */
	a7 = m68k_areg (regs, 7);
	for (i = 0; i < 8 * STACKLINES; i++) {
		a7 += 4;
		if (!(i % 8)) {
			_tcscpy (enforcer_buf_ptr, _T("Stck:"));
			enforcer_buf_ptr += _tcslen (enforcer_buf_ptr);
		}
		_stprintf (enforcer_buf_ptr, _T(" %08x"),get_long (a7));
		enforcer_buf_ptr += _tcslen (enforcer_buf_ptr);

		if (i%8 == 7)
			*enforcer_buf_ptr++ = '\n';
	}

	/* Segtracker output */
	if (enforcer_decode_hunk_and_offset (buf, pc)) {
		_tcscpy (enforcer_buf_ptr, buf);
		enforcer_buf_ptr += _tcslen (enforcer_buf_ptr);
	}

	uae_u32 oldaddrs[BACKTRACELONGS];
	a7 = m68k_areg (regs, 7);
	for (i = 0; i < BACKTRACELONGS; i++) {
		uae_u32 addr;
		a7 += 4;
		addr = get_long (a7);
		for (j = 0; j < i; j++) {
			if (oldaddrs[j] == addr)
				break;
		}
		oldaddrs[i] = addr;
		if (j == i && addr != pc) {
			if (enforcer_decode_hunk_and_offset (buf, addr)) {
				int l = _tcslen (buf);

				if (ENFORCER_BUF_SIZE - (enforcer_buf_ptr - enforcer_buf) > l + 256) {
					_tcscpy (enforcer_buf_ptr, buf);
					enforcer_buf_ptr += l;
				}
			}
		}
	}

	/* Decode the instructions around the pc where the enforcer hit was caused.
	*
	* At first, the area before the pc, this not always done correctly because
	* it's done backwards */
	temppc = pc;

	memset (bestpc_array, 0, sizeof (bestpc_array));
	for (i = 0; i < INSTRUCTIONLINES / 2; i++)
		bestpc_idxs[i] = -1;

	for (i = 0; i < INSTRUCTIONLINES / 2; i++) {
		pospc = temppc;
		bestpc = 0;

		if (bestpc_idxs[i] == -1) {
			for (j = 0; j < 5; j++) {
				pospc -= 2;
				sm68k_disasm (buf, NULL, pospc, &nextpc);
				if (nextpc == temppc) {
					bestpc_idxs[i] = j;
					bestpc_array[i][j] = bestpc = pospc;
				}
			}
		} else {
			bestpc = bestpc_array[i][bestpc_idxs[i]];
		}

		if (!bestpc) {
			/* there was no best pc found, so it is high probable that
			* a former used best pc was wrong.
			*
			* We trace back and use the former best pc instead
			*/

			int former_idx;
			int leave = 0;

			do {
				if (!i) {
					leave = 1;
					break;
				}
				i--;
				former_idx = bestpc_idxs[i];
				bestpc_idxs[i] = -1;
				bestpc_array[i][former_idx] = 0;

				for (j = former_idx - 1; j >= 0; j--) {
					if (bestpc_array[i][j]) {
						bestpc_idxs[i] = j;
						break;
					}
				}
			} while (bestpc_idxs[i] == -1);
			if (leave)
				break;
			if (i)
				temppc = bestpc_array[i-1][bestpc_idxs[i-1]];
			else
				temppc = pc;
			i--; /* will be increased in after continue */
			continue;
		}

		sm68k_disasm (buf, instrcode, bestpc, NULL);
		_stprintf (lines[i], _T("%08x :   %-20s %s\n"), bestpc, instrcode, buf);
		temppc = bestpc;
	}

	i--;
	for (; i >= 0; i--) {
		_tcscpy (enforcer_buf_ptr, lines[i]);
		enforcer_buf_ptr += _tcslen (enforcer_buf_ptr);
	}

	/* Now the instruction after the pc including the pc */
	temppc = pc;
	for (i = 0; i < (INSTRUCTIONLINES + 1) / 2; i++) {
		sm68k_disasm (buf, instrcode, temppc, &nextpc);
		_stprintf (enforcer_buf_ptr, _T("%08x : %s %-20s %s\n"), temppc,
			(i == 0 ? _T("*") : _T(" ")), instrcode, buf);
		enforcer_buf_ptr += _tcslen (enforcer_buf_ptr);
		temppc = nextpc;
	}

	if (!native_task_name)
		native_task_name = my_strdup(_T("Unknown"));
	_stprintf (enforcer_buf_ptr, _T("Name: \"%s\"\n\n"), native_task_name);
	enforcer_buf_ptr += _tcslen (enforcer_buf_ptr);

	console_out (enforcer_buf);
	write_log (_T("%s"), enforcer_buf);
	if (!debug_enforcer()) {
		sleep_millis (5);
		doflashscreen ();
	}

end:
	xfree (native_task_name);
	enforcer_hit = 0;
}
示例#11
0
bool vsync_busywait_do (int *freetime, bool lace, bool oddeven)
{
	bool v;
	static bool framelost;
	int ti;
	frame_time_t t;
	frame_time_t prevtime = vblank_prev_time;
	struct apmode *ap = picasso_on ? &currprefs.gfx_apmode[1] : &currprefs.gfx_apmode[0];

	t = read_processor_time ();
	ti = t - prevtime;
	if (ti) {
		waitvblankstate (false, NULL, NULL);
		vblank_prev_time = t;

		return true;
	}

	if (freetime)
		*freetime = 0;
	v = 0;

	if (isthreadedvsync ()) {

		framelost = false;
		v = 1;

	} else {
		int vp;

		if (currprefs.turbo_emulation) {
			show_screen (0);
			vblank_prev_time = read_processor_time ();
			framelost = true;
			v = -1;

		} else {
			while (!framelost && read_processor_time () - prevtime < 0) {
				vsync_sleep (false);
			}
			vp = vblank_wait ();
			if (vp >= -1) {
				vblank_prev_time = read_processor_time ();
				if (ap->gfx_vflip == 0) {
					show_screen (0);
				}
				for (;;) {
					if (!getvblankpos (&vp))
						break;
					if (vp > 0)
						break;
					sleep_millis (1);
				}
				if (ap->gfx_vflip != 0) {
					show_screen (0);
				}
				v = framelost ? -1 : 1;
			}

			framelost = false;
		}
		getvblankpos (&vp);
	}

		return v;
	}
示例#12
0
文件: eigrp_ip6.c 项目: dervel/eigrp
void *send_ipv6_packets( void *ptr){
	struct eigrp_proccess *proc;
	neighbour *n;
	//long long current_time;
	struct sockaddr_in sin;
	bool cr = false; //Indicates if cr flag should be set on a multicast packet.
	int flags = 0; //Flag the multicast packet will have
	int seq_len=0; //The actual length we used from the hole buffer

	proc = (struct eigrp_proccess *)ptr;

	while(proc->running){
		sleep_millis(100);

		if(linkedlist_isempty(&proc->multicast_queue)){
			//Send any pending packets from neighbour queue
			hash_collection col;
			prepare_hashcollection(&col,proc->neighbours);
			while( (n = next(&col)) != NULL){
				send_packets_neighbour_ip6(n);
			}

		}else{
			printf("Sending multicast Packet.\n");
			//Send the next multicast packet

			int seq_num = proc->seq_num++; // Get the seq number now cause we might need it for the seq_tlv packet

			//If we have pending ack send the sequence tlv 		
			if(!packet_queues_empty(proc)){
				cr = true;
				
				//Build the sequence tlv
				void *seq_tlv=malloc(PACKET_LENGTH); //We will write the tlv in this buffer and then copy it into the packet
				seq_len = fill_sequence_tlv(seq_tlv, proc);
				//Create the packet
				packetv4_param *seq_packet = create_empty_packet(OPCODE_HELLO, 0 , sin);
				addtlv(seq_packet,seq_tlv,seq_len);
				struct tlv_next_multicast next_mul;
				next_mul.type = htons(0x0005);
				next_mul.length = htons(8);
				next_mul.seq_num = htonl(seq_num);
				addtlv(seq_packet,&next_mul,8);
				create_eigrp_header(seq_packet, seq_packet->buffer_len, seq_packet->opcode, proc->proccess_id, 0, 0, 0);
				send_ip4_packet_multicast(seq_packet,proc);
				//Record packets sent
				proc->stats.packets_sent[seq_packet->opcode]++;
				free(seq_tlv);
				free(seq_packet);
	
			}

			packetv4_param *packet = linkedlist_getfirst(&proc->multicast_queue);
			//int length = sizeof(struct eigrphdr);
			//char* buffer = malloc(length);

			if(cr) flags |= FLAG_CR;
			create_eigrp_header(packet, packet->buffer_len, packet->opcode, proc->proccess_id, seq_num, 0, flags);
			queue_sended_multicast_packet(proc, packet,seq_num);
			send_ip4_packet_multicast(packet,proc);
			//Record packets sent
			proc->stats.packets_sent[packet->opcode]++;
			printf("Done sending multicast packet.\n");
		}
	}

	return NULL;
}