Esempio n. 1
0
int ARSAL_Cond_Timedwait(ARSAL_Cond_t *cond, ARSAL_Mutex_t *mutex, int timeout)
{
    int result = 0;
    struct timespec ts;
    ARSAL_Time_GetLocalTime(&ts, NULL);
    ts.tv_nsec += MSEC_TO_NSEC(timeout % SEC_TO_MSEC(1));
    ts.tv_sec  += MSEC_TO_SEC(timeout);
    ts.tv_sec  += NSEC_TO_SEC(ts.tv_nsec);
    ts.tv_nsec %= SEC_TO_NSEC(1);

#if defined(HAVE_PTHREAD_H)
    result = pthread_cond_timedwait((pthread_cond_t *)*cond, (pthread_mutex_t *)*mutex, &ts);
    if ( (result != 0) && (result != ETIMEDOUT) )
    {
        ARSAL_PRINT(ARSAL_PRINT_FATAL, ARSAL_MUTEX_TAG, "Mutex/Cond operation failed! errno = %d , %s ; thread_id = %d",
                    result,
                    strerror(result),
#if HAVE_DECL_SYS_GETTID
                    syscall(SYS_gettid)
#else
                    0
#endif
            );
    }
#endif

    return result;
}
Esempio n. 2
0
void dcc_can_init(int devfd) {
    os_mutex_init(&dcc_mutex);
    mostacan_fd = devfd;
    DccLoop_Init();
    dcc_timer = os_timer_create(&dcc_timer_callback, NULL, NULL);
    os_timer_start(dcc_timer, MSEC_TO_NSEC(100));
    os_thread_create(NULL, "dcc_can_rx", 0, DCC_CAN_THREAD_CAN_STACK_SIZE,
		     dcc_can_thread, NULL);
}