Просмотр исходного кода

modify readme,modify the format of samples

yangjie 7 лет назад
Родитель
Сommit
e91a0ca75d
9 измененных файлов с 19 добавлено и 14 удалено
  1. 1 1
      README.md
  2. 2 1
      dynmem_sample.c
  3. 0 1
      event_sample.c
  4. 0 2
      interrupt_sample.c
  5. 9 2
      msgq_sample.c
  6. 0 2
      priority_inversion.c
  7. 1 0
      semaphore_sample.c
  8. 4 3
      thread_sample.c
  9. 2 2
      timeslice_sample.c

+ 1 - 1
README.md

@@ -16,7 +16,7 @@
 | memp_sample.c  | 内存池的使用 |
 | memp_sample.c  | 内存池的使用 |
 | msgq_sample.c | 消息队列的使用 |
 | msgq_sample.c | 消息队列的使用 |
 | mutex_sample.c  | 互斥量的使用 |
 | mutex_sample.c  | 互斥量的使用 |
-| priority_inversion.c | 优先级翻转特性 |
+| priority_inversion.c | 互斥量解决优先级翻转问题 |
 | producer_consumer.c | 生产者消费者模型 |
 | producer_consumer.c | 生产者消费者模型 |
 | scheduler_hook.c | 调度器钩子的使用 |
 | scheduler_hook.c | 调度器钩子的使用 |
 | semaphore_sample.c | 信号量的使用|
 | semaphore_sample.c | 信号量的使用|

+ 2 - 1
dynmem_sample.c

@@ -50,7 +50,7 @@ void thread1_entry(void *parameter)
 
 
 int dynmem_sample(void)
 int dynmem_sample(void)
 {
 {
-    rt_thread_t tid;
+    rt_thread_t tid = RT_NULL;
 
 
     /* 创建线程1 */
     /* 创建线程1 */
     tid = rt_thread_create("thread1",
     tid = rt_thread_create("thread1",
@@ -63,5 +63,6 @@ int dynmem_sample(void)
 
 
     return 0;
     return 0;
 }
 }
+
 /* 导出到 msh 命令列表中 */
 /* 导出到 msh 命令列表中 */
 MSH_CMD_EXPORT(dynmem_sample, dynmem sample);
 MSH_CMD_EXPORT(dynmem_sample, dynmem sample);

+ 0 - 1
event_sample.c

@@ -56,7 +56,6 @@ static void thread1_recv_event(void *param)
     rt_kprintf("thread1 leave.\n");
     rt_kprintf("thread1 leave.\n");
 }
 }
 
 
-
 ALIGN(RT_ALIGN_SIZE)
 ALIGN(RT_ALIGN_SIZE)
 static char thread2_stack[1024];
 static char thread2_stack[1024];
 static struct rt_thread thread2;
 static struct rt_thread thread2;

+ 0 - 2
interrupt_sample.c

@@ -37,7 +37,6 @@ void thread_entry(void *parameter)
     }
     }
 }
 }
 
 
