Support thread.
This commit is contained in:
@@ -26,7 +26,7 @@ INC_DIR = -I$(KERNEL_ROOT)/services/shell/letter-shell \
|
||||
-I$(KERNEL_ROOT)/services/app
|
||||
|
||||
ifeq ($(BOARD), imx6q-sabrelite)
|
||||
all: init test_fs simple_client simple_server shell fs_server test_irq_hdlr test_irq_block test_irq_send eth_driver epit_server readme.txt | bin
|
||||
all: init test_fs simple_client simple_server shell fs_server test_thread test_irq_hdlr test_irq_block test_irq_send eth_driver epit_server readme.txt | bin
|
||||
else
|
||||
all: init test_fs simple_client simple_server shell fs_server test_irq_hdlr readme.txt | bin
|
||||
endif
|
||||
@@ -52,6 +52,10 @@ epit_server: timer.o epit.o ccm_pll.o usyscall.o arch_usyscall.o libserial.o pri
|
||||
@${objdump} -S $@ > $@.asm
|
||||
endif
|
||||
|
||||
test_thread: test_thread.o libserial.o printf.o usyscall.o arch_usyscall.o
|
||||
@${ld} ${user_ldflags} -e main -o $@ $^ ${board_specs}
|
||||
@${objdump} -S $@ > $@.asm
|
||||
|
||||
test_irq_block: test_irq_block.o libserial.o printf.o libipc.o session.o usyscall.o arch_usyscall.o libmem.o
|
||||
@${ld} ${user_ldflags} -e main -o $@ $^ ${board_specs}
|
||||
@${objdump} -S $@ > $@.asm
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
#include "libserial.h"
|
||||
#include "usyscall.h"
|
||||
|
||||
static int global_value;
|
||||
|
||||
int sub_thread_entry(int argc, char** argv)
|
||||
{
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
global_value++;
|
||||
printf("[gval]: %d\n", global_value);
|
||||
}
|
||||
exit(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
global_value = 0;
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
global_value++;
|
||||
printf("|gval|: %d\n", global_value);
|
||||
}
|
||||
|
||||
char* task_param[2] = { "add_gval", NULL };
|
||||
int tid = thread(sub_thread_entry, "add_gval", task_param);
|
||||
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
global_value++;
|
||||
printf("|gval|: %d\n", global_value);
|
||||
}
|
||||
|
||||
exit(0);
|
||||
return 0;
|
||||
}
|
||||
@@ -57,7 +57,7 @@ static int InodeFreeRecursive(struct Inode* dp);
|
||||
static char* PathElementExtract(char* path, char* name);
|
||||
static uint32_t InodeBlockMapping(struct Inode* inode, uint32_t block_num);
|
||||
|
||||
#define MAX_SUPPORT_FD 2048
|
||||
#define MAX_SUPPORT_FD 4096
|
||||
static struct FileDescriptor fd_table[MAX_SUPPORT_FD];
|
||||
|
||||
struct MemFsRange MemFsRange;
|
||||
|
||||
@@ -23,7 +23,7 @@ struct CwdPair {
|
||||
struct Inode* Inode;
|
||||
};
|
||||
|
||||
#define MAX_SUPPORT_SESSION 2048
|
||||
#define MAX_SUPPORT_SESSION 4096
|
||||
static struct CwdPair session_cwd[MAX_SUPPORT_SESSION];
|
||||
|
||||
static struct CwdPair* get_session_cwd(void)
|
||||
|
||||
@@ -26,6 +26,11 @@ int spawn(struct Session* session, int fd, ipc_read_fn ipc_read, ipc_fsize_fn ip
|
||||
return ret;
|
||||
}
|
||||
|
||||
int thread(void* entry, char* name, char** argv)
|
||||
{
|
||||
return syscall(SYSCALL_THREAD, (uintptr_t)entry, (uintptr_t)name, (uintptr_t)argv, 0);
|
||||
}
|
||||
|
||||
void exit(int status)
|
||||
{
|
||||
syscall(SYSCALL_EXIT, (uintptr_t)status, 0, 0, 0);
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
#define SYSCALL_POLL_SESSION 7 // server poll for it's server sessions
|
||||
#define SYSCALL_CLOSE_SESSION 8 // client close it's client sessions
|
||||
|
||||
#define SYSCALL_EXEC 9 // run elf using current task
|
||||
#define SYSCALL_THREAD 9 // generate a thread using old memspace
|
||||
#define SYSCALL_SYS_STATE 10 // run system state
|
||||
#define SYSCALL_REGISTER_IRQ 11 //
|
||||
|
||||
@@ -65,6 +65,7 @@ typedef int (*ipc_write_fn)(struct Session* session, int fd, char* src, int offs
|
||||
int syscall(int sys_num, intptr_t a1, intptr_t a2, intptr_t a3, intptr_t a4);
|
||||
|
||||
int spawn(struct Session* session, int fd, ipc_read_fn ipc_read, ipc_fsize_fn ipc_fsize, char* name, char** argv);
|
||||
int thread(void* entry, char* name, char** argv);
|
||||
void exit(int status);
|
||||
int yield(task_yield_reason reason);
|
||||
int kill(int pid);
|
||||
|
||||
@@ -225,7 +225,7 @@
|
||||
/**
|
||||
* @brief shell默认用户
|
||||
*/
|
||||
#define SHELL_DEFAULT_USER "letter"
|
||||
#define SHELL_DEFAULT_USER "xizi"
|
||||
#endif /** SHELL_DEFAULT_USER */
|
||||
|
||||
#ifndef SHELL_DEFAULT_USER_PASSWORD
|
||||
|
||||
Reference in New Issue
Block a user