@@ -88,22 +88,33 @@ static struct posix_cond *to_posix_cond(pthread_cond_t *cvar)
88
88
/* Record the associated posix_cond in mu and mark as initialized */
89
89
* cvar = mark_pthread_obj_initialized (bit );
90
90
cv = & posix_cond_pool [bit ];
91
+ (void )pthread_condattr_init ((pthread_condattr_t * )& cv -> attr );
91
92
92
93
return cv ;
93
94
}
94
95
95
- static int cond_wait (pthread_cond_t * cond , pthread_mutex_t * mu , k_timeout_t timeout )
96
+ static int cond_wait (pthread_cond_t * cond , pthread_mutex_t * mu , const struct timespec * abstime )
96
97
{
97
98
int ret ;
98
99
struct k_mutex * m ;
99
100
struct posix_cond * cv ;
101
+ k_timeout_t timeout = K_FOREVER ;
100
102
101
103
m = to_posix_mutex (mu );
102
104
cv = to_posix_cond (cond );
103
105
if (cv == NULL || m == NULL ) {
104
106
return EINVAL ;
105
107
}
106
108
109
+ if (abstime != NULL ) {
110
+ if (!timespec_is_valid (abstime )) {
111
+ LOG_DBG ("%s is invalid" , "abstime" );
112
+ return EINVAL ;
113
+ }
114
+
115
+ timeout = K_MSEC (timespec_to_clock_timeoutms (cv -> attr .clock , abstime ));
116
+ }
117
+
107
118
LOG_DBG ("Waiting on cond %p with timeout %llx" , cv , timeout .ticks );
108
119
ret = k_condvar_wait (& cv -> condvar , m , timeout );
109
120
if (ret == - EAGAIN ) {
@@ -166,24 +177,34 @@ int pthread_cond_broadcast(pthread_cond_t *cvar)
166
177
167
178
int pthread_cond_wait (pthread_cond_t * cv , pthread_mutex_t * mut )
168
179
{
169
- return cond_wait (cv , mut , K_FOREVER );
180
+ return cond_wait (cv , mut , NULL );
170
181
}
171
182
172
183
int pthread_cond_timedwait (pthread_cond_t * cv , pthread_mutex_t * mut , const struct timespec * abstime )
173
184
{
174
- return cond_wait (cv , mut , K_MSEC ( timespec_to_timeoutms ( abstime )) );
185
+ return cond_wait (cv , mut , abstime );
175
186
}
176
187
177
188
int pthread_cond_init (pthread_cond_t * cvar , const pthread_condattr_t * att )
178
189
{
179
190
struct posix_cond * cv ;
191
+ struct posix_condattr * attr = (struct posix_condattr * )attr ;
180
192
181
193
* cvar = PTHREAD_COND_INITIALIZER ;
182
194
cv = to_posix_cond (cvar );
183
195
if (cv == NULL ) {
184
196
return ENOMEM ;
185
197
}
186
198
199
+ if (attr != NULL ) {
200
+ if (!attr -> initialized ) {
201
+ return EINVAL ;
202
+ }
203
+
204
+ (void )pthread_condattr_destroy ((pthread_condattr_t * )& cv -> attr );
205
+ cv -> attr = * attr ;
206
+ }
207
+
187
208
LOG_DBG ("Initialized cond %p" , cv );
188
209
189
210
return 0 ;
0 commit comments