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 /*  FUNCTION                                               RELEASE        */
32 /*                                                                        */
33 /*  pthread_cond_destroy                                  PORTABLE C      */
34 /*                                                           6.1.7        */
35 /*  AUTHOR                                                                */
36 /*                                                                        */
37 /*    William E. Lamie, Microsoft Corporation                             */
38 /*                                                                        */
39 /*  DESCRIPTION                                                           */
40 /*                                                                        */
41 /*    The pthread_cond_destroy function shall destroy the given condition */
42 /*    variable specified by cond; the object becomes, in effect,          */
43 /*    uninitialized.                                                      */
44 /*    A destroyed condition variable object can be reinitialized using    */
45 /*    pthread_cond_init;referencing the object after it has been destroyed*/
46 /*    returns error.                                                      */
47 /*                                                                        */
48 /*  INPUT                                                                 */
49 /*                                                                        */
50 /*     cond                               condition variable object       */
51 /*                                                                        */
52 /*  OUTPUT                                                                */
53 /*                                                                        */
54 /*     OK                                 If successful                   */
55 /*     EINVAL                             If error                        */
56 /*                                                                        */
57 /*  CALLS                                                                 */
58 /*                                                                        */
59 /*     tx_semaphore_delete                Deletes a semaphore internal to */
60 /*                                        to the cond variable            */
61 /*                                                                        */
62 /*  CALLED BY                                                             */
63 /*                                                                        */
64 /*    Application Code                                                    */
65 /*                                                                        */
66 /*  RELEASE HISTORY                                                       */
67 /*                                                                        */
68 /*    DATE              NAME                      DESCRIPTION             */
69 /*                                                                        */
70 /*  06-02-2021     William E. Lamie         Initial Version 6.1.7         */
71 /*                                                                        */
72 /**************************************************************************/
pthread_cond_destroy(pthread_cond_t * cond)73 INT    pthread_cond_destroy(pthread_cond_t *cond)
74 {
75 
76 TX_SEMAPHORE     *semaphore_ptr;
77 UINT              status;
78 
79     if (cond->in_use == TX_FALSE)
80     {
81         posix_errno = EINVAL;
82         posix_set_pthread_errno(EINVAL);
83         return(EINVAL);
84     }
85     else
86     {
87         cond->in_use = TX_FALSE;
88         /* Get the condition variable's internal semaphore.  */
89         /* Simply convert the Condition variable control block into a semaphore  a cast */
90         semaphore_ptr = (&( cond->cond_semaphore ));
91         status = tx_semaphore_delete(semaphore_ptr);
92         if (status != TX_SUCCESS)
93         {
94             posix_errno = EINVAL;
95 	        posix_set_pthread_errno(EINVAL);
96             return(EINVAL);
97         }
98         return(OK);
99     }
100 }
101 
102