Example #1
0
static void Quit(void)
{
	// Exit PowerPC emulation
	exit_emul_ppc();

	// Stop 60Hz thread
	if (tick_thread_active) {
		tick_thread_cancel = true;
		wait_thread(tick_thread);
	}

	// Stop NVRAM watchdog thread
	if (nvram_thread_active) {
		nvram_thread_cancel = true;
		wait_thread(nvram_thread);
	}

	// Deinitialize everything
	ExitAll();

	// Delete SheepShaver globals
	SheepMem::Exit();

	// Delete RAM area
	if (ram_area_mapped)
		vm_mac_release(RAMBase, RAMSize);

	// Delete ROM area
	if (rom_area_mapped)
		vm_mac_release(ROMBase, ROM_AREA_SIZE);

	// Delete DR cache areas
	if (dr_emulator_area_mapped)
		vm_mac_release(DR_EMULATOR_BASE, DR_EMULATOR_SIZE);
	if (dr_cache_area_mapped)
		vm_mac_release(DR_CACHE_BASE, DR_CACHE_SIZE);

	// Delete Kernel Data area
	kernel_data_exit();

	// Exit system routines
	SysExit();

	// Exit preferences
	PrefsExit();

	// Release win32 libraries
	KernelExit();

#ifdef ENABLE_MON
	// Exit mon
	mon_exit();
#endif

	exit(0);
}
Example #2
0
int main(void)
{
	int i;
	pthread_t thread;
	pthread_t thread1;

	if (pthread_create(&thread, NULL, thread_func, NULL) != 0)
	{
		return EXIT_FAILURE;
	}
	if (pthread_create(&thread1, NULL, thread_func, NULL) != 0)
	{
		return EXIT_FAILURE;
	}
	for (i = 0; i < 20; i++)
	{
		puts("a");
		wait_thread();
	}

	if (pthread_join(thread, NULL) != 0)
	{
		return EXIT_FAILURE;
	}

	return EXIT_SUCCESS;
}
Example #3
0
int attach_thread(int tid)
{
    if (ptrace(PTRACE_ATTACH, tid, NULL, NULL) < 0) {
        perror("PTRACE_ATTACH");
        return -1;
    }
    if (wait_thread(tid) < 0)
        return -1;
    return 0;
}
Example #4
0
static void *thread_func(void *vptr_args)
{
    int i;
 
    for (i = 0; i < 20; i++)
    {
        fputs("  b\n", stderr);
        wait_thread();
    }
 
    return NULL;
}
Example #5
0
void call_wait_thread(void *context)
{
  SshThread thread = context;
  D(("C: Call_wait_thread called, number of threads now out %d, thread = %p\n",
     threads, thread));
  D(("C: Waiting for thread\n"));
  wait_thread(thread);
  threads--;
  D(("C: Waited for thread, decrementing threads counter, new value = %d\n",
     threads));
  if (threads == 0)
    ssh_xregister_timeout(0, 0, check_for_threads, NULL);
}
Example #6
0
static struct kernel_dispatch_info *prepare_thread(struct kernel_dispatch_info *disp_info)
{
    // Put the thread to wait
    int is_in_wait = wait_thread(disp_info->thread);
    assert(is_in_wait);
    
    // Duplicate dispatch info
    struct kernel_dispatch_info *dup_disp_info = salloc(kernel_dispatch_salloc_id);
    assert(dup_disp_info);
    memcpy(disp_info, dup_disp_info, sizeof(struct kernel_dispatch_info));
    
