Esempio n. 1
0
int main()
{
    int i;
	/* Initialization Part */
	DosInit();
	TcbInitAll();
    /*TODO*/
    BufInitAll();
  
	/* Get access to the entry address of clock intrrupt */
	old_int8 = getvect(8);

    
    clrscr();
    
    tcbs[0].state = RUNNING;
    current = 0;    /* current thread */


    ThreadCreate(sndThdName,(codeptr)Sender,STACK_SIZE);
	ThreadCreate(recvThdName,(codeptr)Receiver,STACK_SIZE);
	
        
    setvect(8, new_int8);
    my_swtch();

    TcbState();
    while(!ThreadFinished());

    TcbState();
    setvect(8, old_int8); /* Recover old clock interrupt */

    ThreadDestory(0);
    return 0;
}
int main()
{
  ThreadCreate(print2, '1');
  ThreadCreate(print2, '2');
  ThreadCreate(print2, '3');

  print3('a');

  ThreadCreate(print2, '4');
  ThreadCreate(print2, '5');

  ThreadExit();
}
Esempio n. 3
0
void TestPcp()
{
	pthread_t writeId;
	pthread_t readId1;
	pthread_t readId2;

	TestPcpInit( 16, 5, 704 * 576 * 3 / 2 );

	ThreadCreate( &readId1, TestPcpRead1, NULL );
	ThreadCreate( &readId2, TestPcpRead2, NULL );    

	sleep( 2 );
	ThreadCreate( &writeId, TestPcpWriteThread, NULL );
}
Esempio n. 4
0
int main()
{
	SchedSet(NULL, NULL, SCHED_RR, NULL);
	SyncTypeCreate(_NTO_SYNC_SEM, &Semaphore, NULL);		// initial count: 0
	
	ThreadCreate(NULL, Thread1, NULL, NULL);
	ThreadCreate(NULL, Thread1, NULL, NULL);
	sleep(3);
	ThreadCreate(NULL, Thread2, NULL, NULL);
	SchedYield();
			
	sleep(11);
	return(0);
}
Esempio n. 5
0
File: mpd.c Progetto: avih/miniweb
int ehMpd(MW_EVENT event, int argi, void* argp)
{
	switch (event) {
	case MW_INIT:
		if (mpConsoleMutex) return 0;	// already inited
		memset(&mpx,0,sizeof(mpx));
		MutexCreate(&mpConsoleMutex);
		if (loopclip) ThreadCreate(&mpThreadHandle, mpThread, 0);
		break;
	case MW_UNINIT:
		MutexDestroy(&mpConsoleMutex);
		mpClose();
		break;
	case MW_PARSE_ARGS: {
		int i = 0;
		char** argv = (char**)argp;
		for (i = 0; i < argi; i++) {
			if (!strcmp(argv[i], "--mploop")) {
				loopclip = argv[++i];
				break;
			} else if (!strcmp(argv[i], "--mpbin")) {
				mpbin = argv[++i];
			}
		}
		} break;
	}
	return 0;
}
Esempio n. 6
0
void OperThreadWin::RunNewThread( const char* info, OperThreadFunc f, void* data )
{
	StopThread();

	clPtr<OperThreadParam> param = new OperThreadParam;
	tNode = new OperThreadNode( this, info, data );

	param->func = f;
	param->node = tNode;

	MutexLock lock( &operMutex );

	try
	{
		int n = NewThreadID();
//printf("TN=%i\n", n);
		param->IncRefCount();
		ThreadCreate( n, __123___OperThread, param.ptr() );
		threadId = n;
		param.drop(); //!!!
	}
	catch ( ... )
	{
		delete tNode;
		tNode = 0;
	}
}
Esempio n. 7
0
/**
 * Sets up callbacks for device hotplug events.
 */
