Explorar o código

kernel: add rt_critical_level that return the lock count of scheduler

Out side world may be interested in whether the scheduler is locked or
not. Provide an API to tell that.
Grissiom %!s(int64=12) %!d(string=hai) anos
pai
achega
408ac34bc2
Modificáronse 2 ficheiros con 11 adicións e 0 borrados
  1. 1 0
      include/rtthread.h
  2. 10 0
      src/scheduler.c

+ 1 - 0
include/rtthread.h

@@ -173,6 +173,7 @@ void rt_schedule_remove_thread(struct rt_thread *thread);
 
 void rt_enter_critical(void);
 void rt_exit_critical(void);
+rt_uint16_t rt_critical_level(void);
 
 #ifdef RT_USING_HOOK
 void rt_scheduler_sethook(void (*hook)(rt_thread_t from, rt_thread_t to));

+ 10 - 0
src/scheduler.c

@@ -34,6 +34,7 @@
  *                             issue found by kuronca
  * 2010-12-13     Bernard      add defunct list initialization even if not use heap.
  * 2011-05-10     Bernard      clean scheduler debug log.
+ * 2013-12-21     Grissiom     add rt_critical_level
  */
 
 #include <rtthread.h>
@@ -398,5 +399,14 @@ void rt_exit_critical(void)
     }
 }
 
+/**
+ * Get the scheduler lock level
+ *
+ * @return the level of the scheduler lock. 0 means unlocked.
+ */
+rt_uint16_t rt_critical_level(void)
+{
+    return rt_scheduler_lock_nest;
+}
 /*@}*/