1 /* 2 * Copyright (C) 2015-2017 Alibaba Group Holding Limited 3 */ 4 5 #include "aos_cpp.h" 6 #include "aos/kernel.h" 7 #include "k_api.h" 8 #include <stdio.h> 9 10 using namespace AOS; 11 12 #define STACK_BUF_BYTES 2048 13 char stack_buf1[STACK_BUF_BYTES]; 14 15 #define BUF_QUEUE_BYTES 1024 16 17 static WorkQueue *pWorkQueue; 18 static Work * pWork1; 19 static Work * pWork2; 20 demo_task1(void * arg)21static void demo_task1(void *arg) 22 { 23 int count = 0; 24 25 while (count < 5) { 26 printf("demo_task1 count %d\n", count++); 27 28 krhino_task_sleep(RHINO_CONFIG_TICKS_PER_SECOND); 29 }; 30 } 31 demo_task2(void * arg)32static void demo_task2(void *arg) 33 { 34 int count = 0; 35 36 while (count < 5) { 37 printf("demo_task2 count %d\n", count++); 38 39 krhino_task_sleep(RHINO_CONFIG_TICKS_PER_SECOND); 40 }; 41 } 42 test_workqueue(void)43void test_workqueue(void) 44 { 45 pWorkQueue = new WorkQueue; 46 pWork1 = new Work; 47 pWork2 = new Work; 48 49 pWorkQueue->create("task", 30, (cpu_stack_t *)stack_buf1, STACK_BUF_BYTES); 50 51 pWork1->init(demo_task1, NULL, 0); 52 pWork2->init(demo_task2, NULL, 0); 53 54 pWork1->run(pWorkQueue->self()); 55 pWork2->run(pWorkQueue->self()); 56 } 57