-
Notifications
You must be signed in to change notification settings - Fork 5.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: ipc: add nested-free flag support to mutex #9529
Open
polarvid
wants to merge
1
commit into
RT-Thread:master
Choose a base branch
from
polarvid:shell/nested-free-mtx
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -980,6 +980,23 @@ static void _mutex_before_delete_detach(rt_mutex_t mutex) | |
* @{ | ||
*/ | ||
|
||
static void _mutex_init(rt_mutex_t mutex, rt_uint8_t ctrl_flags) | ||
{ | ||
/* initialize ipc object */ | ||
_ipc_object_init(&(mutex->parent)); | ||
|
||
mutex->owner = RT_NULL; | ||
mutex->priority = 0xFF; | ||
mutex->hold = 0; | ||
mutex->ceiling_priority = 0xFF; | ||
mutex->ctrl_flags = ctrl_flags; | ||
rt_list_init(&(mutex->taken_list)); | ||
|
||
/* flag can only be RT_IPC_FLAG_PRIO. RT_IPC_FLAG_FIFO cannot solve the unbounded priority inversion problem */ | ||
mutex->parent.parent.flag = RT_IPC_FLAG_PRIO; | ||
rt_spin_lock_init(&(mutex->spinlock)); | ||
} | ||
|
||
/** | ||
* @brief Initialize a static mutex object. | ||
* | ||
|
@@ -1004,29 +1021,15 @@ static void _mutex_before_delete_detach(rt_mutex_t mutex) | |
* | ||
* @warning This function can ONLY be called from threads. | ||
*/ | ||
rt_err_t rt_mutex_init(rt_mutex_t mutex, const char *name, rt_uint8_t flag) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 不建议更换flag的形参名称,这回把用户搞蒙。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
rt_err_t rt_mutex_init(rt_mutex_t mutex, const char *name, rt_uint8_t ctrl_flag) | ||
{ | ||
/* flag parameter has been obsoleted */ | ||
RT_UNUSED(flag); | ||
|
||
/* parameter check */ | ||
RT_ASSERT(mutex != RT_NULL); | ||
|
||
/* initialize object */ | ||
rt_object_init(&(mutex->parent.parent), RT_Object_Class_Mutex, name); | ||
|
||
/* initialize ipc object */ | ||
_ipc_object_init(&(mutex->parent)); | ||
|
||
mutex->owner = RT_NULL; | ||
mutex->priority = 0xFF; | ||
mutex->hold = 0; | ||
mutex->ceiling_priority = 0xFF; | ||
rt_list_init(&(mutex->taken_list)); | ||
|
||
/* flag can only be RT_IPC_FLAG_PRIO. RT_IPC_FLAG_FIFO cannot solve the unbounded priority inversion problem */ | ||
mutex->parent.parent.flag = RT_IPC_FLAG_PRIO; | ||
rt_spin_lock_init(&(mutex->spinlock)); | ||
_mutex_init(mutex, ctrl_flag); | ||
|
||
return RT_EOK; | ||
} | ||
|
@@ -1230,32 +1233,18 @@ RTM_EXPORT(rt_mutex_getprioceiling); | |
* | ||
* @warning This function can ONLY be called from threads. | ||
*/ | ||
rt_mutex_t rt_mutex_create(const char *name, rt_uint8_t flag) | ||
rt_mutex_t rt_mutex_create(const char *name, rt_uint8_t ctrl_flags) | ||
{ | ||
struct rt_mutex *mutex; | ||
|
||
/* flag parameter has been obsoleted */ | ||
RT_UNUSED(flag); | ||
|
||
RT_DEBUG_NOT_IN_INTERRUPT; | ||
|
||
/* allocate object */ | ||
mutex = (rt_mutex_t)rt_object_allocate(RT_Object_Class_Mutex, name); | ||
if (mutex == RT_NULL) | ||
return mutex; | ||
|
||
/* initialize ipc object */ | ||
_ipc_object_init(&(mutex->parent)); | ||
|
||
mutex->owner = RT_NULL; | ||
mutex->priority = 0xFF; | ||
mutex->hold = 0; | ||
mutex->ceiling_priority = 0xFF; | ||
rt_list_init(&(mutex->taken_list)); | ||
|
||
/* flag can only be RT_IPC_FLAG_PRIO. RT_IPC_FLAG_FIFO cannot solve the unbounded priority inversion problem */ | ||
mutex->parent.parent.flag = RT_IPC_FLAG_PRIO; | ||
rt_spin_lock_init(&(mutex->spinlock)); | ||
_mutex_init(mutex, ctrl_flags); | ||
|
||
return mutex; | ||
} | ||
|
@@ -1351,7 +1340,8 @@ static rt_err_t _rt_mutex_take(rt_mutex_t mutex, rt_int32_t timeout, int suspend | |
|
||
if (mutex->owner == thread) | ||
{ | ||
if (mutex->hold < RT_MUTEX_HOLD_MAX) | ||
if (!(mutex->ctrl_flags & RT_MTX_CTRL_FLAG_NO_RECUR) && | ||
mutex->hold < RT_MUTEX_HOLD_MAX) | ||
{ | ||
/* it's the same thread */ | ||
mutex->hold ++; | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.