예제 #1
0
파일: threads.c 프로젝트: baoson/warfacebot
void threads_init(void)
{
    thread_list = list_new((f_list_cmp) thread_cmp,
                           (f_list_free) thread_free);

    CREATE_THREAD(readstream);
    CREATE_THREAD(sendstream);
    CREATE_THREAD(dispatch);

#if ! defined DBUS_API || defined DEBUG
    CREATE_THREAD(readline);
#endif

    CREATE_THREAD(ping);
}
예제 #2
0
void QueryDNSListenUDPStart(ConfigFileInfo *ConfigInfo)
{
	int _ThreadCount;

	if(Inited == FALSE) return;

	_ThreadCount = ConfigGetInt32(ConfigInfo, "UDPThreads");
	if(_ThreadCount < 1)
	{
		return;
	}

	Threads = SafeMalloc(_ThreadCount * sizeof(ThreadHandle));

	for(; _ThreadCount != 0; --_ThreadCount)
	{
		CREATE_THREAD(QueryDNSListenUDP,
					  (void *)(long)_ThreadCount,
					  Threads[_ThreadCount - 1]
					  );
	}
	INFO("Starting UDP socket %s:%d successfully.\n",
		 ConfigGetRawString(ConfigInfo, "LocalInterface"),
		 ConfigGetInt32(ConfigInfo, "LocalPort")
		 );
}
예제 #3
0
파일: tcp.cpp 프로젝트: webjb/bbb
int s_tcp_t::run()
{
	int       conn_s;
	PRINT_INFO("s_tcp_t::run() ENTER\n");
	while ( !m_quit)
	{
		if( m_is_server )
		{		
			conn_s = accept(m_socket_id, NULL, NULL);
			if( conn_s < 0 )
			{
				if( (errno == EWOULDBLOCK) || (errno == EAGAIN) )// || (conn_s == -1) )
				{
					usleep(1000);
					continue;
				}
				else
				{
					PRINT_ERROR("accept() closed %d\n", errno);					
					break;
				}
			}
			PRINT_INFO("find new client connected\n");
			s_tcp_connection_t * connection;
			connection = new s_tcp_connection_t;
			connection->m_parent = this;
			connection->m_socket_id = conn_s;
			CREATE_THREAD(m_connection_thread, thread_entry, 0x8000, connection, 1);	
		}
	}
	m_quit = 2;
	PRINT_INFO("s_tcp_t::run() EXIT\n");
	return 0;
}
예제 #4
0
void Yodar_4028B::StartHandleThread()
{
	if(m_handleThread == 0)
	{
		m_handleThread = CREATE_THREAD(HandlerProcess, this);
	}
}
예제 #5
0
파일: engine.cpp 프로젝트: dreamsxin/Donut
 	void TEngine::LaunchRendering(const TGraphicsSettings& parContext)
 	{
 		ASSERT_MSG_NO_RELEASE(!FRenderingRunning, "Rendering already launched, it is just paused.");
 		TPipeline* pipeline = GenerateGraphicPipeline(m_scene, parContext.width, parContext.lenght, TPipelineConfig::MINIMAL );
 		FRenderer->CreateRenderWindow(parContext);
 		FRenderer->SetPipeline(pipeline);
 		InitScene();
#if __posix__
 		FThreadData = CREATE_THREAD(FTRenderingThread,CreateRenderingThread,FRenderer);
#elif WIN32
 		CREATE_THREAD(FTRenderingThread,CreateRenderingThread,FRenderer);
#endif
 		ENGINE_INFO("Redering thread created");
 		FRenderingRunning = true;
 		
 	}
