63 lines
2.7 KiB
C
63 lines
2.7 KiB
C
#ifndef __CELOXICA_CREATE_THREAD_H__
|
|
#define __CELOXICA_CREATE_THREAD_H__
|
|
|
|
#include <sched.h>
|
|
#include <pthread.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
typedef void (*utils_log_func_t) (void* priv, const char *format, ...);
|
|
|
|
/**
|
|
* \brief Create a thread to run on a given cpu set.
|
|
*
|
|
* This is a helper function that allows you to start a thread on a given cpu set. The function is designed to prevent
|
|
* potential issues arrising from starting threads when different scheduling methods are in use.
|
|
*
|
|
* Typically threads are started in one of two ways:
|
|
* 1) The thread is started and then it sets its own affinity. If schedFIFO is in use this could mean the thread does not start
|
|
* because it will inherit the affinity of its parent and not get scheduled.
|
|
* 2) The parent thread sets the affinity after the thread starts. This is not ideal because it means the thread runs on the wrong CPU
|
|
* until the parent changes it.
|
|
*
|
|
* This function will set the cpu affinity for the thread before it starts this should resolve the issues mentioned above.
|
|
*
|
|
* @param threadHandle A pointer to a pthead_t this will be used to create the thread.
|
|
* @param func The function to be started in the thread.
|
|
* @param priv The private data for func
|
|
* @param set The cpu set to use to set the cpu affinity.
|
|
* @param schedFIFO sched FIFO priority, if 0 scheduling and priority will be inherited from the parent.
|
|
* @param log The logging function called when an error occurs. Can be NULL.
|
|
* @param logPriv Private data for the logging function.
|
|
*
|
|
* @return -1 on error and 0 on success
|
|
*/
|
|
int CeloxicaCreateThread (pthread_t *threadHandle, void *(*func)(void*), void *priv, cpu_set_t set,
|
|
int schedFIFO, utils_log_func_t log, void *logPriv);
|
|
|
|
/**
|
|
* \brief Create a thread to run on a given cpu.
|
|
*
|
|
* This is a helper function is a wrapper for \ref CeloxicaCreateThread() it allows you to create a thread using the core number.
|
|
*
|
|
* @param threadHandle A pointer to a pthead_t this will be used to create the thread.
|
|
* @param func The function to be started in the thread.
|
|
* @param priv The private data for func
|
|
* @param core The core to run the thread on.
|
|
* @param schedFIFO sched FIFO priority, if 0 scheduling and priority will be inherited from the parent.
|
|
* @param log The logging function called when an error occurs. Can be NULL.
|
|
* @param logPriv Private data for the logging function.
|
|
*
|
|
* @return -1 on error and 0 on success
|
|
*/
|
|
int CeloxicaCreateThreadCore (pthread_t *threadH, void *(*func)(void*), void *priv, int core,
|
|
int schedFIFO, utils_log_func_t log, void *logPriv);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* __CELOXICA_CREATE_THREAD_H__ */
|