-/* 用户应用程序入口 */
 int interrupt_sample(void)
 int interrupt_sample(void)
 {
 {
     rt_thread_t thread;
     rt_thread_t thread;
@@ -49,7 +48,6 @@ int interrupt_sample(void)
     if (thread != RT_NULL)
     if (thread != RT_NULL)
         rt_thread_startup(thread);
         rt_thread_startup(thread);
 
 
-
     /* 创建t2线程 */
     /* 创建t2线程 */
     thread = rt_thread_create("thread2", thread_entry, (void *)20,
     thread = rt_thread_create("thread2", thread_entry, (void *)20,
                               THREAD_STACK_SIZE,
                               THREAD_STACK_SIZE,

+ 9 - 2
msgq_sample.c

@@ -16,6 +16,9 @@
  */
  */
 #include <rtthread.h>
 #include <rtthread.h>
 
 
+#define THREAD_PRIORITY      25
+#define THREAD_TIMESLICE     5
+
 /* 消息队列控制块 */
 /* 消息队列控制块 */
 static struct rt_messagequeue mq;
 static struct rt_messagequeue mq;
 /* 消息队列中用到的放置消息的内存池 */
 /* 消息队列中用到的放置消息的内存池 */
@@ -24,6 +27,7 @@ static rt_uint8_t msg_pool[2048];
 ALIGN(RT_ALIGN_SIZE)
 ALIGN(RT_ALIGN_SIZE)
 static char thread1_stack[1024];
 static char thread1_stack[1024];
 static struct rt_thread thread1;
 static struct rt_thread thread1;
+
 /* 线程1入口函数 */
 /* 线程1入口函数 */
 static void thread1_entry(void *parameter)
 static void thread1_entry(void *parameter)
 {
 {
@@ -52,6 +56,7 @@ static void thread1_entry(void *parameter)
 ALIGN(RT_ALIGN_SIZE)
 ALIGN(RT_ALIGN_SIZE)
 static char thread2_stack[1024];
 static char thread2_stack[1024];
 static struct rt_thread thread2;
 static struct rt_thread thread2;
+
 /* 线程2入口 */
 /* 线程2入口 */
 static void thread2_entry(void *parameter)
 static void thread2_entry(void *parameter)
 {
 {
@@ -121,7 +126,8 @@ int msgq_sample(void)
                    thread1_entry,
                    thread1_entry,
                    RT_NULL,
                    RT_NULL,
                    &thread1_stack[0],
                    &thread1_stack[0],
-                   sizeof(thread1_stack), 25, 5);
+                   sizeof(thread1_stack), 
+                   THREAD_PRIORITY, THREAD_TIMESLICE);
     rt_thread_startup(&thread1);
     rt_thread_startup(&thread1);
 
 
     rt_thread_init(&thread2,
     rt_thread_init(&thread2,
@@ -129,7 +135,8 @@ int msgq_sample(void)
                    thread2_entry,
                    thread2_entry,
                    RT_NULL,
                    RT_NULL,
                    &thread2_stack[0],
                    &thread2_stack[0],
-                   sizeof(thread2_stack), 25, 5);
+                   sizeof(thread2_stack), 
+                   THREAD_PRIORITY, THREAD_TIMESLICE);
     rt_thread_startup(&thread2);
     rt_thread_startup(&thread2);
 
 
     return 0;
     return 0;

+ 0 - 2
priority_inversion.c

@@ -27,7 +27,6 @@ static rt_thread_t tid2 = RT_NULL;
 static rt_thread_t tid3 = RT_NULL;
 static rt_thread_t tid3 = RT_NULL;
 static rt_mutex_t mutex = RT_NULL;
 static rt_mutex_t mutex = RT_NULL;
 
 
-
 #define THREAD_PRIORITY       10
 #define THREAD_PRIORITY       10
 #define THREAD_STACK_SIZE     512
 #define THREAD_STACK_SIZE     512
 #define THREAD_TIMESLICE      5
 #define THREAD_TIMESLICE      5
@@ -67,7 +66,6 @@ static void thread2_entry(void *parameter)
     /* 先让低优先级线程运行 */
     /* 先让低优先级线程运行 */
     rt_thread_mdelay(50);
     rt_thread_mdelay(50);
 
 
-
     /*
     /*
      * 试图持有互斥锁,此时 thread3 持有,应把 thread3 的优先级提升
      * 试图持有互斥锁,此时 thread3 持有,应把 thread3 的优先级提升
      * 到 thread2 相同的优先级
      * 到 thread2 相同的优先级

+ 1 - 0
semaphore_sample.c

@@ -107,6 +107,7 @@ int semaphore_sample()
 
 
     return 0;
     return 0;
 }
 }
+
 /* 导出到 msh 命令列表中 */
 /* 导出到 msh 命令列表中 */
 MSH_CMD_EXPORT(semaphore_sample, semaphore sample);
 MSH_CMD_EXPORT(semaphore_sample, semaphore sample);
 
 

+ 4 - 3
thread_sample.c

@@ -9,10 +9,10 @@
  */ 
  */ 
 
 
 /*
 /*
- * 程序清单:创建/删除、初始化线程
+ * 程序清单:创建、初始化线程/脱离
  *
  *
  * 这个例子会创建两个线程,一个动态线程,一个静态线程。
  * 这个例子会创建两个线程,一个动态线程,一个静态线程。
- * 一个线程在运行完毕后自动被系统删除,另一个线程一直打印计数。
+ * 静态线程在运行完毕后自动被系统脱离,动态线程一直打印计数。
  */
  */
 #include <rtthread.h>
 #include <rtthread.h>
 
 
@@ -38,6 +38,7 @@ static void thread1_entry(void *parameter)
 ALIGN(RT_ALIGN_SIZE)
 ALIGN(RT_ALIGN_SIZE)
 static char thread2_stack[1024];
 static char thread2_stack[1024];
 static struct rt_thread thread2;
 static struct rt_thread thread2;
+
 /* 线程2入口 */
 /* 线程2入口 */
 static void thread2_entry(void *param)
 static void thread2_entry(void *param)
 {
 {
@@ -54,7 +55,7 @@ static void thread2_entry(void *param)
     (线程控制块和线程栈依然在idle线程中释放) */
     (线程控制块和线程栈依然在idle线程中释放) */
 }
 }
 
 
-/* 删除线程示例的初始化 */
+/* 线程示例 */
 int thread_sample(void)
 int thread_sample(void)
 {
 {
     /* 创建线程1,名称是thread1,入口是thread1_entry*/
     /* 创建线程1,名称是thread1,入口是thread1_entry*/

+ 2 - 2
timeslice_sample.c

@@ -43,7 +43,7 @@ static void thread_entry(void* parameter)
 
 
 int timeslice_sample(void)
 int timeslice_sample(void)
 {
 {
-    rt_thread_t tid;
+    rt_thread_t tid = RT_NULL;
     /* 创建线程1 */
     /* 创建线程1 */
     tid = rt_thread_create("thread1", 
     tid = rt_thread_create("thread1", 
                             thread_entry, (void*)1, 
                             thread_entry, (void*)1, 
@@ -52,7 +52,6 @@ int timeslice_sample(void)
     if (tid != RT_NULL) 
     if (tid != RT_NULL) 
         rt_thread_startup(tid);
         rt_thread_startup(tid);
 
 
-
     /* 创建线程2 */
     /* 创建线程2 */
     tid = rt_thread_create("thread2", 
     tid = rt_thread_create("thread2", 
                             thread_entry, (void*)2,
                             thread_entry, (void*)2,
@@ -60,6 +59,7 @@ int timeslice_sample(void)
                             THREAD_PRIORITY, THREAD_TIMESLICE-5);
                             THREAD_PRIORITY, THREAD_TIMESLICE-5);
     if (tid != RT_NULL) 
     if (tid != RT_NULL) 
         rt_thread_startup(tid);
         rt_thread_startup(tid);
+        
     return 0;
     return 0;
 }
 }