DragonOS/kernel/common/kthread.h

77 lines
2.7 KiB
C
Raw Normal View History

2022-09-30 07:30:50 +00:00
#pragma once
#include <common/numa.h>
#include <process/proc-types.h>
#include <common/err.h>
#include <process/process.h>
struct process_control_block *kthread_create_on_node(int (*thread_fn)(void *data),
void *data,
int node,
const char name_fmt[], ...);
/**
* @brief 线
*
* @param thread_fn 线
* @param data thread_fn
* @param name_fmt printf-style format string for the thread name
* @param arg name_fmt的参数
*
* 线
*/
#define kthread_create(thread_fn, data, name_fmt, arg...) \
kthread_create_on_node(thread_fn, data, NUMA_NO_NODE, name_fmt, ##arg)
/**
* @brief 线
*
* @param thread_fn 线
* @param data thread_fn
* @param name_fmt printf-style format string for the thread name
* @param arg name_fmt的参数
*/
#define kthread_run(thread_fn, data, name_fmt, ...) \
({ \
struct process_control_block *__kt = kthread_create(thread_fn, data, name_fmt, ##__VA_ARGS__); \
if (!IS_ERR(__kt)) \
process_wakeup(__kt); \
__kt; \
})
/**
* @brief kthread发送停止信号
*
* @param pcb 线pcb
* @return int
*/
int kthread_stop(struct process_control_block * pcb);
/**
* @brief 线退
*
* @return true 线退
* @return false 退
*/
bool kthread_should_stop(void);
/**
* @brief 线退result参数给kthread_stop()
*
* @param result
*/
void kthread_exit(long result);
/**
* @brief kthread机制(process_init调用)
*
* @return int
*/
int kthread_mechanism_init();
/**
* @brief pcb中的worker_private字段
*
* @param pcb pcb
* @return bool
*/
bool kthread_set_worker_private(struct process_control_block *pcb);