@@ -227,11 +227,18 @@ static int pthread_cond_pool_init(void)
227
227
228
228
int pthread_condattr_init (pthread_condattr_t * att )
229
229
{
230
- __ASSERT_NO_MSG (att != NULL );
231
-
232
230
struct posix_condattr * const attr = (struct posix_condattr * )att ;
233
231
232
+ if (att == NULL ) {
233
+ return EINVAL ;
234
+ }
235
+ if (attr -> initialized ) {
236
+ LOG_DBG ("%s %s initialized" , "attribute" , "already" );
237
+ return EINVAL ;
238
+ }
239
+
234
240
attr -> clock = CLOCK_MONOTONIC ;
241
+ attr -> initialized = true;
235
242
236
243
return 0 ;
237
244
}
@@ -240,7 +247,8 @@ int pthread_condattr_destroy(pthread_condattr_t *att)
240
247
{
241
248
struct posix_condattr * const attr = (struct posix_condattr * )att ;
242
249
243
- if (attr == NULL ) {
250
+ if ((attr == NULL ) || !attr -> initialized ) {
251
+ LOG_DBG ("%s %s initialized" , "attribute" , "not" );
244
252
return EINVAL ;
245
253
}
246
254
@@ -254,6 +262,11 @@ int pthread_condattr_getclock(const pthread_condattr_t *ZRESTRICT att,
254
262
{
255
263
struct posix_condattr * const attr = (struct posix_condattr * )att ;
256
264
265
+ if ((attr == NULL ) || !attr -> initialized ) {
266
+ LOG_DBG ("%s %s initialized" , "attribute" , "not" );
267
+ return EINVAL ;
268
+ }
269
+
257
270
* clock_id = attr -> clock ;
258
271
259
272
return 0 ;
@@ -267,6 +280,11 @@ int pthread_condattr_setclock(pthread_condattr_t *att, clockid_t clock_id)
267
280
return - EINVAL ;
268
281
}
269
282
283
+ if ((attr == NULL ) || !attr -> initialized ) {
284
+ LOG_DBG ("%s %s initialized" , "attribute" , "not" );
285
+ return EINVAL ;
286
+ }
287
+
270
288
attr -> clock = clock_id ;
271
289
272
290
return 0 ;
0 commit comments