コード例 #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
   bool VC1TaskStore::Init(uint32_t iConsumerNumber,
                           uint32_t iMaxFramesInParallel,
                           VC1VideoDecoder* pVC1Decoder)
    {
        uint32_t i;
        m_iNumDSActiveinQueue = 0;
        m_iRangeMapIndex   =  iMaxFramesInParallel + VC1NUMREFFRAMES -1;
        pMainVC1Decoder = pVC1Decoder;
        m_iConsumerNumber = iConsumerNumber;
        m_iNumFramesProcessing = iMaxFramesInParallel;

        {
            // Heap Allocation
            {
                uint32_t heapSize = CalculateHeapSize();

                if (m_pMemoryAllocator->Alloc(&m_iTSHeapID,
                    heapSize,
                    UMC_ALLOC_PERSISTENT,
                    16) != UMC_OK)
                    return false;

                delete m_pSHeap;
                m_pSHeap = new VC1TSHeap((uint8_t*)m_pMemoryAllocator->Lock(m_iTSHeapID),heapSize);
            }

            m_pSHeap->s_new(&m_pGuardGet,m_iNumFramesProcessing);
            for (i = 0; i < m_iNumFramesProcessing; i++)
            {
                m_pSHeap->s_new(&m_pGuardGet[i]);

                vm_mutex_set_invalid(m_pGuardGet[i]);
                if (VM_OK != vm_mutex_init(m_pGuardGet[i]))
                    return false;
            }
        }

        if (0 == vm_mutex_is_valid(&m_mDSGuard))
        {
            if (VM_OK != vm_mutex_init(&m_mDSGuard))
                return false;
        }
        return true;
    }
コード例 #3
0
ファイル: measure.c プロジェクト: lantti/RestessbarKSreporter
ADC_HANDLE open_hx711(int scl_pin, int sda_pin)
{
	ADC_HANDLE handle = 0;
	handle_details* details;
	hx711_task* task;

	while (open_handles[handle] != NULL)
	{
		handle++;
		if (handle > MAX_HANDLE)
		{
			return ADC_HANDLE_INVALID;
		}
	}

	details = vm_calloc(sizeof(handle_details));
	if (details == NULL)
	{
		return ADC_HANDLE_INVALID;
	}

	task = &details->task;
	task->scl_handle = vm_dcl_open(VM_DCL_GPIO, scl_pin);
	if (task->scl_handle == VM_DCL_HANDLE_INVALID)
	{
		vm_free(details);
		return ADC_HANDLE_INVALID;
	}
	vm_dcl_control(task->scl_handle, VM_DCL_GPIO_COMMAND_SET_MODE_0, NULL);
	vm_dcl_control(task->scl_handle, VM_DCL_GPIO_COMMAND_SET_DIRECTION_OUT, NULL);
	vm_dcl_control(task->scl_handle, VM_DCL_GPIO_COMMAND_WRITE_HIGH, NULL);

	task->sda_handle = vm_dcl_open(VM_DCL_GPIO, sda_pin);
	if (task->sda_handle == VM_DCL_HANDLE_INVALID)
	{
		vm_dcl_close(task->scl_handle);
		vm_free(details);
		return ADC_HANDLE_INVALID;
	}
	vm_dcl_control(task->sda_handle, VM_DCL_GPIO_COMMAND_SET_MODE_0, NULL);
	vm_dcl_control(task->sda_handle, VM_DCL_GPIO_COMMAND_SET_DIRECTION_IN, NULL);

	vm_mutex_init(&details->mutex);
	task->op = WAIT;
	task->delay = 100;
	task->callback = dummy_callback;
	task->callback_env = NULL;
	open_handles[handle] = details;
	write_console("open\n");
	vm_thread_create(measurement, (void*) details, (VM_THREAD_PRIORITY) 0);
	return handle;
}
コード例 #4
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, */
コード例 #5
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, */
コード例 #6
0
    bool VC1TaskStore::Reset()
    {
        uint32_t i = 0;

        //close
        m_bIsLastFramesMode = false;
        ResetDSQueue();

        if (vm_mutex_is_valid(&m_mDSGuard))
            vm_mutex_destroy(&m_mDSGuard);

        for (i = 0; i < m_iNumFramesProcessing; i++)
        {
            vm_mutex_destroy(m_pGuardGet[i]);
            m_pGuardGet[i] = 0;
        }

        if(m_pMemoryAllocator)
        {
            if (m_pDescriptorQueue)
            {
                for (i = 0; i < m_iNumFramesProcessing; i++)
                    m_pDescriptorQueue[i]->Release();
            }

            if (static_cast<int>(m_iTSHeapID) != -1)
            {
                m_pMemoryAllocator->Unlock(m_iTSHeapID);
                m_pMemoryAllocator->Free(m_iTSHeapID);
                m_iTSHeapID = (MemID)-1;
            }

            m_iNumDSActiveinQueue = 0;

            delete m_pSHeap;

            // Heap Allocation
            {
                uint32_t heapSize = CalculateHeapSize();

                if (m_pMemoryAllocator->Alloc(&m_iTSHeapID,
                    heapSize,
                    UMC_ALLOC_PERSISTENT,
                    16) != UMC_OK)
                    return false;

                m_pSHeap = new VC1TSHeap((uint8_t*)m_pMemoryAllocator->Lock(m_iTSHeapID), heapSize);
            }

            {
                m_pSHeap->s_new(&m_pGuardGet,m_iNumFramesProcessing);

                for (i = 0; i < m_iNumFramesProcessing; i++)
                {
                    m_pSHeap->s_new(&m_pGuardGet[i]);

                    vm_mutex_set_invalid(m_pGuardGet[i]);
                    if (VM_OK != vm_mutex_init(m_pGuardGet[i]))
                        return false;
                }
            }
        }

        if (0 == vm_mutex_is_valid(&m_mDSGuard))
        {
            if (VM_OK != vm_mutex_init(&m_mDSGuard))
                return false;
        }
        
        SetBFrameIndex(-1);
        SetCurrIndex(-1);
        SetRangeMapIndex(-1);
        SetPrevIndex(-1);
        SetNextIndex(-1);

        return true;
    }