forked from apache/nuttx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pthread/realtime: export interfaces about pthread ceiling priority
pthread_mutex_setprioceiling and pthread_mutex_getprioceiling refers https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_setprioceiling.html Signed-off-by: makejian <[email protected]>
- Loading branch information
makejian
committed
Sep 9, 2024
1 parent
f5f6f53
commit 792d3cd
Showing
12 changed files
with
354 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/**************************************************************************** | ||
* libs/libc/pthread/pthread_mutex_getprioceiling.c | ||
* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. The | ||
* ASF licenses this file to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance with the | ||
* License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
****************************************************************************/ | ||
|
||
/**************************************************************************** | ||
* Included Files | ||
****************************************************************************/ | ||
|
||
#include <nuttx/config.h> | ||
#include <nuttx/mutex.h> | ||
|
||
#include <pthread.h> | ||
|
||
/**************************************************************************** | ||
* Public Functions | ||
****************************************************************************/ | ||
|
||
/**************************************************************************** | ||
* Name: pthread_mutex_getprioceiling | ||
* | ||
* Description: | ||
* Return the mutex priority ceiling from the mutex. | ||
* | ||
* Input Parameters: | ||
* mutex - The mutex to query | ||
* prioceiling - Location to return the mutex priority ceiling | ||
* | ||
* Returned Value: | ||
* 0, if the mutex type was successfully return in 'prioceiling', or | ||
* EINVAL, if any NULL pointers provided. | ||
* | ||
* Assumptions: | ||
* | ||
****************************************************************************/ | ||
|
||
int pthread_mutex_getprioceiling(FAR const pthread_mutex_t *mutex, | ||
FAR int *prioceiling) | ||
{ | ||
#ifdef CONFIG_PRIORITY_PROTECT | ||
# ifdef CONFIG_PTHREAD_MUTEX_TYPES | ||
return -nxrmutex_getprioceiling(&mutex->mutex, prioceiling); | ||
# else | ||
return -nxmutex_getprioceiling(&mutex->mutex, prioceiling); | ||
# endif | ||
#else | ||
return EINVAL; | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/**************************************************************************** | ||
* libs/libc/pthread/pthread_mutex_setprioceiling.c | ||
* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. The | ||
* ASF licenses this file to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance with the | ||
* License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
****************************************************************************/ | ||
|
||
/**************************************************************************** | ||
* Included Files | ||
****************************************************************************/ | ||
|
||
#include <nuttx/config.h> | ||
#include <nuttx/mutex.h> | ||
|
||
#include <pthread.h> | ||
|
||
/**************************************************************************** | ||
* Public Functions | ||
****************************************************************************/ | ||
|
||
/**************************************************************************** | ||
* Name: pthread_mutex_setprioceiling | ||
* | ||
* Description: | ||
* Set the priority ceiling of a mutex. | ||
* | ||
* Input Parameters: | ||
* mutex - The mutex in which to set the mutex priority ceiling. | ||
* prioceiling - The mutex priority ceiling value to set. | ||
* old_ceiling - Location to return the mutex ceiling priority set before. | ||
* | ||
* Returned Value: | ||
* 0, indicating the mutex priority ceiling was successfully set, or | ||
* EINVAL, indicating 'mutex' or 'old_ceiling' is NULL, or 'prioceiling' | ||
* is out of range. | ||
* | ||
* Assumptions: | ||
* | ||
****************************************************************************/ | ||
|
||
int pthread_mutex_setprioceiling(FAR pthread_mutex_t *mutex, | ||
int prioceiling, FAR int *old_ceiling) | ||
{ | ||
int ret = EINVAL; | ||
|
||
#ifdef CONFIG_PRIORITY_PROTECT | ||
ret = pthread_mutex_lock(mutex); | ||
if (ret != OK) | ||
{ | ||
return ret; | ||
} | ||
|
||
# ifdef CONFIG_PTHREAD_MUTEX_TYPES | ||
ret = -nxrmutex_setprioceiling(&mutex->mutex, prioceiling, old_ceiling); | ||
# else | ||
ret = -nxmutex_setprioceiling(&mutex->mutex, prioceiling, old_ceiling); | ||
# endif | ||
pthread_mutex_unlock(mutex); | ||
#endif | ||
return ret; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/**************************************************************************** | ||
* libs/libc/pthread/pthread_mutexattr_getprioceiling.c | ||
* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. The | ||
* ASF licenses this file to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance with the | ||
* License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
****************************************************************************/ | ||
|
||
/**************************************************************************** | ||
* Included Files | ||
****************************************************************************/ | ||
|
||
#include <nuttx/config.h> | ||
#include <pthread.h> | ||
#include <errno.h> | ||
|
||
/**************************************************************************** | ||
* Public Functions | ||
****************************************************************************/ | ||
|
||
/**************************************************************************** | ||
* Name: pthread_mutexattr_getprioceiling | ||
* | ||
* Description: | ||
* Return the mutex ceiling priority from the mutex attributes. | ||
* | ||
* Input Parameters: | ||
* attr - The mutex attributes to query | ||
* prioceiling - Location to return the mutex ceiling priority | ||
* | ||
* Returned Value: | ||
* 0, if the mutex type was successfully return in 'prioceiling', or | ||
* EINVAL, if any NULL pointers provided. | ||
* | ||
* Assumptions: | ||
* | ||
****************************************************************************/ | ||
|
||
int pthread_mutexattr_getprioceiling(FAR const pthread_mutexattr_t *attr, | ||
FAR int *prioceiling) | ||
{ | ||
#ifdef CONFIG_PRIORITY_PROTECT | ||
if (attr != NULL && prioceiling != NULL) | ||
{ | ||
*prioceiling = attr->ceiling; | ||
return OK; | ||
} | ||
#endif | ||
|
||
return EINVAL; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/**************************************************************************** | ||
* libs/libc/pthread/pthread_mutexattr_setprioceiling.c | ||
* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. The | ||
* ASF licenses this file to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance with the | ||
* License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
****************************************************************************/ | ||
|
||
/**************************************************************************** | ||
* Included Files | ||
****************************************************************************/ | ||
|
||
#include <nuttx/config.h> | ||
#include <pthread.h> | ||
#include <errno.h> | ||
#include <sched.h> | ||
|
||
/**************************************************************************** | ||
* Public Functions | ||
****************************************************************************/ | ||
|
||
/**************************************************************************** | ||
* Name: pthread_mutexattr_setprioceiling | ||
* | ||
* Description: | ||
* Set the mutex ceiling priority in the mutex attributes. | ||
* | ||
* Input Parameters: | ||
* attr - The mutex attributes in which to set the mutex type. | ||
* prioceiling - The mutex ceiling priority value to set. | ||
* | ||
* Returned Value: | ||
* 0, if the mutex type was successfully set in 'attr', or | ||
* EINVAL, if 'attr' is NULL or 'prioceiling' out of range. | ||
* | ||
* Assumptions: | ||
* | ||
****************************************************************************/ | ||
|
||
int pthread_mutexattr_setprioceiling(FAR pthread_mutexattr_t *attr, | ||
int prioceiling) | ||
{ | ||
#ifdef CONFIG_PRIORITY_PROTECT | ||
if (attr && prioceiling >= sched_get_priority_min(SCHED_FIFO) && | ||
prioceiling <= sched_get_priority_max(SCHED_FIFO)) | ||
{ | ||
attr->ceiling = prioceiling; | ||
return OK; | ||
} | ||
#endif | ||
|
||
return EINVAL; | ||
} |
Oops, something went wrong.