예제 #6
0
void Kommunikater::event_connect (irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count)
{
	irc_ctx_t * ctx = (irc_ctx_t *) irc_get_ctx (session);
	irc_cmd_join (session, ctx->channel, 0);

	thread_id_t tid;
	CREATE_THREAD(&tid, myThread, &state);
}
예제 #7
0
파일: engine.cpp 프로젝트: dreamsxin/Donut
 	void TEngine::ResumeRendering()
 	{
 		ASSERT_MSG_NO_RELEASE(FRenderingRunning, "Rendering is not launched.")
 		FRenderer->ShowRenderWindow();
 		FRenderer->SetRendering(true);
 		FThreadData = CREATE_THREAD(FTRenderingThread, CreateRenderingThread, FRenderer);
 		ENGINE_INFO("Rendering resumed");
 	}
예제 #8
0
파일: gfwlist.c 프로젝트: 0rt/dnsforwarder
int GfwList_PeriodicWork(ConfigFileInfo *ConfigInfo)
{
	ThreadHandle gt;

	if( GfwList != NULL )
	{
		CREATE_THREAD(LoadGfwList_Thread, ConfigInfo, gt);
		DETACH_THREAD(gt);
	}

	return 0;
}
예제 #9
0
파일: object.cpp 프로젝트: webjb/bbb
int s_object_t::start()
{
//	PRINT_INFO("xc_ao_t::start\n");

	if( m_quit == 0 )
	{
		PRINT_INFO("started\n");
		return 0;
	}
	m_quit = 0;
    CREATE_THREAD(m_thread, thread_entry, 0x8000, this, 1);         // Reserve 32KB stack
    return 0;
}
예제 #10
0
/*!
 * @brief The entry point into the program.
 */
