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