コード例 #1
0
ファイル: Thread.c プロジェクト: manjunathgitbub/iperf-ssm
/* -------------------------------------------------------------------
 * unset a thread from being ignorable, so joinall will wait on it
 * this simply increments the thread count that joinall uses.
 * This is utilized by the reporter thread which knows when it
 * is ok to quit (aka no pending reports).
 * ------------------------------------------------------------------- */
void thread_unsetignore( void ) {
    Condition_Lock( thread_sNum_cond );
    thread_sNum++;
    Condition_Signal( &thread_sNum_cond );
    Condition_Unlock( thread_sNum_cond );
}
コード例 #2
0
ファイル: Thread.c プロジェクト: manjunathgitbub/iperf-ssm
/* -------------------------------------------------------------------
 * set a thread to be non-terminating, so if you cancel through
 * Ctrl-C they can be ignored by the joinall.
 * ------------------------------------------------------------------- */
void thread_register_nonterm( void ) {
    Condition_Lock( thread_sNum_cond );
    nonterminating_num++; 
    Condition_Unlock( thread_sNum_cond );
}
コード例 #3
0
ファイル: Thread.c プロジェクト: manjunathgitbub/iperf-ssm
/* -------------------------------------------------------------------
 * set a thread to be ignorable, so joinall won't wait on it
 * this simply decrements the thread count that joinall uses.
 * This is utilized by the reporter thread which knows when it
 * is ok to quit (aka no pending reports).
 * ------------------------------------------------------------------- */
void thread_setignore( ) {
    Condition_Lock( thread_sNum_cond );
    thread_sNum--;
    Condition_Signal( &thread_sNum_cond );
    Condition_Unlock( thread_sNum_cond );
}
コード例 #4
0
ファイル: Thread.c プロジェクト: manjunathgitbub/iperf-ssm
DWORD WINAPI
#else
void*
#endif
thread_run_wrapper( void* paramPtr ) {
    struct thread_Settings* thread = (struct thread_Settings*) paramPtr;

    // which type of object are we
    switch ( thread->mThreadMode ) {
        case kMode_Server:
            {
                /* Spawn a Server thread with these settings */
                server_spawn( thread );
            } break;
        case kMode_Client:
            {
                /* Spawn a Client thread with these settings */
                client_spawn( thread );
            } break;
        case kMode_Reporter:
            {
                /* Spawn a Reporter thread with these settings */
                reporter_spawn( thread );
            } break;
        case kMode_Listener:
            {
                // Increment the non-terminating thread count
                thread_register_nonterm();
                /* Spawn a Listener thread with these settings */
                listener_spawn( thread );
                // Decrement the non-terminating thread count
                thread_unregister_nonterm();
            } break;
        default:
            {
                FAIL(1, "Unknown Thread Type!\n", thread);
            } break;
    }

#ifdef HAVE_POSIX_THREAD
    // detach Thread. If someone already joined it will not do anything
    // If noone has then it will free resources upon return from this
    // function (Run_Wrapper)
    pthread_detach(thread->mTID);
#endif

    // decrement thread count and send condition signal
    Condition_Lock( thread_sNum_cond );
    thread_sNum--;
    Condition_Signal( &thread_sNum_cond );
    Condition_Unlock( thread_sNum_cond );

    // Check if we need to start up a thread after executing this one
    if ( thread->runNext != NULL ) {
        thread_start( thread->runNext );
    }

    // Destroy this thread object
    Settings_Destroy( thread );

    return 0;
} // end run_wrapper
コード例 #5
0
/* -------------------------------------------------------------------
 * set a thread to be non-terminating, so if you cancel through
 * Ctrl-C they can be ignored by the joinall.
 * ------------------------------------------------------------------- */
