コード例 #1
0
ファイル: vm_thread_linux32.c プロジェクト: ph0b/MediaSDK
/* attach to current thread. return 1 if successful  */
int32_t vm_thread_attach(vm_thread *thread, vm_thread_callback func, void *arg)
{
    int32_t i_res = 1;
    pthread_attr_t attr;

    /* check error(s) */
    if (NULL == thread)
        return 0;

    if (0 != i_res)
    {
        if (VM_OK != vm_event_init(&thread->exit_event, 1, 0))
            i_res = 0;
    }

    if ((0 != i_res) &&
        (VM_OK != vm_mutex_init(&thread->access_mut)))
        i_res = 0;

    thread->is_valid = 1;
    thread->p_thread_func = func;
    thread->p_arg = 0;
    thread->i_wait_count = 1; // vm_thread_wait should not try to join this thread
    thread->handle = pthread_self();

    return i_res;
}
コード例 #2
0
/* create a thread. return 1 if success */
Ipp32s vm_thread_create(vm_thread *thread,
                        Ipp32u (*vm_thread_func)(void *),
                        void *arg)
{
    Ipp32s i_res = 1;
    pthread_attr_t attr;

    /* check error(s) */
    if ((NULL == thread) ||
        (NULL == vm_thread_func))
        return 0;

    if (0 != i_res)
    {
        if (VM_OK != vm_event_init(&thread->exit_event, 1, 0))
            i_res = 0;
    }

    if ((0 != i_res) &&
        (VM_OK != vm_mutex_init(&thread->access_mut)))
        i_res = 0;

    if (0 != i_res)
    {
        vm_mutex_lock(&thread->access_mut);
        thread->p_thread_func = vm_thread_func;
        thread->p_arg = arg;
        pthread_attr_init(&attr);
        pthread_attr_setschedpolicy(&attr, geteuid() ? SCHED_OTHER : SCHED_RR);

        thread->is_valid =! pthread_create(&thread->handle,
                                           &attr,
                                           vm_thread_proc,
                                           (void*)thread);
        i_res = (thread->is_valid) ? 1 : 0;
        vm_mutex_unlock(&thread->access_mut);
        pthread_attr_destroy(&attr);
    }
    vm_thread_set_priority(thread, VM_THREAD_PRIORITY_LOWEST);
    return i_res;

} /* Ipp32s vm_thread_create(vm_thread *thread, */
コード例 #3
0
ファイル: vm_thread_linux32.c プロジェクト: ph0b/MediaSDK
/* create a thread. return 1 if success */
int32_t vm_thread_create(vm_thread *thread,
                        uint32_t (*vm_thread_func)(void *),
                        void *arg)
{
    int32_t i_res = 1;
//    pthread_attr_t attr;

    /* check error(s) */
    if ((NULL == thread) ||
        (NULL == vm_thread_func))
        return 0;

    if (0 != i_res)
    {
        if (VM_OK != vm_event_init(&thread->exit_event, 1, 0))
            i_res = 0;
    }

    if ((0 != i_res) &&
        (VM_OK != vm_mutex_init(&thread->access_mut)))
        i_res = 0;

    if (0 != i_res)
    {
        vm_mutex_lock(&thread->access_mut);
        thread->p_thread_func = vm_thread_func;
        thread->p_arg = arg;

        thread->is_valid =! pthread_create(&thread->handle,
                                           NULL,
                                           vm_thread_proc,
                                           (void*)thread);

        i_res = (thread->is_valid) ? 1 : 0;
        vm_mutex_unlock(&thread->access_mut);
//        pthread_attr_destroy(&attr);
    }
    return i_res;

} /* int32_t vm_thread_create(vm_thread *thread, */