* @brief Set the scheduling policy and parameters for a thread. * * This function sets the scheduling policy and associated parameters for the specified thread. * It allows controlling the scheduling behavior of threads. * * @param[in] tid The thread ID of the target thread. * @param[in] policy The scheduling policy to be applied. Common values include: * - `SCHED_FIFO`
| 8936 | * Ensure the `param` structure is properly initialized for the given `policy`. |
| 8937 | */ |
| 8938 | sysret_t sys_sched_setscheduler(int tid, int policy, void *param) |
| 8939 | { |
| 8940 | sysret_t ret; |
| 8941 | struct sched_param *sched_param = RT_NULL; |
| 8942 | rt_thread_t thread = RT_NULL; |
| 8943 | |
| 8944 | if (!lwp_user_accessable(param, sizeof(struct sched_param))) |
| 8945 | { |
| 8946 | return -EFAULT; |
| 8947 | } |
| 8948 | |
| 8949 | sched_param = kmem_get(sizeof(struct sched_param)); |
| 8950 | if (sched_param == RT_NULL) |
| 8951 | { |
| 8952 | return -ENOMEM; |
| 8953 | } |
| 8954 | |
| 8955 | if (lwp_get_from_user(sched_param, param, sizeof(struct sched_param)) != sizeof(struct sched_param)) |
| 8956 | { |
| 8957 | kmem_put(sched_param); |
| 8958 | return -EINVAL; |
| 8959 | } |
| 8960 | |
| 8961 | thread = lwp_tid_get_thread_and_inc_ref(tid); |
| 8962 | ret = rt_thread_control(thread, RT_THREAD_CTRL_RESET_PRIORITY, (void *)&sched_param->sched_priority); |
| 8963 | lwp_tid_dec_ref(thread); |
| 8964 | |
| 8965 | kmem_put(sched_param); |
| 8966 | |
| 8967 | return ret; |
| 8968 | } |
| 8969 | |
| 8970 | /** |
| 8971 | * @brief Get the scheduling policy of a thread. |
nothing calls this directly
no test coverage detected