Hi, On 02/02/2015 03:02 AM, Cunming Liang wrote: > The rte_gettid() wraps the linux and freebsd syscall gettid(). > It provides a persistent unique thread id for the calling thread. > It will save the unique id in TLS on the first time. > > [...] > > +/** > + * A wrap API for syscall gettid. > + * > + * @return > + * On success, returns the thread ID of calling process. > + * It always successful. > + */ > +int rte_sys_gettid(void); > + > +/** > + * Get system unique thread id. > + * > + * @return > + * On success, returns the thread ID of calling process. > + * It always successful. > + */ > +static inline int rte_gettid(void) > +{ > + static RTE_DEFINE_PER_LCORE(int, _thread_id) = -1; > + if (RTE_PER_LCORE(_thread_id) == -1) > + RTE_PER_LCORE(_thread_id) = rte_sys_gettid(); > + return RTE_PER_LCORE(_thread_id); > +}
Instead of doing the test each time rte_gettid() is called, why not having 2 functions: rte_init_tid() -> assign the per_lcore variable rte_gettid() -> return the per_lcore variable Regards, Olivier