ipc支持send
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
#include <pthread.h>
|
||||
#include <futex.h>
|
||||
#include <assert.h>
|
||||
#include <limits.h>
|
||||
#define FT_NR 16
|
||||
|
||||
static obj_handler_t hd_futex_ipc;
|
||||
@@ -110,13 +111,65 @@ static futex_lock_t *futex_find(futex_t *ft, void *uaddr)
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
void futex_svr_thread(void)
|
||||
|
||||
static void futex_svr_thread(void)
|
||||
{
|
||||
ipc_msg_t *msg;
|
||||
uint32_t *uaddr;
|
||||
int futex_op;
|
||||
uint32_t val;
|
||||
const struct timespec *timeout; /*or val2*/
|
||||
uint32_t uaddr2;
|
||||
uint32_t val3;
|
||||
|
||||
ulog_write_str(LOG_PROT, "futex running..\n");
|
||||
thread_msg_buf_get(-1, (umword_t *)(&msg), NULL);
|
||||
while (1)
|
||||
{
|
||||
ipc_wait(hd_futex_ipc, 0);
|
||||
/*TODO:处理锁信息*/
|
||||
uaddr = (uint32_t *)(msg->msg_buf[0]);
|
||||
futex_op = msg->msg_buf[1];
|
||||
val = msg->msg_buf[2];
|
||||
timeout = (const struct timespec *)(msg->msg_buf[3]); /*or val2*/
|
||||
uaddr2 = msg->msg_buf[4];
|
||||
val3 = msg->msg_buf[5];
|
||||
|
||||
futex_op = futex_op & 0x7f;
|
||||
switch (futex_op)
|
||||
{
|
||||
case FUTEX_REQUEUE:
|
||||
{
|
||||
if (val3 == *uaddr)
|
||||
{
|
||||
futex_lock_t *flt = futex_find(&ft, uaddr);
|
||||
int rel_cnt = 0;
|
||||
int wake_cnt = 0;
|
||||
|
||||
if (flt)
|
||||
{
|
||||
wake_cnt = val = INT_MAX ? fq_queue_len(&flt->fqt) : val;
|
||||
|
||||
for (int i = 0; i < wake_cnt; i++)
|
||||
{
|
||||
obj_handler_t hd;
|
||||
int ret = fq_dequeue(&flt->fqt, &hd);
|
||||
|
||||
if (ret != 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (fq_queue_len(&flt->fqt) == 0)
|
||||
{
|
||||
flt->uaddr = 0;
|
||||
}
|
||||
/*TODO: ipc_send()*/
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
ipc_reply(hd_futex_ipc, msg_tag_init4(0, 0, 0, 0));
|
||||
}
|
||||
@@ -135,7 +188,9 @@ int be_futex(uint32_t *uaddr, int futex_op, uint32_t val,
|
||||
total = timeout->tv_sec * 1000 + timeout->tv_nsec / 1000 / 1000;
|
||||
}
|
||||
umword_t st_val;
|
||||
ipc_msg_t *msg = (ipc_msg_t *)futex_thread_msg_bug;
|
||||
ipc_msg_t *msg;
|
||||
|
||||
thread_msg_buf_get(-1, (umword_t *)(&msg), NULL);
|
||||
|
||||
msg->msg_buf[0] = (umword_t)uaddr;
|
||||
msg->msg_buf[1] = (umword_t)futex_op;
|
||||
|
||||
@@ -51,6 +51,7 @@ msg_tag_t ipc_bind(obj_handler_t obj, obj_handler_t tag_th, umword_t user_obj);
|
||||
msg_tag_t ipc_wait(obj_handler_t obj, umword_t *user_obj);
|
||||
msg_tag_t ipc_reply(obj_handler_t obj, msg_tag_t tag);
|
||||
msg_tag_t ipc_call(obj_handler_t obj, msg_tag_t in_tag, ipc_timeout_t timeout);
|
||||
msg_tag_t ipc_send(obj_handler_t obj, msg_tag_t in_tag, ipc_timeout_t timeout);
|
||||
|
||||
#define EWTIMEDOUT 131 /* Connection timed out */
|
||||
#define ERTIMEDOUT 132 /* Connection timed out */
|
||||
#define EWTIMEDOUT 131 /* Connection timed out */
|
||||
#define ERTIMEDOUT 132 /* Connection timed out */
|
||||
|
||||
@@ -11,18 +11,19 @@ enum ipc_op
|
||||
IPC_REPLY, //!< 服务端回复信息
|
||||
IPC_BIND, //!< 绑定服务端线程
|
||||
IPC_UNBIND, //!< 解除绑定
|
||||
IPC_SEND, //!< 发送数据
|
||||
};
|
||||
msg_tag_t ipc_bind(obj_handler_t obj, obj_handler_t tag_th, umword_t user_obj)
|
||||
{
|
||||
register volatile umword_t r0 asm("r0");
|
||||
|
||||
mk_syscall(syscall_prot_create(IPC_BIND, IPC_PROT, obj).raw,
|
||||
0,
|
||||
tag_th,
|
||||
user_obj,
|
||||
0,
|
||||
0,
|
||||
0);
|
||||
0,
|
||||
tag_th,
|
||||
user_obj,
|
||||
0,
|
||||
0,
|
||||
0);
|
||||
asm __volatile__(""
|
||||
:
|
||||
:
|
||||
@@ -37,12 +38,12 @@ msg_tag_t ipc_wait(obj_handler_t obj, umword_t *user_obj)
|
||||
register volatile umword_t r1 asm("r1");
|
||||
|
||||
mk_syscall(syscall_prot_create(IPC_WAIT, IPC_PROT, obj).raw,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0);
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0);
|
||||
asm __volatile__(""
|
||||
:
|
||||
:
|
||||
@@ -58,12 +59,12 @@ msg_tag_t ipc_reply(obj_handler_t obj, msg_tag_t in_tag)
|
||||
register volatile umword_t r0 asm("r0");
|
||||
|
||||
mk_syscall(syscall_prot_create(IPC_REPLY, IPC_PROT, obj).raw,
|
||||
in_tag.raw,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0);
|
||||
in_tag.raw,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0);
|
||||
asm __volatile__(""
|
||||
:
|
||||
:
|
||||
@@ -77,12 +78,12 @@ msg_tag_t ipc_call(obj_handler_t obj, msg_tag_t in_tag, ipc_timeout_t timeout)
|
||||
register volatile umword_t r0 asm("r0");
|
||||
|
||||
mk_syscall(syscall_prot_create(IPC_CALL, IPC_PROT, obj).raw,
|
||||
in_tag.raw,
|
||||
timeout.raw,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0);
|
||||
in_tag.raw,
|
||||
timeout.raw,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0);
|
||||
asm __volatile__(""
|
||||
:
|
||||
:
|
||||
@@ -90,4 +91,23 @@ msg_tag_t ipc_call(obj_handler_t obj, msg_tag_t in_tag, ipc_timeout_t timeout)
|
||||
msg_tag_t tag = msg_tag_init(r0);
|
||||
|
||||
return tag;
|
||||
}
|
||||
}
|
||||
msg_tag_t ipc_send(obj_handler_t obj, msg_tag_t in_tag, ipc_timeout_t timeout)
|
||||
{
|
||||
register volatile umword_t r0 asm("r0");
|
||||
|
||||
mk_syscall(syscall_prot_create(IPC_SEND, IPC_PROT, obj).raw,
|
||||
in_tag.raw,
|
||||
timeout.raw,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0);
|
||||
asm __volatile__(""
|
||||
:
|
||||
:
|
||||
: "r0");
|
||||
msg_tag_t tag = msg_tag_init(r0);
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
||||
@@ -24,5 +24,5 @@ void u_sleep_init(void)
|
||||
|
||||
void u_sleep_ms(size_t ms)
|
||||
{
|
||||
ipc_call(hd, msg_tag_init4(0, 0, 0, 0), ipc_timeout_create2(ms / (1000 / SYS_SCHE_HZ), 0));
|
||||
ipc_send(hd, msg_tag_init4(0, 0, 0, 0), ipc_timeout_create2(ms / (1000 / SYS_SCHE_HZ), 0));
|
||||
}
|
||||
|
||||
@@ -21,8 +21,6 @@
|
||||
extern void futex_init(void);
|
||||
int main(int argc, char *args[])
|
||||
{
|
||||
fs_backend_init();
|
||||
// futex_init();
|
||||
ulog_write_str(LOG_PROT, "init..\n");
|
||||
#if 0
|
||||
ulog_test();
|
||||
@@ -35,9 +33,9 @@ int main(int argc, char *args[])
|
||||
mm_test();
|
||||
app_test();
|
||||
mpu_test();
|
||||
ipc_test();
|
||||
thread_press_test();
|
||||
kobj_create_press_test();
|
||||
ipc_test();
|
||||
#endif
|
||||
uenv_t env = *u_get_global_env();
|
||||
obj_handler_t ipc_hd;
|
||||
|
||||
@@ -98,6 +98,7 @@ static void thread_test_func2(void)
|
||||
strcpy(buf, "I am th2.\n");
|
||||
ipc_call(ipc_hd, msg_tag_init4(0, ROUND_UP(strlen(buf), WORD_BYTES), 0, 0), ipc_timeout_create2(0, 0));
|
||||
printf("th2:%s", buf);
|
||||
// hard_sleep();
|
||||
}
|
||||
printf("thread_test_func2.\n");
|
||||
task_unmap(TASK_PROT, vpage_create_raw3(KOBJ_DELETE_RIGHT, 0, th2_hd));
|
||||
@@ -108,12 +109,14 @@ static void thread_test_func3(void)
|
||||
{
|
||||
char *buf;
|
||||
umword_t len;
|
||||
thread_msg_buf_get(th3_hd, (umword_t *)(&buf), NULL);
|
||||
thread_msg_buf_get(th3_hd, (umword_t *)(&buf), &len);
|
||||
memset(buf, 0, len);
|
||||
while (1)
|
||||
{
|
||||
strcpy(buf, "I am th3.\n");
|
||||
ipc_call(ipc_hd, msg_tag_init4(0, ROUND_UP(strlen(buf), WORD_BYTES), 0, 0), ipc_timeout_create2(0, 0));
|
||||
printf("th3:%s", buf);
|
||||
// hard_sleep();
|
||||
}
|
||||
printf("thread_test_func2.\n");
|
||||
task_unmap(TASK_PROT, vpage_create_raw3(KOBJ_DELETE_RIGHT, 0, th3_hd));
|
||||
|
||||
Reference in New Issue
Block a user