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_cond_init PORTABLE C */
34 /* 6.1.7 */
35 /* AUTHOR */
36 /* */
37 /* William E. Lamie, Microsoft Corporation */
38 /* */
39 /* DESCRIPTION */
40 /* */
41 /* This function shall initialize the condition variable referenced by */
42 /* cond with attributes referenced by attr. If attr is NULL,the default*/
43 /* condition variable attributes shall be used; the effect is the same */
44 /* as passing the address of a default condition variable attributes */
45 /* object. Upon successful initialization, the state of the condition */
46 /* variable shall become initialized. */
47 /* */
48 /* INPUT */
49 /* */
50 /* Nothing */
51 /* */
52 /* OUTPUT */
53 /* */
54 /* cond condition variable object */
55 /* attr attributes */
56 /* */
57 /* CALLS */
58 /* */
59 /* tx_semaphore_create create a semaphore internal to */
60 /* cond variable */
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_init(pthread_cond_t * cond,pthread_condattr_t * attr)72 INT pthread_cond_init(pthread_cond_t *cond, pthread_condattr_t *attr)
73 {
74
75 TX_SEMAPHORE *semaphore_ptr;
76 UINT status;
77
78 cond->in_use = TX_TRUE;
79 /* Get the condition variable's internal semaphore. */
80 /* Simply convert the COndition variable control block into a semaphore a cast */
81 semaphore_ptr = (&( cond->cond_semaphore ));
82 /* Now create the internal semaphore for this cond variable */
83 status = tx_semaphore_create(semaphore_ptr,"csem",0);
84 if (status != TX_SUCCESS)
85 {
86 posix_errno = EINVAL;
87 posix_set_pthread_errno(EINVAL);
88 return(EINVAL);
89 }
90 else
91 return(OK);
92 }
93