diff options
| author | bernard <[email protected]> | 2017-09-29 10:23:49 +0800 |
|---|---|---|
| committer | bernard <[email protected]> | 2017-09-29 10:23:49 +0800 |
| commit | e9a77b513f0a4b37d539a030592a61b08d03602d (patch) | |
| tree | 25dcda0b9f5d16e410179834b95c35b726de837b /src | |
| parent | b47994cb4201e158bc745bf260a47ae2dd1c497a (diff) | |
[Kernel] mutex can be used before scheduler startup.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ipc.c | 18 |
1 files changed, 10 insertions, 8 deletions
@@ -644,17 +644,18 @@ rt_err_t rt_mutex_take(rt_mutex_t mutex, rt_int32_t time) register rt_base_t temp; struct rt_thread *thread; + RT_ASSERT(mutex != RT_NULL); + + /* get current thread */ + thread = rt_thread_self(); + if (!thread) return RT_EOK; /* return directory if scheduler not started */ + /* this function must not be used in interrupt even if time = 0 */ RT_DEBUG_IN_THREAD_CONTEXT; - RT_ASSERT(mutex != RT_NULL); - /* disable interrupt */ temp = rt_hw_interrupt_disable(); - /* get current thread */ - thread = rt_thread_self(); - RT_OBJECT_HOOK_CALL(rt_object_trytake_hook, (&(mutex->parent.parent))); RT_DEBUG_LOG(RT_DEBUG_IPC, @@ -777,11 +778,12 @@ rt_err_t rt_mutex_release(rt_mutex_t mutex) need_schedule = RT_FALSE; - /* only thread could release mutex because we need test the ownership */ - RT_DEBUG_IN_THREAD_CONTEXT; - /* get current thread */ thread = rt_thread_self(); + if (!thread) return RT_EOK; + + /* only thread could release mutex because we need test the ownership */ + RT_DEBUG_IN_THREAD_CONTEXT; /* disable interrupt */ temp = rt_hw_interrupt_disable(); |
