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 "px_int.h" /* Posix helper functions */
27
28
29 /**************************************************************************/
30 /* */
31 /* FUNCTION RELEASE */
32 /* */
33 /* sem_post PORTABLE C */
34 /* 6.1.7 */
35 /* AUTHOR */
36 /* */
37 /* William E. Lamie, Microsoft Corporation */
38 /* */
39 /* DESCRIPTION */
40 /* */
41 /* This function releases/puts back a semaphore token. */
42 /* */
43 /* INPUT */
44 /* */
45 /* sem semaphore descriptor */
46 /* */
47 /* OUTPUT */
48 /* */
49 /* temp1 If successful */
50 /* ERROR If fails */
51 /* */
52 /* CALLS */
53 /* */
54 /* tx_semaphore_put ThreadX Semaphore put */
55 /* posix_internal_error Internal posix error */
56 /* */
57 /* CALLED BY */
58 /* */
59 /* Application Code */
60 /* */
61 /* RELEASE HISTORY */
62 /* */
63 /* DATE NAME DESCRIPTION */
64 /* */
65 /* 06-02-2021 William E. Lamie Initial Version 6.1.7 */
66 /* */
67 /**************************************************************************/
sem_post(sem_t * sem)68 INT sem_post(sem_t * sem)
69 {
70
71 TX_SEMAPHORE *TheSem;
72 UINT temp1;
73
74 /* Assign a temporary variable for clarity. */
75 TheSem = (TX_SEMAPHORE *)sem;
76
77 if( !TheSem || TheSem->tx_semaphore_id != TX_SEMAPHORE_ID)
78 {
79 /* Set appropriate errno. */
80 posix_errno = EINVAL;
81 posix_set_pthread_errno(EINVAL);
82 /* Return ERROR. */
83 return (EINVAL);
84 }
85
86 /* Place an instance of the semaphore. */
87 temp1 = tx_semaphore_put(TheSem);
88
89 /* Make sure the semaphore was incremented. */
90 if (temp1 != TX_SUCCESS)
91 {
92
93 /* return generic error. */
94 posix_internal_error(159);
95
96 /* Return ERROR. */
97 return (ERROR);
98 }
99
100 /* All done. */
101 return(temp1);
102 }
103