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_attr_setdetachstate PORTABLE C */
34 /* 6.1.7 */
35 /* AUTHOR */
36 /* */
37 /* William E. Lamie, Microsoft Corporation */
38 /* */
39 /* DESCRIPTION */
40 /* */
41 /* This function sets the detach state attribute from a pthread */
42 /* attributes object specified.The detach state of a thread indicates */
43 /* whether the system is allowed to free thread resources when the */
44 /* thread terminates. */
45 /* The detach state specifies one of: */
46 /* PTHREAD_CREATE_DETACHED or PTHREAD_CREATE_JOINABLE. */
47 /* The default detach state (DEFAULT_DETACHSTATE) is: */
48 /* PTHREAD_CREATE_JOINABLE. */
49 /* */
50 /* INPUT */
51 /* */
52 /* attr Address of the thread attributes */
53 /* detachstate detach state to set */
54 /* */
55 /* */
56 /* OUTPUT */
57 /* */
58 /* 0 if successful */
59 /* Value in case of any error */
60 /* */
61 /* CALLS */
62 /* */
63 /* None */
64 /* */
65 /* CALLED BY */
66 /* */
67 /* Application Code */
68 /* */
69 /* RELEASE HISTORY */
70 /* */
71 /* DATE NAME DESCRIPTION */
72 /* */
73 /* 06-02-2021 William E. Lamie Initial Version 6.1.7 */
74 /* */
75 /**************************************************************************/
76
pthread_attr_setdetachstate(pthread_attr_t * attr,INT detachstate)77 INT pthread_attr_setdetachstate(pthread_attr_t *attr,INT detachstate)
78 {
79 /* First check the attribute object is already destroyed? */
80 if (attr->inuse == TX_FALSE)
81 {
82 posix_errno = EINVAL;
83 posix_set_pthread_errno(EINVAL);
84 return(EINVAL);
85 }
86 else
87 {
88 attr->detach_state = detachstate ;
89 return(OK);
90 }
91 }
92