コード例 #1
0
ファイル: gprof-helper.c プロジェクト: Antisunny/bedops
                   void *__restrict arg) 
{ 
    wrapper_t wrapper_data; 
    int i_return; 

    /* Initialize the wrapper structure */ 
    wrapper_data.start_routine = start_routine; 
    wrapper_data.arg = arg; 
    getitimer(ITIMER_PROF, &wrapper_data.itimer); 
    pthread_cond_init(&wrapper_data.wait, NULL); 
    pthread_mutex_init(&wrapper_data.lock, NULL); 
    pthread_mutex_lock(&wrapper_data.lock); 

    /* The real pthread_create call */ 
    i_return = pthread_create_orig(thread, 
                                   attr, 
                                   &wrapper_routine, 
                                   &wrapper_data); 

    /* If the thread was successfully spawned, wait for the data 
     * to be released */ 
    if(i_return == 0) 
        { 
            pthread_cond_wait(&wrapper_data.wait, &wrapper_data.lock); 
        } 

    pthread_mutex_unlock(&wrapper_data.lock); 
    pthread_mutex_destroy(&wrapper_data.lock); 
    pthread_cond_destroy(&wrapper_data.wait); 

    return i_return; 
} 
コード例 #2
0
ファイル: gprof_helper.c プロジェクト: danielhuo/codes
        void* __restrict arg
        )
{
    wrapper_t data;
    int ret;

    /* Initialize the wrapper structure */
    data.start_routine = start_routine;
    data.arg = arg;
    getitimer(ITIMER_PROF, &data.itimer);

    pthread_cond_init(&data.cond, NULL);
    pthread_mutex_init(&data.lock, NULL);


    pthread_mutex_lock(&data.lock);
    ret = pthread_create_orig(thread, attr, &wrapper_routine, &data);   /* real pthread_create call */

    /* If the thread was successfully spawned,
     * wait for the data to be released */
    if(ret == 0){
        pthread_cond_wait(&data.cond, &data.lock);
    }
    pthread_mutex_unlock(&data.lock);

    pthread_mutex_destroy(&data.lock);
    pthread_cond_destroy(&data.cond);

    return ret;
}