Пример #1
0
CONST int *
__errnoloc(void)
{
    int *ptr = NULL;

    pthread_once(&__once, __errnoinit);
    ptr = pthread_get_specific(__key);
    if (!ptr) {
        ptr = malloc(sizeof(int));
        pthread_setspecific(__key, ptr);
    }

    return ptr;
}
// May be called from any thread - totally reentrant
void* pebil_get_data(pthread_t thread_id, pthread_key_t image_key){
    if( pthread_self() == thread_id ) {
        return pthread_get_specific(image_key);
    } else {
        struct thread_list * threadinfo = get_thread_data(thread_id);

        struct data_list * curdata = threadinfo->datas;

        while(curdata != NULL) {
            if(curdata->image_id == image_key){
                return curdata->data;
            }
        }

        assert(0 && "Attempt to retrieve non-existent image data");
        return NULL;
    }
}