mirror of
https://github.com/Ai-Thinker-Open/Ai-Thinker-Open_RTL8710BX_ALIOS_SDK.git
synced 2026-07-14 14:05:38 +00:00
rel_1.6.0 init
This commit is contained in:
commit
27b3e2883d
19359 changed files with 8093121 additions and 0 deletions
62
Living_SDK/kernel/rhino/test/posix/posix_cond_test.c
Normal file
62
Living_SDK/kernel/rhino/test/posix/posix_cond_test.c
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
#include <k_api.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <pthread.h>
|
||||
|
||||
static pthread_t thread;
|
||||
static pthread_cond_t cond;
|
||||
static pthread_mutex_t mutex;
|
||||
static int flag = 1;
|
||||
|
||||
extern int gettimeofday(struct timeval *tv, void *tzp);
|
||||
|
||||
static void *demo_task1(void *arg)
|
||||
{
|
||||
struct timeval now;
|
||||
struct timespec outtime;
|
||||
pthread_mutex_lock(&mutex);
|
||||
while (flag)
|
||||
{
|
||||
printf("demo_task1\n");
|
||||
gettimeofday(&now, NULL);
|
||||
outtime.tv_sec = now.tv_sec + 5;
|
||||
outtime.tv_nsec = now.tv_usec * 1000;
|
||||
pthread_cond_timedwait(&cond, &mutex, &outtime);
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&mutex);
|
||||
printf("demo_task1 exit\n");
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *demo_task2(void *arg)
|
||||
{
|
||||
krhino_task_sleep(RHINO_CONFIG_TICKS_PER_SECOND*10);
|
||||
printf("Now terminate the thread!\n");
|
||||
flag = 0;
|
||||
pthread_mutex_lock(&mutex);
|
||||
pthread_cond_signal(&cond);
|
||||
pthread_mutex_unlock(&mutex);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *init_task(void *arg)
|
||||
{
|
||||
pthread_mutex_init(&mutex, NULL);
|
||||
pthread_cond_init(&cond, NULL);
|
||||
|
||||
pthread_create(&thread, NULL, demo_task1, NULL);
|
||||
pthread_create(&thread, NULL, demo_task2, NULL);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void posix_test_case4(void)
|
||||
{
|
||||
pthread_create(&thread, NULL, init_task, NULL);
|
||||
}
|
||||
|
||||
|
||||
58
Living_SDK/kernel/rhino/test/posix/posix_mutex_test.c
Normal file
58
Living_SDK/kernel/rhino/test/posix/posix_mutex_test.c
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <pthread.h>
|
||||
|
||||
static pthread_mutex_t mutex;
|
||||
|
||||
static void *init_task(void *arg)
|
||||
{
|
||||
pthread_mutex_init(&mutex, NULL);
|
||||
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *demo_task1(void *arg)
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
while (1)
|
||||
{
|
||||
pthread_mutex_lock(&mutex);
|
||||
printf("demo_task1 get sem %d\n", count++);
|
||||
};
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *demo_task2(void *arg)
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
while (1)
|
||||
{
|
||||
pthread_mutex_unlock(&mutex);
|
||||
|
||||
printf("demo_task2 release sem %d\n", count++);
|
||||
krhino_task_sleep(RHINO_CONFIG_TICKS_PER_SECOND);
|
||||
};
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void posix_test_case3(void)
|
||||
{
|
||||
pthread_t thread;
|
||||
|
||||
pthread_create(&thread, NULL, init_task, NULL);
|
||||
pthread_create(&thread, NULL, demo_task1, NULL);
|
||||
pthread_create(&thread, NULL, demo_task2, NULL);
|
||||
}
|
||||
|
||||
|
||||
|
||||
57
Living_SDK/kernel/rhino/test/posix/posix_sem_test.c
Normal file
57
Living_SDK/kernel/rhino/test/posix/posix_sem_test.c
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <pthread.h>
|
||||
#include <semaphore.h>
|
||||
|
||||
static sem_t sem;
|
||||
|
||||
static void *init_task(void *arg)
|
||||
{
|
||||
sem_init(&sem, 0, 0);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *demo_task1(void *arg)
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
while (1)
|
||||
{
|
||||
sem_wait(&sem);
|
||||
printf("demo_task1 get sem %d\n", count++);
|
||||
};
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *demo_task2(void *arg)
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
while (1)
|
||||
{
|
||||
sem_post(&sem);
|
||||
|
||||
printf("demo_task2 release sem %d\n", count++);
|
||||
krhino_task_sleep(RHINO_CONFIG_TICKS_PER_SECOND);
|
||||
};
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void posix_test_case2(void)
|
||||
{
|
||||
pthread_t thread;
|
||||
|
||||
pthread_create(&thread, NULL, init_task, NULL);
|
||||
pthread_create(&thread, NULL, demo_task1, NULL);
|
||||
pthread_create(&thread, NULL, demo_task2, NULL);
|
||||
}
|
||||
|
||||
|
||||
33
Living_SDK/kernel/rhino/test/posix/posix_task_test.c
Normal file
33
Living_SDK/kernel/rhino/test/posix/posix_task_test.c
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <pthread.h>
|
||||
|
||||
static void *demo_task(void *arg)
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
while (1)
|
||||
{
|
||||
printf("hello world! count %d\n", count++);
|
||||
|
||||
//sleep 1 second
|
||||
|
||||
krhino_task_sleep(RHINO_CONFIG_TICKS_PER_SECOND);
|
||||
};
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* test target : pthread_create() */
|
||||
void posix_test_case1(void)
|
||||
{
|
||||
pthread_t thread;
|
||||
|
||||
pthread_create(&thread, NULL, demo_task, NULL);
|
||||
}
|
||||
|
||||
19
Living_SDK/kernel/rhino/test/posix/posix_test.c
Normal file
19
Living_SDK/kernel/rhino/test/posix/posix_test.c
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
extern void posix_test_case1(void);
|
||||
extern void posix_test_case2(void);
|
||||
extern void posix_test_case3(void);
|
||||
extern void posix_test_case4(void);
|
||||
|
||||
|
||||
void posix_test_entry(void)
|
||||
{
|
||||
//posix_test_case1();
|
||||
//posix_test_case2();
|
||||
//posix_test_case3();
|
||||
//posix_test_case4();
|
||||
}
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue