1 /* thread_12.c - helper file for testing kernel mutex APIs */
2 
3 /*
4  * Copyright (c) 2015-2016 Wind River Systems, Inc.
5  *
6  * SPDX-License-Identifier: Apache-2.0
7  */
8 
9 /*
10  * @file
11  * @brief mutex test helper
12  *
13  * This module defines a thread that is used in recursive mutex locking tests.
14  * It helps ensure that a private mutex can be referenced in a file other than
15  * the one it was defined in.
16  */
17 
18 #include <zephyr/tc_util.h>
19 #include <zephyr/kernel.h>
20 #include <zephyr/sys/mutex.h>
21 
22 static int tc_rc = TC_PASS;         /* test case return code */
23 
24 extern struct sys_mutex private_mutex;
25 
26 /**
27  *
28  * thread_12 - thread that participates in recursive locking tests
29  *
30  */
31 
thread_12(void * p1,void * p2,void * p3)32 void thread_12(void *p1, void *p2, void *p3)
33 {
34 	ARG_UNUSED(p1);
35 	ARG_UNUSED(p2);
36 	ARG_UNUSED(p3);
37 
38 	int rv;
39 
40 	/* Wait for private mutex to be released */
41 
42 	rv = sys_mutex_lock(&private_mutex, K_FOREVER);
43 	if (rv != 0) {
44 		tc_rc = TC_FAIL;
45 		TC_ERROR("Failed to obtain private mutex\n");
46 		return;
47 	}
48 
49 	/* Wait a bit, then release the mutex */
50 
51 	k_sleep(K_MSEC(500));
52 	sys_mutex_unlock(&private_mutex);
53 
54 }
55