/** LINUX Application - Wait for a device wake up. \param max_fd max devFd number to check. \param read_fd_in contains the devFd for wakeup. \param read_fd_out returns the waked up devFd. \param timeout_ms max time to wait [ms]. \return Number of descriptors contained in the descriptor sets (0: no set or timeout). -1 in case of error. */ IFX_int32_t IFXOS_DeviceSelect( const IFX_uint32_t max_fd, const IFXOS_devFd_set_t *read_fd_in, IFXOS_devFd_set_t *read_fd_out, const IFX_uint32_t timeout_ms) { IFXOS_devFd_set_t tmp; struct timeval tv; switch (timeout_ms) { case IFXOS_NO_WAIT: tv.tv_sec = 0; tv.tv_usec = 0; break; case IFXOS_WAIT_FOREVER: break; default: tv.tv_sec = timeout_ms / 1000; tv.tv_usec = (timeout_ms % 1000) * 1000; } if(read_fd_in) { if(read_fd_out) { memcpy(read_fd_out, read_fd_in, sizeof(IFXOS_devFd_set_t)); if (timeout_ms != IFXOS_WAIT_FOREVER) return select(max_fd, read_fd_out, NULL, NULL, &tv); else return select(max_fd, read_fd_out, NULL, NULL, NULL); } else { memcpy(&tmp, read_fd_in, sizeof(IFXOS_devFd_set_t)); if (timeout_ms != IFXOS_WAIT_FOREVER) return select(max_fd, &tmp, NULL, NULL, &tv); else return select(max_fd, &tmp, NULL, NULL, NULL); } } else { IFXOS_MSecSleep(timeout_ms); } return 0; }
/* For a detailed description of the function, its arguments and return value please refer to the description in the header file 'drv_dsl_cpe_os.h' */ DSL_void_t DSL_DRV_MSecSleep(DSL_uint32_t msec) { IFXOS_MSecSleep(msec); }
/** Win32 - Shutdown a given thread. Therefore the thread delete functions triggers the user thread function to shutdown and wait for end. \par Implementation - force a shutdown via the shutdown flag and wait for task end with timeout. - free previous allocated internal data. \param pThrCntrl - Thread control struct. \param waitTime_ms - Time [ms] to wait for "self-shutdown" of the user thread. \return - IFX_SUCCESS thread was successful deleted - thread control struct is freed. - IFX_ERROR thread was not deleted */ IFX_int32_t IFXOS_ThreadShutdown( IFXOS_ThreadCtrl_t *pThrCntrl, IFX_uint32_t waitTime_ms) { IFX_uint32_t waitCnt = 1; if(pThrCntrl) { if (IFXOS_THREAD_INIT_VALID(pThrCntrl) == IFX_TRUE) { if (pThrCntrl->thrParams.bRunning == IFX_TRUE) { /* trigger user thread routine to shutdown */ pThrCntrl->thrParams.bShutDown = IFX_TRUE; if (waitTime_ms != IFXOS_THREAD_DELETE_WAIT_FOREVER) { waitCnt = waitTime_ms / IFXOS_THREAD_DOWN_WAIT_POLL_MS; } while (waitCnt && (pThrCntrl->thrParams.bRunning == IFX_TRUE) ) { IFXOS_MSecSleep(IFXOS_THREAD_DOWN_WAIT_POLL_MS); if (waitTime_ms != IFXOS_THREAD_DELETE_WAIT_FOREVER) waitCnt--; } } else { IFXOS_PRN_USR_ERR_NL( IFXOS, IFXOS_PRN_LEVEL_WRN, ("IFXOS WRN - Thread Shutdown <%s> - not running" IFXOS_CRLF, pThrCntrl->thrParams.pName)); } pThrCntrl->bValid = IFX_FALSE; IFXOS_SYS_OBJECT_RELEASE(pThrCntrl->thrParams.pSysObject); if (pThrCntrl->thrParams.bRunning != IFX_FALSE) { IFXOS_PRN_USR_ERR_NL( IFXOS, IFXOS_PRN_LEVEL_ERR, ("IFXOS ERROR - Thread Shutdown <%s> - no responce" IFXOS_CRLF, pThrCntrl->thrParams.pName)); return IFX_ERROR; } return IFX_SUCCESS; } else { IFXOS_PRN_USR_ERR_NL( IFXOS, IFXOS_PRN_LEVEL_ERR, ("IFXOS ERROR - Thread Shutdown, invalid object" IFXOS_CRLF)); } } else { IFXOS_PRN_USR_ERR_NL( IFXOS, IFXOS_PRN_LEVEL_ERR, ("IFXOS ERROR - Thread Shutdown, missing object" IFXOS_CRLF)); } return IFX_ERROR; }
/** Win32 - Shutdown and terminate a given thread. Therefore the thread delete functions triggers the user thread function to shutdown. In case of not responce (timeout) the thread will be canceled. \par Implementation - force a shutdown via the shutdown flag and wait for task end with timeout. - kill in case of no shutdown responce. - free previous allocated internal data. \param pThrCntrl - Thread control struct. \param waitTime_ms - Time [ms] to wait for "self-shutdown" of the user thread. \return - IFX_SUCCESS thread was successful deleted - thread control struct is freed. - IFX_ERROR thread was not deleted */ IFX_int32_t IFXOS_ThreadDelete( IFXOS_ThreadCtrl_t *pThrCntrl, IFX_uint32_t waitTime_ms) { IFX_uint32_t waitCnt = 1; if(pThrCntrl) { if (IFXOS_THREAD_INIT_VALID(pThrCntrl) == IFX_TRUE) { if (pThrCntrl->thrParams.bRunning == IFX_TRUE) { /* trigger user thread routine to shutdown */ pThrCntrl->thrParams.bShutDown = IFX_TRUE; if (waitTime_ms != IFXOS_THREAD_DELETE_WAIT_FOREVER) { waitCnt = waitTime_ms / IFXOS_THREAD_DOWN_WAIT_POLL_MS; } while (waitCnt && (pThrCntrl->thrParams.bRunning == IFX_TRUE) ) { IFXOS_MSecSleep(IFXOS_THREAD_DOWN_WAIT_POLL_MS); if (waitTime_ms != IFXOS_THREAD_DELETE_WAIT_FOREVER) waitCnt--; } } else { IFXOS_PRN_USR_ERR_NL( IFXOS, IFXOS_PRN_LEVEL_WRN, ("IFXOS WRN - Thread Delete <%s> - not running" IFXOS_CRLF, pThrCntrl->thrParams.pName)); } /* terminate the task if it does not terminate within given time */ if (pThrCntrl->thrParams.bRunning == IFX_TRUE) { IFXOS_PRN_USR_ERR_NL( IFXOS, IFXOS_PRN_LEVEL_WRN, ("IFXOS WRN - Thread Delete <%s> TID %d - kill, no shutdown responce" IFXOS_CRLF, pThrCntrl->thrParams.pName, pThrCntrl->tid)); if (!(CloseHandle((HANDLE)pThrCntrl->tid))) { IFXOS_PRN_USR_ERR_NL( IFXOS, IFXOS_PRN_LEVEL_ERR, ("IFXOS ERROR - Thread Delete <%s> TID %d - kill failed (mem loss ?)" IFXOS_CRLF, pThrCntrl->thrParams.pName, pThrCntrl->tid)); pThrCntrl->bValid = IFX_FALSE; IFXOS_SYS_OBJECT_RELEASE(pThrCntrl->thrParams.pSysObject); return IFX_ERROR; } pThrCntrl->thrParams.bRunning = IFX_FALSE; } pThrCntrl->bValid = IFX_FALSE; IFXOS_SYS_OBJECT_RELEASE(pThrCntrl->thrParams.pSysObject); return IFX_SUCCESS; } else { IFXOS_PRN_USR_ERR_NL( IFXOS, IFXOS_PRN_LEVEL_ERR, ("IFXOS ERROR - ThreadDelete, invalid object" IFXOS_CRLF)); } } else { IFXOS_PRN_USR_ERR_NL( IFXOS, IFXOS_PRN_LEVEL_ERR, ("IFXOS ERROR - ThreadDelete, missing object" IFXOS_CRLF)); } return IFX_ERROR; }