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 /*    pthread_mutexattr_destroy                           PORTABLE C      */
34 /*                                                           6.1.7        */
35 /*  AUTHOR                                                                */
36 /*                                                                        */
37 /*    William E. Lamie, Microsoft Corporation                             */
38 /*                                                                        */
39 /*  DESCRIPTION                                                           */
40 /*                                                                        */
41 /*     This function shall destroy a mutex attributes object; the object  */
42 /*     becomes,in effect,uninitialized.A destroyed attr attributes object */
43 /*     can be reinitialized using pthread_mutexattr_init();               */
44 /*                                                                        */
45 /*                                                                        */
46 /*  INPUT                                                                 */
47 /*                                                                        */
48 /*    attr                           Address of the mutex attributes      */
49 /*                                   object to be destroyed.              */
50 /*                                                                        */
51 /*  OUTPUT                                                                */
52 /*                                                                        */
53 /*     0                             If successful                        */
54 /*     Value                         In case of any error or the results  */
55 /*                                   of referencing the object after it   */
56 /*                                   has been destroyed.                  */
57 /*                                                                        */
58 /*  CALLS                                                                 */
59 /*                                                                        */
60 /*    None                                                                */
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_mutexattr_destroy(pthread_mutexattr_t * attr)73 INT pthread_mutexattr_destroy(pthread_mutexattr_t *attr)
74 {
75 
76     /* Clear the flag and make this pthread_mutexattr structure free */
77     /* First check the attribute object is already destroyed? */
78     if (attr->in_use == TX_FALSE)
79     {
80         posix_errno = EINVAL;
81 	    posix_set_pthread_errno(EINVAL);
82         return(EINVAL);
83     }
84     else
85     {
86         /* No then destroy the attributes object */
87         attr->in_use = TX_FALSE;
88         return(OK);
89     }
90 }
91