int main(void)
/*lint -restore Enable MISRA rule (6.3) checking. */
{
	/* Write your local variable definition here */

	/*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
	PE_low_level_init();
	/*** End of Processor Expert internal initialization.                    ***/

	/* Write your code here */
	OS_Init(CPU_CORE_CLK_HZ);

	//Important semaphores. Do it now!
	EventSemaphore = OS_SemaphoreCreate(0);
	InitSemaphore = OS_SemaphoreCreate(1);
	RtcSemaphore = OS_SemaphoreCreate(0);

	//Make some threads.
	CREATE_THREAD(InitThread, NULL, InitThreadStack, TP_INITTHREAD);
	CREATE_THREAD(MainThread, NULL, MainThreadStack, TP_MAINTHREAD);
	CREATE_THREAD(EventThread, NULL, EventThreadStack, TP_EVENTTHREAD);
	CREATE_THREAD(PacketThread, NULL, PacketThreadStack, TP_PACKETTHREAD);
	CREATE_THREAD(RtcThread, NULL, RtcThreadStack, TP_RTCTHREAD);

	//GOGOGOGOOGOGOGO
	OS_Start();

	//We don't go here.

	/*** Don't write any code pass this line, or it will be deleted during code generation. ***/
  /*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/
  #ifdef PEX_RTOS_START
    PEX_RTOS_START();                  /* Startup of the selected RTOS. Macro is defined by the RTOS component. */
  #endif
  /*** End of RTOS startup code.  ***/
  /*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
  for(;;){}
  /*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/
예제 #11
0
static int QueryDNSListenTCP(void *Unused)
{
	static ThreadHandle	Unused2;
	RecvInfo			*Info = NULL;
	CompatibleAddr		*Peer;
	socklen_t			AddrLen;

	while(TRUE){

		Info = SafeMalloc(sizeof(RecvInfo));

		Peer = &(Info -> Peer);
		memset(Info, 0, sizeof(CompatibleAddr));

		if( Family == AF_INET )
		{
			AddrLen = sizeof(struct sockaddr);
			Info -> Socket = accept(ListenSocketTCP, (struct sockaddr *)&(Peer -> Addr4), (socklen_t *)&AddrLen);
		} else {
			AddrLen = sizeof(struct sockaddr_in6);
			Info -> Socket = accept(ListenSocketTCP, (struct sockaddr *)&(Peer -> Addr6), (socklen_t *)&AddrLen);
		}

		if(Info -> Socket == INVALID_SOCKET)
		{
			SafeFree(Info);
			continue;
		}

		SetSocketWait(Info -> Socket, TRUE);
		SetSocketRecvTimeLimit(Info -> Socket, 2000);

		if( Family == AF_INET )
		{
			INFO("Established TCP connection to %s:%d\n", inet_ntoa(Peer -> Addr4.sin_addr), Peer -> Addr4.sin_port);
		} else {
			char Addr[LENGTH_OF_IPV6_ADDRESS_ASCII] = {0};

			IPv6AddressToAsc(&(Peer -> Addr6.sin6_addr), Addr);

			INFO("Established TCP connection to %s:%d\n", Addr, Peer -> Addr6.sin6_port);
		}

		CREATE_THREAD(TCPRecv, (void *)Info, Unused2);
#ifdef WIN32
		CloseHandle(Unused2);
#endif /* WIN32 */
	}
	CLOSE_SOCKET(ListenSocketTCP);
	return 0;
}
예제 #12
0
void QueryDNSListenTCPStart(void)
{
	static ThreadHandle	Unused;

	if(Inited == FALSE)
		return;

	INFO("Starting TCP socket %s:%d successfully.\n", ConfigGetString(&ConfigInfo, "LocalInterface"),
													   ConfigGetInt32(&ConfigInfo, "LocalPort")
													   );
	CREATE_THREAD(QueryDNSListenTCP, NULL, Unused);
#ifdef WIN32
	CloseHandle(Unused);
#endif /* WIN32 */
}
예제 #13
0
	TESTCASE() {

		MAX_WAIT_TIME(3*USECSPERSEC);

		for (int i = 0; i < NUM_THREADS; i++)
		{
			CREATE_THREAD(i+1, increment_routine, (void*)counter);
		}

		//-----------------------------------------

		printf("counter->x: %lx\n", &counter->x);
		printf("counter->lock: %lx\n", &counter->mutex);

		EXISTS(t1, PTRUE, "Select thread t1");
		EXISTS(t2, NOT(t1), "Select thread t2");
//
		RUN_UNTIL(BY(t1), ENDS(), __, "Reads from x");
//
//		RUN_UNTIL(NOT_BY(t1), WRITES(&counter->x, t2), __, "Writes to x");
//
//		RUN_UNTIL(PTRUE, ENDS(t1), __, "Ends...");


//		WHILE_STAR
//		{
//			FORALL(t, (TID == t1 || TID == t2), "Select thread t");
//			RUN_UNTIL(BY(t), ENDS(), __, "Run until ends");
//		}



//			FORALL(t, PTRUE, "Select thread t");
//			RUN_UNTIL(BY(t), ENDS(), __, "Run until ends");



//			FORALL(t, PTRUE, "Select thread t");
//			RUN_UNTIL(BY(t), PTRUE, __, "Run until ends");
//		}

	}
