2017-10-03 22:31:55 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2010-2015 Wind River Systems, Inc.
|
|
|
|
* Copyright (c) 2017 Oticon A/S
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* @brief Thread support primitives
|
|
|
|
*
|
|
|
|
* This module provides core thread related primitives for the POSIX
|
|
|
|
* architecture
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <toolchain.h>
|
|
|
|
#include <kernel_structs.h>
|
2019-10-24 23:08:21 +08:00
|
|
|
#include <ksched.h>
|
2017-10-03 22:31:55 +08:00
|
|
|
#include <wait_q.h>
|
|
|
|
|
|
|
|
#include "posix_core.h"
|
2019-10-24 23:08:21 +08:00
|
|
|
#include <arch/posix/posix_soc_if.h>
|
2017-10-03 22:31:55 +08:00
|
|
|
|
2019-10-04 01:08:13 +08:00
|
|
|
/* Note that in this arch we cheat quite a bit: we use as stack a normal
|
2017-10-03 22:31:55 +08:00
|
|
|
* pthreads stack and therefore we ignore the stack size
|
|
|
|
*/
|
2019-11-08 04:43:29 +08:00
|
|
|
void arch_new_thread(struct k_thread *thread, k_thread_stack_t *stack,
|
|
|
|
size_t stack_size, k_thread_entry_t thread_func,
|
|
|
|
void *arg1, void *arg2, void *arg3,
|
|
|
|
int priority, unsigned int options)
|
2017-10-03 22:31:55 +08:00
|
|
|
{
|
|
|
|
|
2019-04-05 03:05:28 +08:00
|
|
|
char *stack_memory = Z_THREAD_STACK_BUFFER(stack);
|
2017-10-03 22:31:55 +08:00
|
|
|
|
2019-03-09 05:19:05 +08:00
|
|
|
Z_ASSERT_VALID_PRIO(priority, thread_func);
|
2017-10-03 22:31:55 +08:00
|
|
|
|
|
|
|
posix_thread_status_t *thread_status;
|
|
|
|
|
2019-03-14 23:20:46 +08:00
|
|
|
z_new_thread_init(thread, stack_memory, stack_size, priority, options);
|
2017-10-03 22:31:55 +08:00
|
|
|
|
|
|
|
/* We store it in the same place where normal archs store the
|
|
|
|
* "initial stack frame"
|
|
|
|
*/
|
|
|
|
thread_status = (posix_thread_status_t *)
|
|
|
|
STACK_ROUND_DOWN(stack_memory + stack_size
|
|
|
|
- sizeof(*thread_status));
|
|
|
|
|
2019-03-09 05:19:05 +08:00
|
|
|
/* z_thread_entry() arguments */
|
2017-10-03 22:31:55 +08:00
|
|
|
thread_status->entry_point = thread_func;
|
|
|
|
thread_status->arg1 = arg1;
|
|
|
|
thread_status->arg2 = arg2;
|
|
|
|
thread_status->arg3 = arg3;
|
|
|
|
#if defined(CONFIG_ARCH_HAS_THREAD_ABORT)
|
|
|
|
thread_status->aborted = 0;
|
|
|
|
#endif
|
|
|
|
|
2019-07-12 15:38:50 +08:00
|
|
|
thread->callee_saved.thread_status = thread_status;
|
2017-10-03 22:31:55 +08:00
|
|
|
|
|
|
|
posix_new_thread(thread_status);
|
|
|
|
}
|
|
|
|
|
|
|
|
void posix_new_thread_pre_start(void)
|
|
|
|
{
|
|
|
|
posix_irq_full_unlock();
|
|
|
|
}
|