예제 #1
0
 int JackNetMasterInterface::Recv ( size_t size, int flags )
 {
     int rx_bytes;
     if ( ( ( rx_bytes = fSocket.Recv ( fRxBuffer, size, flags ) ) == SOCKET_ERROR ) && fRunning )
     {
         net_error_t error = fSocket.GetError();
         //no data isn't really a network error, so just return 0 avalaible read bytes
         if ( error == NET_NO_DATA )
             return 0;
         else if ( error == NET_CONN_ERROR )
         {
             //fatal connection issue, exit
             jack_error ( "'%s' : %s, exiting.", fParams.fName, StrError ( NET_ERROR_CODE ) );
             //ask to the manager to properly remove the master
             Exit();
             
             // UGLY temporary way to be sure the thread does not call code possibly causing a deadlock in JackEngine.
             ThreadExit();
         }
         else
             jack_error ( "Error in master receive : %s", StrError ( NET_ERROR_CODE ) );
     }
     
     packet_header_t* header = reinterpret_cast<packet_header_t*>(fRxBuffer);
     PacketHeaderNToH(header, header);
     return rx_bytes;
 }
예제 #2
0
static void
connJob(void * const userHandle) {
/*----------------------------------------------------------------------------
   This is the root function for a thread that processes a connection
   (performs HTTP transactions).

   We never return.  We ultimately exit the thread.
-----------------------------------------------------------------------------*/
    TConn * const connectionP = userHandle;

    (connectionP->job)(connectionP);

    connectionP->finished = TRUE;
        /* Note that if we are running in a forked process, setting
           connectionP->finished has no effect, because it's just our own
           copy of *connectionP.  In this case, Parent must update his own
           copy based on a SIGCHLD signal that the OS will generate right
           after we exit.
        */


    /* Note that ThreadExit() runs a cleanup function, which in our
       case is connDone().
    */
    ThreadExit(connectionP->threadP, 0);
}
예제 #3
0
static void thread_exit() {
#ifdef NEKO_WINDOWS
	ThreadExit();
#else
        pthread_exit(NULL);
#endif
}
예제 #4
0
파일: assign2_3.c 프로젝트: EdwardC/project
void test(){
	int j;
	
  for(j = 0; j < 10; j++){
    PrintStr("loop in test() \n");
  }
  ThreadExit(0);
}
GuiImageAsync::~GuiImageAsync()
{
	ThreadRemoveImage(this);
	ThreadExit();
	while(InUse == this) usleep(100);
	if (imgData) delete imgData;
	if (arg) free(arg);
}
예제 #6
0
void printString(char* c)
{
#if 1
    c[6]=48 + counter++;
    PutString(c);
    ThreadExit();
#endif
}
예제 #7
0
  void JackNetMasterInterface::FatalSendError()
 {
     // fatal connection issue, exit
     jack_error("Send connection lost error = %s, '%s' exiting", StrError(NET_ERROR_CODE), fParams.fName);
     // ask to the manager to properly remove the master
     Exit();
     // UGLY temporary way to be sure the thread does not call code possibly causing a deadlock in JackEngine.
     ThreadExit();
 }