    return dup_disp_info;
}
Example #7
0
int main()
{
	//int fd = 0;
	char buffer[BUFFER_SIEZE] = {0};

	if((fd = Open_Port(HOST_PORT)) == -1)
	{
		perror("Open port");
		return -1;
	}
	
	if( Set_Port(fd,9600,8,'N',1) == -1)
	{
		perror("Set_Port");
		return -1;
	}
	
	//Serial_SendStr(fd,"Hello This is from Ubuntu\n");

	pthread_mutex_init(&mut,NULL);
	
	while(1)
	{
		time(&now);
		tm_now = localtime(&now);
		datetime=asctime(tm_now);
		
		create_thread();
        wait_thread();
		if( IsReceve ==1)
        {
	        printf("\n%sInput the Send Message:\n",datetime);
       memset(buffer,0,BUFFER_SIEZE);
        if(fgets(buffer,BUFFER_SIEZE,stdin) == NULL)//get input chars
        {
			perror("Fgets");
			break;
		}
		write(fd,buffer,strlen(buffer));//send chars		
			IsReceve = 0;
			
		}
        

	}
	
	close(fd);
	
	return 0;
 
}
Example #8
0
int main(int argc, char **argv)
{
	pthread_t tid;
	int opt;

	sem_init(&main_sem, 0, 0);
	sem_init(&thread_sem, 0, 0);
	while ((opt = getopt(argc, argv, "hs:d:")) != -1) {
		switch (opt){
		case 'h':
			usage();
			exit(0);
		case 'l':
			local = 1;
			break;
		case 's':
			sport = atoi(optarg);
		case 'd':
			dport = atoi(optarg);
			break;
		default:
			usage();
			exit(0);
		}
	}
	if (optind != (argc - 1)) {
		usage();
		exit(0);
	}
	dst = argv[optind];
	/* prepare local for libpcap */
	if (strcmp(dst, "127.0.0.1") == 0 || strcmp(src, dst) == 0)
		local = 1;

	signal(SIGALRM, sigalrm);
	alarm(10);
	pthread_create(&tid, NULL, pcap_thread, NULL);

	/* wait init ack num */
	while (tcp_seq == 0) {
		wait_thread();
	}

	/* when do_send OK, wait analyse */
	do_send();
	tell_thread();

	pthread_join(tid, NULL);
	exit(0);
}
Example #9
0
//-----------------------------------------------------------------------------
//used in application frame update (idle) to update new data -- virtual function
//get data and update dataDims|Origin progresively until all data is updated
//for data distribution: DL_CHUNK
//and load mode:  DL_BLOCKING or DL_THREAD
//-----------------------------------------------------------------------------
bool CDataLoader::update_data()
{
    //fprintf(stderr, "**** %s:%s() ****\n", __FILE__, __func__);

    if(m_cid >= m_chunkNum[0]*m_chunkNum[1]*m_chunkNum[2]) return false;

    assert(m_dataDist == DL_CHUNK);

    switch(m_dataLoadmode)
    {
    case DL_BLOCKING: loaddata_chunk(m_cid); break;
    case DL_THREAD:  wait_thread(m_cid); break;
    default: m_data = 0;
    }
    
    m_cid++;
    return true;
}
Example #10
0
int main(int argc, char *argv[])
{
    int threads = 8;

    if (argc > 1)
        threads = atoi(argv[1]);
    if (threads > MAX_THREADS)
        threads = MAX_THREADS;

    printf("Testing with %d threads\n", threads);

    for (int i = 0; i < threads; i++) {
        launch_thread(i);
    }

    for (int i = 0; i < threads; i++) {
        wait_thread(i);
    }

    return 0;
}
Example #11
0
int thread_wait(int tid,int timeout){
	int rcode;
	int nmask,smask;
	if( ThreadWait ){
		thwait++;
		if( lTHREADLOG() ){
			syslog_ERROR("thread_wait(%X %d)\n",tid,timeout);
		}
		if( !isWindows() && 0 < timeout ){
			if( thread_wait_timeout(tid,timeout) < 0 ){
				thwaitTimeout++;
				return -1;
			}
		}
		if( wait_thread(tid,timeout) < 0 )
		{
			thwaitWaiterr++;
			return -1;
		}
		nmask = sigmask(SIGINT)|sigmask(SIGTERM)|sigmask(SIGPIPE);
		nmask |= sigmask(SIGHUP);
		smask = sigblock(nmask);
		rcode = (*ThreadWait)(tid,timeout);
		if( rcode == 0 ){
			ActiveThreads--;
			putpplog("actthreads()--=%d [%X]\n",ActiveThreads,tid);
		}
		else{
			thwaitCodeerr++;
		}
		sigsetmask(smask);
		return rcode;
		/*
		return (*ThreadWait)(tid,timeout);
		*/
	}
	return -1;
}
Example #12
0
void		draw_set(t_image *img, t_frac *f)
{
	t_data_thread		dt;
	pthread_t			draw_threads[NUM_THREADS];
	int					i;
	int					starts[NUM_THREADS];
	int					ends[NUM_THREADS];

	init_starts_ends(starts, ends);
	i = 0;
	dt.img = img;
	dt.f = f;
	pthread_mutex_init(&dt.frac_mutex, NULL);
	while (i < NUM_THREADS)
	{
		dt.start = starts[i];
		dt.f->p.x = dt.start;
		dt.end = ends[i];
		launch_thread(&draw_threads[i], draw_worker, &dt);
		wait_thread(draw_threads[i]);
		i++;
	}
	pthread_mutex_destroy(&dt.frac_mutex);
}
Example #13
0
void TestThisThread()
{
  hadesmem::Thread thread(::GetCurrentThreadId());
  BOOST_TEST_EQ(thread, thread);
  hadesmem::Thread thread_new(::GetCurrentThreadId());
  BOOST_TEST_EQ(thread, thread_new);
  hadesmem::Thread const thread_moved(std::move(thread_new));
  hadesmem::Thread thread_copy(thread);
  BOOST_TEST_EQ(thread_copy, thread);
  thread = thread_copy;
  BOOST_TEST_EQ(thread, thread_copy);
  thread_new = std::move(thread_copy);
  BOOST_TEST_EQ(thread, thread_new);
  BOOST_TEST(thread >= thread);
  BOOST_TEST(thread <= thread);
  BOOST_TEST_EQ(thread.GetId(), ::GetCurrentThreadId());
  std::stringstream thread_str_1;
  thread_str_1.imbue(std::locale::classic());
  thread_str_1 << thread;
  DWORD thread_id_1;
  thread_str_1 >> thread_id_1;
  BOOST_TEST_EQ(thread.GetId(), thread_id_1);
  std::wstringstream thread_str_2;
  thread_str_2.imbue(std::locale::classic());
  thread_str_2 << thread;
  DWORD thread_id_2;
  thread_str_2 >> thread_id_2;
  BOOST_TEST_EQ(thread.GetId(), thread_id_2);

  hadesmem::detail::SmartHandle quit_event(
    ::CreateEvent(nullptr, TRUE, FALSE, nullptr));
  DWORD other_id = 0;
  hadesmem::detail::SmartHandle wait_thread(
    ::CreateThread(nullptr, 0, &WaitFunc, &quit_event, 0, &other_id));
  // Disgusting hack to work around a potential race condition where we suspend
  // the thread before it's actually waiting on our event, and instead it's
  // still in its initialization routine and ends up holding a lock that the
  // main thread will need (e.g. from malloc). See thread_140224_144550.dmp.
  ::Sleep(5 * 1000);
  auto const cleanup_thread_func = [&]()
  {

    BOOST_TEST_NE(::SetEvent(quit_event.GetHandle()), 0);
    BOOST_TEST_EQ(::WaitForSingleObject(wait_thread.GetHandle(), INFINITE),
                  WAIT_OBJECT_0);
  };
  {
    ScopeExit<decltype(cleanup_thread_func)> cleanup_thread(
      cleanup_thread_func);

    hadesmem::Thread const other_thread(other_id);
    BOOST_TEST_EQ(hadesmem::SuspendThread(other_thread), 0UL);
    BOOST_TEST_EQ(hadesmem::SuspendThread(other_thread), 1UL);
    BOOST_TEST_EQ(hadesmem::ResumeThread(other_thread), 2UL);
    BOOST_TEST_EQ(hadesmem::ResumeThread(other_thread), 1UL);

    {
      hadesmem::SuspendedThread const suspend_thread(other_thread.GetId());

      CONTEXT const full_context =
        hadesmem::GetThreadContext(other_thread, CONTEXT_FULL);
      CONTEXT const all_context =
        hadesmem::GetThreadContext(other_thread, CONTEXT_ALL);
      hadesmem::SetThreadContext(other_thread, full_context);
      hadesmem::SetThreadContext(other_thread, all_context);
      BOOST_TEST_THROWS(hadesmem::GetThreadContext(thread, CONTEXT_FULL),
                        hadesmem::Error);
    }

    {
      hadesmem::SuspendedProcess const suspend_process(::GetCurrentProcessId());
    }
  }
}
Example #14
0
int
sys_wait_thread(void)
{
  return wait_thread();
}