1 /***************************************************************************
2 * Copyright (c) 2024 Microsoft Corporation
3 *
4 * This program and the accompanying materials are made available under the
5 * terms of the MIT License which is available at
6 * https://opensource.org/licenses/MIT.
7 *
8 * SPDX-License-Identifier: MIT
9 **************************************************************************/
10
11
12 /**************************************************************************/
13 /**************************************************************************/
14 /** */
15 /** POSIX wrapper for THREADX */
16 /** */
17 /** */
18 /** */
19 /**************************************************************************/
20 /**************************************************************************/
21
22 /* Include necessary system files. */
23
24 #include "tx_api.h" /* Threadx API */
25 #include "pthread.h" /* Posix API */
26 #include "tx_posix.h" /* Posix API */
27 #include "px_int.h" /* Posix helper functions */
28
29
30
31 /**************************************************************************/
32 /* */
33 /* FUNCTION RELEASE */
34 /* */
35 /* sched_yield PORTABLE C */
36 /* 6.1.7 */
37 /* AUTHOR */
38 /* */
39 /* William E. Lamie, Microsoft Corporation */
40 /* */
41 /* DESCRIPTION */
42 /* */
43 /* This routine forces the running thread to relinquish the CPU */
44 /* */
45 /* INPUT */
46 /* */
47 /* void . */
48 /* */
49 /* OUTPUT */
50 /* */
51 /* OK If successful */
52 /* ERROR IF fails */
53 /* */
54 /* CALLS */
55 /* */
56 /* posix_in_thread_context Checks thread is called from its context.*/
57 /* tx_thread_relinquish Relinquishes processor control */
58 /* posix_internal_error Returns generic error */
59 /* */
60 /* CALLED BY */
61 /* */
62 /* Application Code */
63 /* */
64 /* RELEASE HISTORY */
65 /* */
66 /* DATE NAME DESCRIPTION */
67 /* */
68 /* 06-02-2021 William E. Lamie Initial Version 6.1.7 */
69 /* */
70 /**************************************************************************/
sched_yield(VOID)71 INT sched_yield(VOID)
72 {
73
74 /* Make sure we're calling this routine from a thread context. */
75 if (!posix_in_thread_context())
76 {
77 /* return POSIX error. */
78 posix_internal_error(444);
79
80 /* return error. */
81 return (ERROR);
82 }
83
84 /* This relinquishes the CPU. */
85 tx_thread_relinquish();
86 return(OK);
87 }
88