23 #define THREAD_LIST_LINK(tcb) \
26 struct thread *first_child; \
28 irq_local_save(&flag); \
29 INIT_LIST_HEAD(&(tcb)->child); \
30 INIT_LIST_HEAD(&(tcb)->sibling); \
32 first_child = list_entry(tcb->parent->child.next, struct thread, child); \
34 list_add_tail(&tcb->sibling, &first_child->sibling); \
36 list_add_tail(&tcb->child, &tcb->parent->child); \
39 list_add_tail(&(tcb)->link, &(tcb)->root->link); \
40 irq_local_restore(flag); \
43 #define THREAD_IS_ROOT(tcb) ((tcb)->parent == NULL && (tcb)->root == (tcb))
45 #define THREAD_LIST_INIT(tcb) \
47 INIT_LIST_HEAD(&(tcb)->sibling); \
48 INIT_LIST_HEAD(&(tcb)->child); \
49 INIT_LIST_HEAD(&(tcb)->link); \
100 static int file_entry_create(
struct object *
object,
void *data)
129 static int file_entry_destroy(
struct object *
object)
147 static int file_entry_copy(
struct object *_dest,
struct object *_src)
170 static int file_object_create(
struct object *
object,
void *data)
175 .
create = file_entry_create,
176 .destroy = file_entry_destroy,
178 .copy = file_entry_copy,
182 file =
object_get(
object,
struct file,
object);
205 dbg_printf(
"Failed to initialize entry object\n");
226 static int file_object_destroy(
struct object *
object)
231 file =
object_get(
object,
struct file,
object);
254 static int file_object_copy(
struct object *dest,
struct object *src)
256 struct file *dest_file;
257 struct file *src_file;
259 dest_file =
object_get(dest,
struct file,
object);
260 src_file =
object_get(src,
struct file,
object);
263 if (src_file->
size) {
276 if (!dest_file->
ctx) {
295 static int file_ctx_create(
struct object *
object,
void *data)
300 .
create = file_object_create,
301 .destroy = file_object_destroy,
302 .copy = file_object_copy,
315 static inline int thread_fini_file_table(
struct thread *tcb)
335 static int file_ctx_destroy(
struct object *
object)
348 static int file_ctx_copy(
struct object *_dest,
struct object *_src)
376 static inline int thread_init_file_table(
struct thread *tcb)
378 const char *dev_node;
383 .
create = file_ctx_create,
384 .destroy = file_ctx_destroy,
385 .copy = file_ctx_copy,
403 dbg_printf(
"Failed to create a file context\n");
411 dev_node =
getenv(
"stdin");
414 info.
path = dev_node;
423 dev_node =
getenv(
"stdout");
426 info.
path = dev_node;
431 dbg_printf(
"Failed to initiate the STDOUT\n");
435 dev_node =
getenv(
"stderr");
438 info.
path = dev_node;
443 dbg_printf(
"Failed to initiate the STDERR\n");
450 static inline int destroy_stack(
struct thread *tcb)
461 static inline int allocate_stack(
struct thread *tcb)
497 ret = allocate_stack(tcb);
499 dbg_printf(
"Heap is not allocated: %d\n", ret);
505 local_tcb = (
struct local_tcb *)tmp;
522 static int thread_object_create(
struct object *
object,
void *_attr)
532 ret = create_stack(tcb, attr);
538 ret = thread_init_file_table(tcb);
549 thread_fini_file_table(tcb);
572 static int thread_object_destroy(
struct object *
object)
582 list_del(&tcb->
link);
607 list_link(&tmp->
sibling, end_of_sibling);
622 list_link(&tmp->
sibling, end_of_sibling);
627 thread_fini_file_table(tcb);
634 static int thread_object_copy(
struct object *_dest,
struct object *_src)
658 static struct object *thread_object_link(
struct object *
object)
674 .
create = thread_object_create,
675 .destroy = thread_object_destroy,
676 .copy = thread_object_copy,
677 .link = thread_object_link,
695 assert(tcb &&
"Invalid argument");
701 assert(tcb &&
"Invalid argument");
707 unsigned long stack_pointer;
709 assert(tcb &&
"Invalid argument");
714 return stack_pointer;
719 assert(tcb &&
"Invalid argument");
725 assert(tcb &&
"Invalid argument");