ULONG HPRegisterForHotplugEvents(void)
{
	struct udev *udev;

	(void)pthread_mutex_init(&usbNotifierMutex, NULL);

	if (driverSize <= 0)
	{
		Log1(PCSC_LOG_INFO, "No bundle files in pcsc drivers directory: "
			PCSCLITE_HP_DROPDIR);
		Log1(PCSC_LOG_INFO, "Disabling USB support for pcscd");
		return 0;
	}

	/* Create the udev object */
	udev = udev_new();
	if (!udev)
	{
		Log1(PCSC_LOG_ERROR, "udev_new() failed");
		return 0;
	}

	HPRescanUsbBus(udev);

	(void)ThreadCreate(&usbNotifyThread, THREAD_ATTR_DETACHED,
		(PCSCLITE_THREAD_FUNCTION( )) HPEstablishUSBNotifications, udev);

	return 0;
} /* HPRegisterForHotplugEvents */
Esempio n. 8
0
bool Thread::Start(const std::string& name){
	RECOVERABLE_ASSERT(m_handle == nullptr);

	m_handle = ThreadCreate(name, ThreadClassEntry, this);
	
	return (m_handle != nullptr);
}
Esempio n. 9
0
int
main(int argc, char **argv)
{
    InitTerminalDriver();
    InitTerminal(1);

    if (argc > 1) HardwareOutputSpeed(1, atoi(argv[1]));
    if (argc > 2) HardwareInputSpeed(1, atoi(argv[2]));

    ThreadCreate(writer1, NULL);
    ThreadCreate(writer2, NULL);

    ThreadWaitAll();

    exit(0);
}
Esempio n. 10
0
void calendar_manager_thread_init(void)
{
  thread_hdl thread_id;
  Bool ret = FAILURE;

  ret = ThreadCreate( &thread_id,
                      THREAD_CALENDAR_MANAGER_NAME,
                      THREAD_DEFAULT_PRIORITY,
                      NULL,
                      THREAD_DEFAULT_STACK_SIZE,
                      calendar_manager_thread_entry,
                      (void *)(NULL) );

  if(FAILURE == ret)
  {
    CALENDER_DEBUG("Failed to create thread.");
    calendar_quit();
  }

  if(FAILURE == ThreadDetach(&thread_id))
  {
    CALENDER_DEBUG("Failed to detach thread.");
    calendar_quit();
  }
}
Esempio n. 11
0
static void
makeThread(TConn *             const connectionP,
           enum abyss_foreback const foregroundBackground,
           abyss_bool          const useSigchld,
           const char **       const errorP) {

    switch (foregroundBackground) {
    case ABYSS_FOREGROUND:
        connectionP->hasOwnThread = FALSE;
        *errorP = NULL;
        break;
    case ABYSS_BACKGROUND: {
        const char * error;
        connectionP->hasOwnThread = TRUE;
        ThreadCreate(&connectionP->threadP, connectionP,
                     &connJob, &threadDone, useSigchld,
                     &error);
        if (error) {
            xmlrpc_asprintf(errorP, "Unable to create thread to "
                            "process connection.  %s", error);
            xmlrpc_strfree(error);
        } else
            *errorP = NULL;
    }
    break;
    } /* switch */
}
Esempio n. 12
0
int uhAsyncDataTest(UrlHandlerParam* param)
{
	int ret = FLAG_DATA_STREAM | FLAG_TO_FREE;
	HANDLER_DATA* hdata = (HANDLER_DATA*)param->hs->ptr;

	if (param->pucBuffer) {
		if (!hdata) {
			// first invoke
			hdata = param->hs->ptr = calloc(1, sizeof(HANDLER_DATA));
			ThreadCreate(&hdata->thread, WriteContent, hdata);
			param->dataBytes = 0;
		} else {
			if (hdata->state == 1) {
				// done
				ret = 0;
			} else if (ThreadWait(hdata->thread, 10, 0)) {
				// data not ready
				param->dataBytes = 0;
			} else {
				// data ready
				strcpy(param->pucBuffer, hdata->result);
				param->dataBytes = strlen(param->pucBuffer);
				hdata->state = 1;
			}
		}
	} else {
		// cleanup
		ret = 0;
	}
	param->fileType=HTTPFILETYPE_TEXT;
	return ret;
}
Esempio n. 13
0
static void testThreads()
{
	/* be nice and start up the threads like they should be */
	ThreadInit();

	{
		TThread *heapThread = (TThread *)malloc(sizeof(TThread));
		int sleepTime = 3;
		int numThreadsToSpawn = 5;
		int i = 0;

		for  (i = 0; i<numThreadsToSpawn; ++i) {
			assert(ThreadCreate(heapThread,
			                    sillyThreadFn,
			                    &sleepTime) == TRUE);
		}

		/* give the threads time to get fired up */
		sleep(1);

		assert(ThreadCount(THREAD_DEFAULT_CLASS) == numThreadsToSpawn);

		/* give the threads time to run to completion */
		sleep(sleepTime + 1);

		assert(ThreadCount(THREAD_DEFAULT_CLASS) == 0);
	}
}
Esempio n. 14
0
/*
 * Sets up callbacks for device hotplug events.
 */
