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 /* */
32 /* FUNCTION RELEASE */
33 /* */
34 /* pthread_cond_signal PORTABLE C */
35 /* 6.1.7 */
36 /* AUTHOR */
37 /* */
38 /* William E. Lamie, Microsoft Corporation */
39 /* */
40 /* DESCRIPTION */
41 /* */
42 /* This function shall unblock at least one of the threads that are */
43 /* blocked on the specified condition variable cond */
44 /* (if any threads are blocked on cond).If more than one thread is */
45 /* blocked on a condition variable, the scheduling policy shall */
46 /* determine the order in which threads are unblocked.When each thread */
47 /* unblocked as a result of a pthread_cond_signal returns from its call*/
48 /* to pthread_cond_wait or pthread_cond_timedwait, the thread shall own*/
49 /* the mutex with which it called pthread_cond_wait or */
50 /* pthread_cond_timedwait.The thread(s) that are unblocked shall */
51 /* contend for the mutex according to the scheduling policy */
52 /* (if applicable), and as if each had called pthread_mutex_lock. */
53 /* The pthread_cond_broadcast or pthread_cond_signal functions may be */
54 /* called by a thread whether or not it currently owns the mutex that */
55 /* threads calling pthread_cond_wait or pthread_cond_timedwait have */
56 /* associated with the condition variable during their waits; however, */
57 /* if predictable scheduling behavior is required,then that mutex shall*/
58 /* be locked by the thread calling pthread_cond_signal. */
59 /* This function shall have no effect if there are no threads currently*/
60 /* blocked on cond. */
61 /* */
62 /* INPUT */
63 /* */
64 /* Nothing */
65 /* */
66 /* OUTPUT */
67 /* */
68 /* Nothing */
69 /* */
70 /* CALLS */
71 /* */
72 /* tx_semaphore_prioritize line up pthreads waiting at semaphore*/
73 /* tx_semaphore_put ThreadX semaphore put service */
74 /* */
75 /* CALLED BY */
76 /* */
77 /* Application Code */
78 /* */
79 /* RELEASE HISTORY */
80 /* */
81 /* DATE NAME DESCRIPTION */
82 /* */
83 /* 06-02-2021 William E. Lamie Initial Version 6.1.7 */
84 /* */
85 /**************************************************************************/
pthread_cond_signal(pthread_cond_t * cond)86 INT pthread_cond_signal(pthread_cond_t *cond)
87 {
88
89 TX_SEMAPHORE *semaphore_ptr;
90 UINT status;
91
92 /* Get the condition variable's internal semaphore. */
93 /* Simply convert the COndition variable control block into a semaphore a cast */
94 semaphore_ptr = (&( cond->cond_semaphore ));
95 if ( semaphore_ptr->tx_semaphore_suspended_count)
96 {
97 status = tx_semaphore_prioritize(semaphore_ptr);
98 if ( status != TX_SUCCESS)
99 {
100 posix_errno = EINVAL;
101 posix_set_pthread_errno(EINVAL);
102 return(EINVAL);
103 }
104 status = tx_semaphore_put(semaphore_ptr);
105 if ( status != TX_SUCCESS)
106 {
107 posix_errno = EINVAL;
108 posix_set_pthread_errno(EINVAL);
109 return(EINVAL);
110 }
111 }
112 return(OK);
113 }
114