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