rel_1.6.0 init

This commit is contained in:
guocheng.kgc 2020-06-18 20:06:52 +08:00 committed by shengdong.dsd
commit 27b3e2883d
19359 changed files with 8093121 additions and 0 deletions

View 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);
}

View 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);
}

View 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);
}

View 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);
}

View 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();
}