ULONG HPRegisterForHotplugEvents(void)
{
	ThreadCreate(&sHotplugWatcherThread,
		THREAD_ATTR_DEFAULT,
		(PCSCLITE_THREAD_FUNCTION( )) HPDeviceNotificationThread, NULL);

	return 0;
}
Esempio n. 15
0
//---------------------------------------------------------------------------
void TSnapThread::Start() 
{
    if (!Started)
    {
        ThreadCreate();
        Started = true;
    }
}
Esempio n. 16
0
void ThreadMain()
{
    int t1, t2, t3, t4;

    t1 = ThreadCreate(f, 1);
    printf("create a new thread (i=%d) [id=%d]\n", 1, t1);
    t2 = ThreadCreate(f, 2);
    printf("create a new thread (i=%d) [id=%d]\n", 2, t2);
    t3 = ThreadCreate(f, 3);
    printf("create a new thread (i=%d) [id=%d]\n", 4, t3);

    t4 = ThreadCreate(f, 4);
    printf("create a new thread (i=%d) [id=%d]\n", 4, t4);
    ThreadYield();

    printf("main thread invoked.\n");
}
Esempio n. 17
0
//____________________________________________________________
// TTCPClient
//____________________________________________________________
TTCPClient::TTCPClient (SocketRef ref, IPAddrPtr addr, TTCPListener * client)
	: TTCPSocket(0, client)
{
	fRef = ref;
	fPort = ntohs(addr->sin_port);
	fBind = false;
	ThreadCreate (kTCPClientMode);
	SetMTU ();
}
Esempio n. 18
0
int main()
{
	TThread loggingThread;
	TThread *loggerThreads = (TThread*)malloc(sizeof(TThread) * numThreadsToStart);
	unsigned int i = 0;

	printf("Creating threads\n");

	/* fire off the consumer thread */
	ThreadCreate(&loggingThread, log_error_thread, 0);

	sleep(1);

	/* fire off the producer threads */
	for (i=0; i<numThreadsToStart; ++i) {
		int *thrNum = (int*)malloc(sizeof(int));
		*thrNum = i;
		ThreadCreate(&loggerThreads[i], testLoggingThread, thrNum);
	}

	sleep(1);

	printf("Signalling START\n");

	/* signal that the threads can start */
	MutexLock(&cond_mutex);
	start_flag = 1;
	CondBroadcast(&start_cond);
	MutexUnlock(&cond_mutex);

	printf("Waiting for threads to complete\n");

	MutexLock(&threadCountLock);
	while (threadCount) {
		CondWait(&threadCountCond, &threadCountLock);
	}
	MutexUnlock(&threadCountLock);

	sleep(10);

	printf("See ya later, alligator\n");
	
	return EXIT_SUCCESS;
}
Esempio n. 19
0
int main()
{
  int i;

  ThreadCreate(f, THIS);
  f(THAT);

  for (i=0; i<100000; i++)
	;
}
void StartRecordGetH264Thread()
{
	int ret;
	g_recordGetH264Tm.runFlag = 1;
	ret = ThreadCreate( &g_recordGetH264Tm.id, RecordGetH264Thread, NULL );
	if( 0!= ret )
    {        
    	g_recordGetH264Tm.runFlag = 0;
    	SVPrint( "error:ThreadCreate:%s\r\n", STRERROR_ERRNO );
    }
}
Esempio n. 21
0
void StartSnapJpgThread()
{
	int ret;
	g_snapJpgTm.runFlag = 1;
	ret = ThreadCreate( &g_snapJpgTm.id, SnapJpgThread, NULL );
	if( 0!= ret )
    {        
    	g_snapJpgTm.runFlag = 0;
    	SVPrint( "error:ThreadCreate:%s\r\n", STRERROR_ERRNO );
    }
}
Esempio n. 22
0
void StartDtuAppThread()
{
	int ret;
	g_dtuAppTm.runFlag = 1;
	ret = ThreadCreate( &g_dtuAppTm.id, DtuAppThread, NULL );
	if( 0!= ret )
    {        
    	g_dtuAppTm.runFlag = 0;
    	SVPrint( "error:ThreadCreate:%s\r\n", STRERROR_ERRNO );
    }
}
Esempio n. 23
0
int main()
{
    int i;
	/* Initialization Part */
	DosInit();
	TcbInitAll();
    BufInit(freebuf);
  
	/* Get access to the entry address of clock intrrupt */
	old_int8 = getvect(8);

    
    clrscr();
    
    tcbs[0].state = RUNNING;
    current = 0;    /* current thread */

    /* Init NumBuf*/
    for(i = 0; i < NUM_BUF_LEN; i++)
    {
        numBuf[i] = 0;
    }
    
    pIn = pOut = 0; /* out/in Index for numBuf */

    ThreadCreate("T1",(codeptr)T1Producer,STACK_SIZE);
	ThreadCreate("T2",(codeptr)T2Custemer,STACK_SIZE);
	
        
    setvect(8, new_int8);
    my_swtch();

    TcbState();
    while(!ThreadFinished());

    TcbState();
    setvect(8, old_int8); /* Recover old clock interrupt */

    ThreadDestory(0);
    return 0;
}
Esempio n. 24
0
//____________________________________________________________
SocketStatus TTCPClient::ClientOpen (IPAddrPtr addr)
{
	int ret = TTCPSocket::Open ();
	if (ret != noErr) return ret;	

	addr->sin_port = htons(fPort);
	struct sockaddr * to = (struct sockaddr *)addr;
	if (connect (fRef, to, sizeof(struct sockaddr)) == SOCKET_ERROR)
		return WSAGetLastError ();
	SetMTU ();
	return ThreadCreate (kTCPClientMode);
}
Esempio n. 25
0
int main()
{

    char* stt = "\n\n\nth=0\n\n\n";
    char* mai = "\n\n\nmain\n\n\n";
    int x;
    for(x=0;x<20;x++){
        ThreadCreate(printString,stt);
    }
    PutString(mai);
    return 0;
}
Esempio n. 26
0
int main()
{
	/* Initialization Part */
	DosInit();
	TcbInitAll();
    BufInit(freebuf);
  
	/* Get access to the entry address of clock intrrupt */
	old_int8 = getvect(8);

    /*
	printf("Please Input the Time Slice \n");
	scanf("%d",&timeSlice);

	printf("Press Any Key To Continue ......\n");
	getch();
    */
    
    clrscr();
    
    tcbs[0].state = RUNNING;
    current = 0;    /* current thread */
    sum = 0;

    ThreadCreate("T1",(codeptr)T1AddOne,STACK_SIZE);
	ThreadCreate("T2",(codeptr)T2AddTwo,STACK_SIZE);
	
        
    setvect(8, new_int8);
    my_swtch();

    TcbState();
    while(!ThreadFinished());

    TcbState();
    setvect(8, old_int8); /* Recover old clock interrupt */
    printf("End : Sum is %d \n",sum);
    ThreadDestory(0);
    return 0;
}
Esempio n. 27
0
/***
  * 功能:
        窗体FrmWiFi的绘制函数,绘制整个窗体
  * 参数:
        1.void *pWndObj:    指向当前窗体对象
  * 返回:
        成功返回零,失败返回非零值
  * 备注:
***/
int FrmWiFiPaint(void *pWndObj)
{
    //错误标志、返回值定义
    int iReturn = 0;
	int i = 0;
    //得到当前窗体对象
    pFrmWiFi = (GUIWINDOW *) pWndObj;

    //显示桌面背景图片
    DisplayPicture(pWiFiBtnLeftBg);

	//显示菜单
    DisplayPicture(pWiFiMenuBg);
	for(i = 0; i < 5; i++)
	{
		DisplayPicture(pWiFiMenu[i]);
		DisplayLabel(pWiFiLblMenu[i]);
	}

	//显示状态栏上的图片
	DisplayPicture(pWiFiBtnOnOffBg);
	
	//显示窗体左上角窗体Label
	DisplayLabel(pWiFiLblFrmName);
	DisplayLabel(pWiFiLblOnOffInfo);
	//DisplayLabel(pWiFiLblConnecting);//victor

	SetPictureBitmap(BmpFileDirectory"btn_wifi_on_unpress.bmp", pWiFiBtnREnableOn);
	SetPictureBitmap(BmpFileDirectory"btn_wifi_off_press.bmp", pWiFiBtnREnableOff);
	SetPictureBitmap(BmpFileDirectory"btn_wifi_ssid_press.bmp", pWiFiBtnConnect);//victor

	DisplayPicture(pWiFiBtnREnableOn);
	DisplayPicture(pWiFiBtnREnableOff);	
	DisplayPicture(pWiFiBtnConnect);//victor
	DisplayLabel(pWiFiLblConnecting);//victor
	
	for(i = 0; i < WIFIITEM; i++)
	{
		DisplayPicture(pWiFiItem[i]);
		DisplayLabel(pWiFiLblItem[i]);
	}

	//初始化wifi,创建wifi线程
	InitMutex(&pWifiMutex, NULL);
	InitWifiQueue(10);
	ThreadCreate(&thdWifi, NULL, DefaultWifiThread, NULL);

    return iReturn;
}
Esempio n. 28
0
	void init(string ip, unsigned short _port) {
		Net::startup();

		try {
			socketClient.connectIPv4(ip, _port);
		}
		catch (...) {
			DebugError("Cannot connect to the server!");
			return;
		}

		threadRun = true;
		mutex = MutexCreate();
		t = ThreadCreate(networkThread, NULL);
	}
Esempio n. 29
0
//=============================================================================
int _tmain(int argc, _TCHAR* argv[]) {
    bool shutdown = false;
    ThreadInit();
    Thread * mainThread = ThreadRegister("main");
    Thread * childThread = ThreadCreate("test", 0, ThreadProc, &shutdown);

    ThreadLogAllThreads();

    shutdown = true;
    ThreadDestroy(childThread); childThread = NULL;
    ThreadUnregister(mainThread); mainThread = NULL;
    ThreadDestroy();

    return 0;
}
Esempio n. 30
0
//_______________________________________________________________________
int main (int argc, char *argv[])
{
	DrvMemPtr mem = GetData();
	uid_t uid = getuid ();
	
	if (argc != 2) usage (argv[0]);
	CheckMidiShare();
	setuid (name_to_uid ("root")); 
	mem->devId = openDev (argv[1]);
	SetupMidi (argv[1], mem);
	ThreadCreate (mem);
	run (mem, argv[1]);
	closeDriver (mem);
 	setuid (uid);
	return 0;        
}