MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / _lwp_setaffinity

Function _lwp_setaffinity

components/lwp/lwp_pid.c:2242–2258  ·  view source on GitHub ↗

* @brief Set CPU affinity for a thread * * @param[in] tid The thread ID to set affinity for * @param[in] cpu The target CPU core number * * @return 0 on success, -1 on failure (invalid thread ID) * * @note This function binds a thread to a specific CPU core in SMP systems. * It handles thread reference counting and returns operation status. */

Source from the content-addressed store, hash-verified

2240 * It handles thread reference counting and returns operation status.
2241 */
2242static int _lwp_setaffinity(int tid, int cpu)
2243{
2244 rt_thread_t thread;
2245 int ret = -1;
2246
2247 thread = lwp_tid_get_thread_and_inc_ref(tid);
2248
2249 if (thread)
2250 {
2251#ifdef RT_USING_SMP
2252 rt_thread_control(thread, RT_THREAD_CTRL_BIND_CPU, (void *)(rt_ubase_t)cpu);
2253#endif
2254 ret = 0;
2255 }
2256 lwp_tid_dec_ref(thread);
2257 return ret;
2258}
2259
2260/**
2261 * @brief Sets CPU affinity for a thread

Callers 1

lwp_setaffinityFunction · 0.85

Calls 3

rt_thread_controlFunction · 0.85
lwp_tid_dec_refFunction · 0.85

Tested by

no test coverage detected