线程增加ipc能力,原ipc对象将修改为ipc代理功能

This commit is contained in:
zhangzheng
2023-11-26 00:15:32 +08:00
parent 782ef1331d
commit 5a0ad76ad0
16 changed files with 569 additions and 113 deletions

View File

@@ -21,13 +21,73 @@ typedef struct task task_t;
struct thread;
typedef struct thread thread_t;
#define THREAD_MSG_BUG_LEN 128UL //!< 最小的消息寄存器大小
#define MSG_BUF_HAS_DATA_FLAGS 0x01U //!< 已经有数据了
#define MSG_BUF_RECV_R_FLAGS 0x02U //!< 接收来自recv_th的消息
#define MSG_BUF_REPLY_FLAGS 0x04U //!< 回复消息给send_th
#define IPC_MSG_SIZE 96
#define MAP_BUF_SIZE 16
#define IPC_USER_SIZE 12
#if (IPC_MSG_SIZE + MAP_BUF_SIZE + IPC_USER_SIZE) > THREAD_MSG_BUG_LEN
#error "IPC MSG len error."
#endif
typedef struct ipc_msg
{
union
{
struct
{
umword_t msg_buf[IPC_MSG_SIZE / WORD_BYTES];
umword_t map_buf[MAP_BUF_SIZE / WORD_BYTES];
umword_t user[IPC_USER_SIZE / WORD_BYTES];
};
uint8_t data[THREAD_MSG_BUG_LEN];
};
} ipc_msg_t;
typedef union ipc_timeout
{
umword_t raw;
struct
{
uhmword_t send_timeout;
uhmword_t recv_timeout;
};
} ipc_timeout_t;
static inline ipc_timeout_t ipc_timeout_create2(uhmword_t send_timeout, uhmword_t recv_timeout)
{
return (ipc_timeout_t){
.send_timeout = send_timeout,
.recv_timeout = recv_timeout,
};
}
static inline ipc_timeout_t ipc_timeout_create(umword_t raw)
{
return (ipc_timeout_t){
.raw = raw,
};
}
enum thread_state
{
THREAD_IDLE, //!< 空闲状态
THREAD_DEAD, //!< 死亡状态
THREAD_SUSPEND, //!< 只有接收和发送ipc消息时才能挂起
THREAD_READY, //!< 在就绪队列中
THREAD_TODEAD, //!< 该标志标志线程马上要死亡了执行完必要操作后进入THREAD_DEAD状态
THREAD_IDLE = 0, //!< 空闲状态
THREAD_DEAD = 1, //!< 死亡状态
THREAD_SUSPEND = 2, //!< 只有接收和发送ipc消息时才能挂起
THREAD_READY = 3, //!< 在就绪队列中
THREAD_TODEAD = 4, //!< 该标志标志线程马上要死亡了执行完必要操作后进入THREAD_DEAD状态
};
enum thread_ipc_state
{
THREAD_NONE,
THREAD_SEND,
THREAD_RECV,
THREAD_WAIT,
THREAD_TIMEOUT,
THREAD_IPC_ABORT,
};
typedef struct
{
@@ -50,11 +110,6 @@ typedef struct sp_info
mword_t sp_type; //!< 使用的栈类型
} sp_info_t;
#define THREAD_MSG_BUG_LEN 128UL //!< 默认的消息寄存器大小
#define MSG_BUF_HAS_DATA_FLAGS 0x01U //!< 已经有数据了
#define MSG_BUF_RECV_R_FLAGS 0x02U //!< 接收来自recv_th的消息
#define MSG_BUF_REPLY_FLAGS 0x04U //!< 回复消息给send_th
typedef struct msg_buf
{
void *msg; //!< buf长度是固定的 @see THREAD_MSG_BUG_LEN
@@ -64,15 +119,23 @@ typedef struct msg_buf
#define THREAD_MAIGC 0xdeadead //!< 用于栈溢出检测
typedef struct thread
{
kobject_t kobj; //!< 内核对象节点
sched_t sche; //!< 调度节点
kobject_t *task; //!< 绑定的task
sp_info_t sp; //!< sp信息
ram_limit_t *lim; //!< 内存限制
ref_counter_t ref; //!< 引用计数
msg_buf_t msg; //!< 每个线程独有的消息缓存区
enum thread_state status; //!< 线程状态
umword_t magic; //!< maigc
kobject_t kobj; //!< 内核对象节点
sched_t sche; //!< 调度节点
kobject_t *task; //!< 绑定的task
sp_info_t sp; //!< sp信息
ram_limit_t *lim; //!< 内存限制
ref_counter_t ref; //!< 引用计数
msg_buf_t msg; //!< 每个线程独有的消息缓存区
slist_head_t wait_send; //!< 节点
slist_head_t wait_head; //!< 里面是等待发送给当前线程数据的线程们。
mword_t ipc_times; //!< ipc时间
thread_t *last_send_th; //!< 当前线程上次接收到谁的数据
enum thread_state status; //!< 线程状态
enum thread_ipc_state ipc_status; //!< ipc状态
umword_t magic; //!< maigc
} thread_t;
static inline void thread_set_msg_bug(thread_t *th, void *msg)
@@ -119,4 +182,6 @@ void thread_sched(void);
void thread_suspend(thread_t *th);
void thread_dead(thread_t *th);
void thread_todead(thread_t *th, bool_t is_sche);
void thread_ready(thread_t *th, bool_t is_sche);
void thread_ready(thread_t *th, bool_t is_sche);
void thread_timeout_check(ssize_t tick);