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 /** ThreadX Component                                                     */
16 /**                                                                       */
17 /**   Semaphore                                                           */
18 /**                                                                       */
19 /**************************************************************************/
20 /**************************************************************************/
21 
22 #define TX_SOURCE_CODE
23 
24 
25 /* Include necessary system files.  */
26 
27 #include "tx_api.h"
28 #include "tx_semaphore.h"
29 
30 
31 /**************************************************************************/
32 /*                                                                        */
33 /*  FUNCTION                                               RELEASE        */
34 /*                                                                        */
35 /*    _txe_semaphore_ceiling_put                          PORTABLE C      */
36 /*                                                           6.1          */
37 /*  AUTHOR                                                                */
38 /*                                                                        */
39 /*    William E. Lamie, Microsoft Corporation                             */
40 /*                                                                        */
41 /*  DESCRIPTION                                                           */
42 /*                                                                        */
43 /*    This function checks for errors in the semaphore ceiling put        */
44 /*    function call.                                                      */
45 /*                                                                        */
46 /*  INPUT                                                                 */
47 /*                                                                        */
48 /*    semaphore_ptr                         Pointer to semaphore          */
49 /*    ceiling                               Maximum value of semaphore    */
50 /*                                                                        */
51 /*  OUTPUT                                                                */
52 /*                                                                        */
53 /*    TX_SEMAPHORE_ERROR                    Invalid semaphore pointer     */
54 /*    TX_INVALID_CEILING                    Invalid semaphore ceiling     */
55 /*    status                                Actual completion status      */
56 /*                                                                        */
57 /*  CALLS                                                                 */
58 /*                                                                        */
59 /*    _tx_semaphore_ceiling_put             Actual semaphore ceiling put  */
60 /*                                            function                    */
61 /*                                                                        */
62 /*  CALLED BY                                                             */
63 /*                                                                        */
64 /*    Application Code                                                    */
65 /*                                                                        */
66 /*  RELEASE HISTORY                                                       */
67 /*                                                                        */
68 /*    DATE              NAME                      DESCRIPTION             */
69 /*                                                                        */
70 /*  05-19-2020     William E. Lamie         Initial Version 6.0           */
71 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
72 /*                                            resulting in version 6.1    */
73 /*                                                                        */
74 /**************************************************************************/
_txe_semaphore_ceiling_put(TX_SEMAPHORE * semaphore_ptr,ULONG ceiling)75 UINT  _txe_semaphore_ceiling_put(TX_SEMAPHORE *semaphore_ptr, ULONG ceiling)
76 {
77 
78 UINT        status;
79 
80 
81     /* Check for an invalid semaphore pointer.  */
82     if (semaphore_ptr == TX_NULL)
83     {
84 
85         /* Semaphore pointer is invalid, return appropriate error code.  */
86         status =  TX_SEMAPHORE_ERROR;
87     }
88 
89     /* Now check for a valid semaphore ID.  */
90     else if (semaphore_ptr -> tx_semaphore_id != TX_SEMAPHORE_ID)
91     {
92 
93         /* Semaphore pointer is invalid, return appropriate error code.  */
94         status =  TX_SEMAPHORE_ERROR;
95     }
96 
97     /* Determine if the ceiling is valid - must be greater than 1.  */
98     else if (ceiling == ((ULONG) 0))
99     {
100 
101         /* Invalid ceiling, return error.  */
102         status =  TX_INVALID_CEILING;
103     }
104     else
105     {
106 
107         /* Call actual semaphore ceiling put function.  */
108         status =  _tx_semaphore_ceiling_put(semaphore_ptr, ceiling);
109     }
110 
111     /* Return completion status.  */
112     return(status);
113 }
114 
115