Skip to content
This repository has been archived by the owner on Sep 21, 2021. It is now read-only.

Commit

Permalink
thread: allow creating thread with automatic priority
Browse files Browse the repository at this point in the history
  • Loading branch information
misson20000 committed Sep 13, 2018
1 parent c4c5db4 commit d80eb0b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion include/libtransistor/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ typedef struct {
* @param thread Structure to initialize
* @param entry Entry function for thread
* @param arg Second argument to thread entry function
* @param priority Priority of the newly created thread. Must be between 0x00 and 0x3F.
* @param priority Priority of the newly created thread. Must be between 0x00 and 0x3F. Use -1 for same as current thread.
* @param processor_id Which processor the newly created thread will run on. Use -2 for don't care.
* @param stack_size Size of the stack.
* @param stack_bottom Bottom of a pre-allocated stack. If this is NULL, a new stack will be allocated via \ref alloc_pages.
Expand Down
9 changes: 7 additions & 2 deletions lib/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ result_t trn_thread_create(trn_thread_t *thread,
int32_t processor_id,
size_t stack_size,
void *stack_bottom) {
result_t r;
if(priority == -1) {
LIB_ASSERT_OK(fail, svcGetThreadPriority(&priority, 0xffff8000));
}

if(stack_bottom == NULL) {
thread->owns_stack = true;
thread->stack_bottom = alloc_pages(stack_size, stack_size, &thread->stack_size);
Expand All @@ -35,12 +40,11 @@ result_t trn_thread_create(trn_thread_t *thread,
thread->stack_bottom = stack_bottom;
thread->stack_size = stack_size;
}

thread->entry = entry;
thread->arg = arg;
thread->pthread = NULL;

result_t r;
LIB_ASSERT_OK(fail_stack, svcCreateThread(&thread->handle, &trn_thread_entry, thread, thread->stack_bottom + thread->stack_size, priority, processor_id));

return RESULT_OK;
Expand All @@ -49,6 +53,7 @@ result_t trn_thread_create(trn_thread_t *thread,
if(thread->owns_stack) {
free_pages(thread->stack_bottom);
}
fail:
return r;
}

Expand Down

0 comments on commit d80eb0b

Please sign in to comment.