void f(void *arg)
{
  const char *s = arg;
  int i;
  for (i = 0; i < N; i++)
    puts(s);

  ThreadExit();
}
void print2(void* arg)
{
  int volatile i;
  for(i = 0; i < 5; i++){
    PutChar((char)arg);
  }
  PutString("\n");
  ThreadExit();
}
void print(void* arg)
{

#if 1
  PutChar((char)arg);
  PutChar('z');
  ThreadExit();
#endif

}
예제 #11
0
파일: t_thread.c 프로젝트: cmjonze/anacapa
static void *sillyThreadFn(void *args)
{
	int *sleepTime = (int *)args;
	assert(sleepTime);

	/* we don't want you sleeping forever, so arg > 20 is tossed */
	assert(*sleepTime >= 0 && *sleepTime <= 20);

    	sleep(*sleepTime);

	/* make sure we let the Thread manager know we're gone */
	ThreadExit(ThreadSelf());
}
int main()
{
  ThreadCreate(print2, '1');
  ThreadCreate(print2, '2');
  ThreadCreate(print2, '3');

  print3('a');

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

  ThreadExit();
}
예제 #13
0
DWORD CExecFT::ThreadProc()
{
    _hrInit = ThreadInit();

    if(_hEvent)
    {
        Verify(SetEvent(_hEvent));
    }

    if(_hrInit == S_OK)
    {
        ThreadExec();
    }

    ThreadTerm();
    ThreadExit();
    return 0;
}
예제 #14
0
/* this is not proper really, but works!
*/
void wav_end(struct AUDIO_HEADER *header)
{
unsigned char ispred[20]={0x52 ,0x49 ,0x46 ,0x46 ,0xfc ,0x59  ,0x4  ,0x0 ,0x57
 ,0x41 ,0x56 ,0x45 ,0x66 ,0x6d ,0x74 ,0x20 ,0x10  ,0x0  ,0x0  ,0x0 };
unsigned char iza[8]={0x64 ,0x61 ,0x74 ,0x61};
int len,fs,i;

	len=tell(out_fd)-44;
	fs=t_sampling_frequency[header->ID][header->sampling_frequency];
	Rewind(out_fd);
	FileWrite(ispred,1,20,out_fd);

	/* 'microsoft' PCM */
	FilePutChar(1,out_fd);
	FilePutChar(0,out_fd);
	
	/* nch */
	FilePutChar(nch,out_fd);
	FilePutChar(0,out_fd);
	
	/* samples_per_second */
	for (i=0;i<32;i+=8) FilePutChar((fs>>i)&0xff,out_fd);
	
	/* average block size */
	fs *= 2*nch;
	for (i=0;i<32;i+=8) FilePutChar((fs>>i)&0xff,out_fd);
	
	/* block align */
        fs = 2*nch;
        for (i=0;i<16;i+=8) FilePutChar((fs>>i)&0xff,out_fd);
	         
	/* bits per sample */
        FilePutChar(16,out_fd);
        FilePutChar(0,out_fd);
        
        /* i jope anomalija! */
        FileWrite(iza,1,4,out_fd);

	/* length */
	for (i=0;i<32;i+=8) FilePutChar((len>>i)&0xff,out_fd);
	
	ThreadExit(0);
}
예제 #15
0
/***
  * 功能:
        默认触摸屏线程入口函数
  * 参数:
        1.void *pThreadArg:     线程入口函数参数,类型为(GUITOUCH *)
  * 返回:
        返回线程结束状态
  * 备注:
***/
void* DefaultTouchThread(void *pThreadArg)
{
    //错误标志、返回值定义
    int iErr = 0;
    static int iReturn = 0;
    //临时变量定义
    int iExit = 0;
    GUITOUCH *pTouchObj = pThreadArg;

    while (!iExit)
    {
        //根据结束标志判断是否需要结束触摸屏线程
        iExit = GetExitFlag();
        if (iExit)
        {
            break;
        }

        //触摸屏事件的封装
        switch (pTouchObj->iDevType)
        {
        case GUITOUCH_TYP_STD:
            iErr = StandardTouchProcess(pTouchObj);
            break;
        case GUITOUCH_TYP_CUST:
            iErr = CustomTouchProcess(pTouchObj);
            break;
        default:
            break;
        }

        //出错为-1,表示无触摸屏数据可读,睡眠50毫秒
        if (-1 == iErr)
        {
            MsecSleep(50);
        }
    }

    //退出线程
    ThreadExit(&iReturn);
    return &iReturn;    //该语句只是为了消除编译器报警,实际上不起作用
}
예제 #16
0
/* TX client thread.
   Reads from the Queue and sends it to the network.
*/
void *TBClientTxFunc(void *pClient_Arg)
#ifdef BODYDEF
{
	BOOL SentNick = FALSE;
	TBClient_Type *pThis = (TBClient_Type*)pClient_Arg;
	assert(pThis);
	while(pThis->Running)
	{
		char *pMsg = NULL;
		TBMessage_Type Msg;
		THQRead(&pThis->TxQueue, &pMsg);
		assert(pMsg);
		if (SentNick == FALSE)
		{
			Msg.Header.Type = MSG_TYPE_NICK;
			memcpy(Msg.Body,
				   pThis->Nick,
				   strlen(pThis->Nick));

			Msg.Header.Length = strlen(pThis->Nick);

			pThis->ClientWrite(pThis->CliSocket,
							   MSG_PACKET_LEN(Msg),
							   (char *)&Msg);			
			SentNick = TRUE;
		}
		Msg.Header.Type = MSG_TYPE_CHAT;
		memcpy(Msg.Body,
			   pMsg,
			   strlen(pMsg));

		Msg.Header.Length = strlen(pMsg);

		pThis->ClientWrite(pThis->CliSocket,
						   MSG_PACKET_LEN(Msg),
						   (char *)&Msg);			
		free(pMsg);
	}

	ThreadExit(NULL);
}
예제 #17
0
/**************************************************
 * Secondary threads main function                *
 **************************************************/