void thread_register_nonterm( void ) {
    Condition_Lock( thread_sNum_cond );
    IPERF_DEBUGF( THREAD_DEBUG | IPERF_DBG_TRACE, ( "Registering non-terminating thread.\r\n" ) );
    nonterminating_num++; 
    Condition_Unlock( thread_sNum_cond );
} // end thread_register_nonterm
コード例 #6
0
DWORD WINAPI
#else
void*
#endif /* HAVE_WIN32_THREAD */
thread_run_wrapper( void* paramPtr ) {
    struct thread_Settings* thread = (struct thread_Settings*) paramPtr;
    IPERF_DEBUGF( THREAD_DEBUG | IPERF_DBG_TRACE | IPERF_DBG_STATE, ( "%s thread is now running. ID is %lu.\r\n", thread_names[thread->mThreadMode], (long unsigned) thread_getid() ) );

    // which type of object are we
    switch ( thread->mThreadMode ) {
        case kMode_Server:
            {
                /* Spawn a Server thread with these settings */
                server_spawn( thread );
            } break;
        case kMode_Client:
            {
                /* Spawn a Client thread with these settings */
                client_spawn( thread );
            } break;
        case kMode_Reporter:
            {
                /* Spawn a Reporter thread with these settings */
                reporter_spawn( thread );
            } break;
        case kMode_Listener:
            {
                // Increment the non-terminating thread count
                thread_register_nonterm();
                /* Spawn a Listener thread with these settings */
                listener_spawn( thread );
                // Decrement the non-terminating thread count
                thread_unregister_nonterm();
            } break;
        default:
            {
                FAIL(1, ( "Unknown Thread Type!\r\n" ), thread);
            } break;
    }

#ifdef HAVE_POSIX_THREAD
    // detach Thread. If someone already joined it will not do anything
    // If noone has then it will free resources upon return from this
    // function (Run_Wrapper)
    IPERF_DEBUGF( THREAD_DEBUG | IPERF_DBG_TRACE, ( "Detaching %s thread.\r\n", thread_names[thread->mThreadMode] ) );
    pthread_detach(thread->mTID);
#endif /* HAVE_POSIX_THREAD */

    // decrement thread count and send condition signal
    Condition_Lock( thread_sNum_cond );
    IPERF_DEBUGF( THREAD_DEBUG | IPERF_DBG_TRACE, ( "Decrementing thread count from %d to %d.\r\n", thread_sNum, (thread_sNum - 1) ) );
    thread_sNum--;

    IPERF_DEBUGF( CONDITION_DEBUG | IPERF_DBG_TRACE, ( "Signaling thread_sNum_cond condition.\r\n" ) );
    Condition_Signal( &thread_sNum_cond );
    Condition_Unlock( thread_sNum_cond );

    // Check if we need to start up a thread after executing this one
    if ( thread->runNext != NULL ) {
        thread_start( thread->runNext );
    }

    // Destroy this thread object
    Settings_Destroy( thread );

    return 0;
} // end thread_run_wrapper
コード例 #7
0
ファイル: photograph.c プロジェクト: 119-org/lamobo-d1
static void *photograph_thread(void *param)
{
	//int mount_falg = 0;
	T_S32 bavail, bsize;
	signed long long DiskSize = 0;
	T_pSTR filename;
	
	while(1)
	{
	
		Condition_Lock( g_conMangerPh );

		Condition_Wait( &g_conMangerPh );
		if(g_phsize == 0)
			continue;
		
		Condition_Unlock( g_conMangerPh );
		if(sd_mount == 0)
		{
			if (access(SDDEV, R_OK) < 0)
			{
				//no sd card
				printf("no SDsard exit \n");
				continue;
			}
			else
			{
				//mount_sd();
			}
			//mount_falg =1;
		}

		
		DiskFreeSize( "/mnt", &bavail, &bsize);
		DiskSize = (T_S64)(T_U32)(bavail) * (T_S64)(T_U32)(bsize);
		
		if ( DiskSize < (T_S64)MIN_FREE_SPACE_SIZE ) 
		{
			printf( "get %s disk size error!\n", "/mnt" );
			//umount_sd();
			goto err;
		}

		filename = MakeFileName();
		printf("filename is %s \n", filename);
		if(filename == NULL)
		{
			printf("filename is NULL \n");
			goto err;
		}

		long fid = open(filename, O_RDWR | O_CREAT | O_TRUNC);
		if(fid <= 0)
		{
			printf("open file err \n");
			free(filename);
			goto err;
		}

		Condition_Lock( g_conMetex );
		g_busy = 1;
		Condition_Unlock( g_conMetex );
		
		write( fid, encbuf, g_phsize);

		Condition_Lock( g_conMetex );
		g_busy = 0;
		Condition_Unlock( g_conMetex );

		close(fid);

		free(filename);	
err:
		g_phsize = 0;
		
		
		//if( mount_falg == 1 )
		//{
			//umount_sd();
		//}
		
		//printf("save file ok\n");
			
	}
	return NULL;
}