File tree Expand file tree Collapse file tree 4 files changed +30
-1
lines changed Expand file tree Collapse file tree 4 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -183,6 +183,8 @@ int pthread_condattr_setclock(pthread_condattr_t *att, clockid_t clock_id);
183
183
* FIXME: Only PRIO_NONE is supported. Implement other protocols.
184
184
*/
185
185
#define PTHREAD_PRIO_NONE 0
186
+ #define PTHREAD_PRIO_INHERIT 1
187
+ #define PTHREAD_PRIO_PROTECT 2
186
188
187
189
/**
188
190
* @brief POSIX threading compatibility API
Original file line number Diff line number Diff line change @@ -315,6 +315,29 @@ int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *attr,
315
315
return 0 ;
316
316
}
317
317
318
+ /**
319
+ * @brief Set protocol attribute for mutex.
320
+ *
321
+ * See IEEE 1003.1
322
+ */
323
+ int pthread_mutexattr_setprotocol (pthread_mutexattr_t * attr , int protocol )
324
+ {
325
+ if (attr == NULL ) {
326
+ return EINVAL ;
327
+ }
328
+
329
+ switch (protocol ) {
330
+ case PTHREAD_PRIO_NONE :
331
+ return 0 ;
332
+ case PTHREAD_PRIO_INHERIT :
333
+ return ENOTSUP ;
334
+ case PTHREAD_PRIO_PROTECT :
335
+ return ENOTSUP ;
336
+ default :
337
+ return EINVAL ;
338
+ }
339
+ }
340
+
318
341
int pthread_mutexattr_init (pthread_mutexattr_t * attr )
319
342
{
320
343
struct pthread_mutexattr * const a = (struct pthread_mutexattr * )attr ;
Original file line number Diff line number Diff line change @@ -63,6 +63,10 @@ static void test_mutex_common(int type, void *(*entry)(void *arg))
63
63
zassert_not_ok (pthread_mutexattr_getprotocol (NULL , & protocol ));
64
64
zassert_not_ok (pthread_mutexattr_getprotocol (& mut_attr , NULL ));
65
65
zassert_not_ok (pthread_mutexattr_getprotocol (NULL , NULL ));
66
+
67
+ zassert_not_ok (pthread_mutexattr_setprotocol (& mut_attr , PTHREAD_PRIO_INHERIT ));
68
+ zassert_not_ok (pthread_mutexattr_setprotocol (& mut_attr , PTHREAD_PRIO_PROTECT ));
69
+ zassert_ok (pthread_mutexattr_setprotocol (& mut_attr , PTHREAD_PRIO_NONE ));
66
70
zassert_ok (pthread_mutexattr_getprotocol (& mut_attr , & protocol ),
67
71
"reading mutex protocol is failed" );
68
72
zassert_ok (pthread_mutexattr_destroy (& mut_attr ));
Original file line number Diff line number Diff line change @@ -128,7 +128,7 @@ ZTEST(posix_headers, test_pthread_h)
128
128
zassert_not_null (pthread_mutexattr_gettype );
129
129
zassert_not_null (pthread_mutexattr_init );
130
130
/* zassert_not_null(pthread_mutexattr_setprioceiling); */ /* not implemented */
131
- /* zassert_not_null(pthread_mutexattr_setprotocol); */ /* not implemented */
131
+ zassert_not_null (pthread_mutexattr_setprotocol );
132
132
/* zassert_not_null(pthread_mutexattr_setpshared); */ /* not implemented */
133
133
/* zassert_not_null(pthread_mutexattr_setrobust); */ /* not implemented */
134
134
zassert_not_null (pthread_mutexattr_settype );
You can’t perform that action at this time.
0 commit comments