1 /*
2 * Copyright (c) 2020 Intel Corporation.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <zephyr/kernel.h>
8
9 #include "footprint.h"
10
11 #define STACK_SIZE 512
12
13 K_MUTEX_DEFINE(user_mutex);
14
15 #ifdef CONFIG_USERSPACE
user_thread_fn(void * arg1,void * arg2,void * arg3)16 static void user_thread_fn(void *arg1, void *arg2, void *arg3)
17 {
18 ARG_UNUSED(arg1);
19 ARG_UNUSED(arg2);
20 ARG_UNUSED(arg3);
21
22 k_mutex_lock(&user_mutex, K_FOREVER);
23
24 k_mutex_unlock(&user_mutex);
25 }
26
run_user_mutex(void)27 static void run_user_mutex(void)
28 {
29 k_tid_t tid;
30
31 /* Exercise simple workqueue */
32 tid = k_thread_create(&my_thread, my_stack_area, STACK_SIZE,
33 user_thread_fn, NULL, NULL, NULL,
34 0, K_USER, K_FOREVER);
35 k_object_access_grant(&user_mutex, tid);
36
37 k_thread_start(tid);
38 k_thread_join(tid, K_FOREVER);
39 }
40 #endif /* CONFIG_USERSPACE */
41
run_system_mutex(void)42 static void run_system_mutex(void)
43 {
44 struct k_mutex sys_mutex;
45
46 k_mutex_init(&sys_mutex);
47
48 k_mutex_lock(&sys_mutex, K_FOREVER);
49
50 k_mutex_unlock(&sys_mutex);
51 }
52
run_mutex(void)53 void run_mutex(void)
54 {
55 run_system_mutex();
56
57 #ifdef CONFIG_USERSPACE
58 run_user_mutex();
59 #endif
60 }
61