예제 #14
0
파일: main.c 프로젝트: yogpstop/MyGCCProj
int main(int argc, char **argv) {
	int i;
	buf_str ctx;
	memset(&ctx, 0, sizeof(buf_str));
	ctx.p.period = PERIOD_SIZE;
	ctx.p.buf_max = 0xFFF;//TODO variable buf
	ctx.p.mutex = malloc(sizeof(MUTEX_T) * (ctx.p.buf_max + 1));
	for (i = 0; i <= ctx.p.buf_max; i++) {
		MUTEX_INIT(ctx.p.mutex + i);
	}
	ctx.p.update = malloc(sizeof(unsigned char) * (ctx.p.buf_max + 1));
	memset(ctx.p.update, 0, sizeof(unsigned char) * (ctx.p.buf_max + 1));
	ctx.p.buf = malloc((ctx.p.buf_max + 1) * ctx.p.period * CHANNELS * BITS / 8);
	//FIXME memory allocation failed
	ctx.list = listing(argv + 1);
	if(!ctx.list) force_exit_signal = 1;
	else list_shuffle(ctx.list);
	THREAD_T play, buffer;
#ifndef _WIN32
	pthread_attr_t rt;
	struct sched_param p = {};
	p.sched_priority = sched_get_priority_max(SCHED_RR);
	pthread_attr_init(&rt);
	pthread_attr_setinheritsched(&rt, PTHREAD_EXPLICIT_SCHED);
	pthread_attr_setschedpolicy(&rt, SCHED_RR);
	pthread_attr_setschedparam(&rt, &p);
#endif
	CREATE_THREAD(buffer, buffer_thread, &ctx);
	CREATE_THREAD_RT(play, play_thread, &ctx.p, &rt);
	console();
	JOIN_THREAD(buffer);
	JOIN_THREAD(play);
	list_full_remove(ctx.list);
	for (i = 0; i <= ctx.p.buf_max; i++) {
		MUTEX_DESTROY(ctx.p.mutex + i);
	}
	free(ctx.p.mutex);
	free(ctx.p.update);
	free(ctx.p.buf);
	return 0;
}
예제 #15
0
파일: app.cpp 프로젝트: webjb/bbb
s_app_t::s_app_t()
{
	m_msg = s_message_t::get_inst();

	m_wheel = s_wheel_t::get_inst();
	m_eye = s_eye_t::get_inst();
	m_arm = s_arm_t::get_inst();
	m_drive_player = s_drive_player_t::get_inst();
	
	m_msg_player = s_massage_player_t::get_inst();
	
	m_soccer_player = s_soccer_player_t::get_inst();
		
    CREATE_THREAD(m_keyboard_thread, thread_keyboard_entry, 0x8000, this, 1);         // Reserve 32KB stack

	m_last_ms = 0;
	m_run_state = S_RUN_STATE_NOTHING;

	m_exit = 0;
	
	m_msg->start();
	m_wheel->start();
}
예제 #16
0
TESTCASE() {

    ThreadVarPtr t_ip1 = CREATE_THREAD(insertpair_routine1, (void*)&multiset);
    ThreadVarPtr t_ip2 = CREATE_THREAD(insertpair_routine2, (void*)&multiset);
    ThreadVarPtr t_ip3 = CREATE_THREAD(insertpair_routine3, (void*)&multiset);

    ThreadVarPtr t_lu1 = CREATE_THREAD(lookup_routine1, (void*)&multiset);
    ThreadVarPtr t_lu2 = CREATE_THREAD(lookup_routine2, (void*)&multiset);
    ThreadVarPtr t_lu3 = CREATE_THREAD(lookup_routine3, (void*)&multiset);

    printf("=============================================\n"
           "=============================================\n");

    //----------------------------------------------------------------------------------
    //----------------------------------------------------------------------------------

    FORALL(t1, BY(t_ip1) || BY(t_ip2) || BY(t_ip3));
    RUN_UNTIL(BY(t1), ENDS(), __);

    FORALL(t2, (BY(t_ip1) || BY(t_ip2) || BY(t_ip3)) && NOT(t1));
    RUN_UNTIL(BY(t2), ENDS(), __);

    FORALL(t3, (BY(t_ip1) || BY(t_ip2) || BY(t_ip3)) && NOT(t1) && NOT(t2));
    RUN_UNTIL(BY(t3), ENDS(), __);

    RUN_UNTIL(BY(t_lu2), ENDS(), __);
    RUN_UNTIL(BY(t_lu1), ENDS(), __);
    RUN_UNTIL(BY(t_lu3), ENDS(), __);

    WHILE_STAR
    {
        EXISTS(t);
        RUN_UNTIL(PTRUE && !FINAL(), FINAL(t))

    }
    RUN_UNTIL(PTRUE, FINAL())
}
예제 #17
0
void Toggle_AssumeControl()
{
	OS_ERROR error = CREATE_THREAD(ToggleThread, NULL, ToggleThreadStack, TP_MODETHREAD);
}