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