void* DoNewThread(void* threadNumArg) {
    int threadNum = *((int*)threadNumArg);
    Print(roleStrings[threadNum] + " thread was created succesfully."); // FOR DEBUG
    IncThreads();
    switch (threadNum) {
    case ROLE_WAIT:
        DoSleep(1000);
        ErrorExit(RES_EXIT_TIMEOUT); // the ROLE_WAIT thread reached its timeout of 1000 seconds - something is wrong
        
    case ROLE_LOOP:
        while (1); // never exits from here
        break;

    case ROLE_FINISH:
        break; // exits normally, process continues

    case ROLE_EXIT:
        if (exitType == EXIT_SEC_EXIT) {
            while (NumOfThreads() != ROLE_SIZE) {
                DoYield(); // wait here until all threads are ready
            }
            Print("ROLE_EXIT thread is calling exit()"); // FOR DEBUG

            // exit and kill the entire process
            exit(RES_SUCCESS); // never returns
        }
        // thread exits but process continues
        ThreadExit(); // never returns

    case ROLE_CANCELED:
        // On Windows, this thread will be canceled using the TerminateThread API. The documentation states that
        // it is unsafe to use this function if the target thread is executing certain kernel32 calls etc.
        // On Linux, the thread must enter a function which is defined as a cancellation point. See pthreads entry
        // in the chapter 7 of the manual for further details.
        readyToCancel = true;
        EnterSafeCancellationPoint();
    }
        
    return NULL;
}
예제 #18
0
 int JackNetMasterInterface::Send ( size_t size, int flags )
 {
     int tx_bytes;
     packet_header_t* header = reinterpret_cast<packet_header_t*>(fTxBuffer);
     PacketHeaderHToN(header, header);
     
     if ( ( ( tx_bytes = fSocket.Send ( fTxBuffer, size, flags ) ) == SOCKET_ERROR ) && fRunning )
     {
         net_error_t error = fSocket.GetError();
         if ( error == NET_CONN_ERROR )
         {
             //fatal connection issue, exit
             jack_error ( "'%s' : %s, exiting.", fParams.fName, StrError ( NET_ERROR_CODE ) );
             Exit();
             
             // UGLY temporary way to be sure the thread does not call code possibly causing a deadlock in JackEngine.
             ThreadExit();
         }
         else
             jack_error ( "Error in master send : %s", StrError ( NET_ERROR_CODE ) );
     }
     return tx_bytes;
 }
예제 #19
0
void
sThreadExit (int num) {
  ThreadExit(num);
}
int main()
{
  ThreadCreate(f, THIS);
  f(THAT);
  ThreadExit();
}