1 /**************************************************************************/
2 /* */
3 /* Copyright (c) Microsoft Corporation. All rights reserved. */
4 /* */
5 /* This software is licensed under the Microsoft Software License */
6 /* Terms for Microsoft Azure RTOS. Full text of the license can be */
7 /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
8 /* and in the root directory of this software. */
9 /* */
10 /**************************************************************************/
11
12
13 /**************************************************************************/
14 /**************************************************************************/
15 /** */
16 /** POSIX wrapper for THREADX */
17 /** */
18 /** */
19 /** */
20 /**************************************************************************/
21 /**************************************************************************/
22
23 /* Include necessary system files. */
24
25 #include "tx_api.h" /* Threadx API */
26 #include "pthread.h" /* Posix API */
27 #include "px_int.h" /* Posix helper functions */
28
29
30 /**************************************************************************/
31 /* */
32 /* FUNCTION RELEASE */
33 /* */
34 /* sem_post PORTABLE C */
35 /* 6.1.7 */
36 /* AUTHOR */
37 /* */
38 /* William E. Lamie, Microsoft Corporation */
39 /* */
40 /* DESCRIPTION */
41 /* */
42 /* This function releases/puts back a semaphore token. */
43 /* */
44 /* INPUT */
45 /* */
46 /* sem semaphore descriptor */
47 /* */
48 /* OUTPUT */
49 /* */
50 /* temp1 If successful */
51 /* ERROR If fails */
52 /* */
53 /* CALLS */
54 /* */
55 /* tx_semaphore_put ThreadX Semaphore put */
56 /* posix_internal_error Internal posix error */
57 /* */
58 /* CALLED BY */
59 /* */
60 /* Application Code */
61 /* */
62 /* RELEASE HISTORY */
63 /* */
64 /* DATE NAME DESCRIPTION */
65 /* */
66 /* 06-02-2021 William E. Lamie Initial Version 6.1.7 */
67 /* */
68 /**************************************************************************/
sem_post(sem_t * sem)69 INT sem_post(sem_t * sem)
70 {
71
72 TX_SEMAPHORE *TheSem;
73 UINT temp1;
74
75 /* Assign a temporary variable for clarity. */
76 TheSem = (TX_SEMAPHORE *)sem;
77
78 if( !TheSem || TheSem->tx_semaphore_id != TX_SEMAPHORE_ID)
79 {
80 /* Set appropriate errno. */
81 posix_errno = EINVAL;
82 posix_set_pthread_errno(EINVAL);
83 /* Return ERROR. */
84 return (EINVAL);
85 }
86
87 /* Place an instance of the semaphore. */
88 temp1 = tx_semaphore_put(TheSem);
89
90 /* Make sure the semaphore was incremented. */
91 if (temp1 != TX_SUCCESS)
92 {
93
94 /* return generic error. */
95 posix_internal_error(159);
96
97 /* Return ERROR. */
98 return (ERROR);
99 }
100
101 /* All done. */
102 return(temp1);
103 }
104