mirror of
https://github.com/open5gs/open5gs.git
synced 2026-05-05 23:37:22 +00:00
therad_join, thread_exit, thread_yeild is added
This commit is contained in:
parent
bfb3fdcae3
commit
7e1b469c3d
9 changed files with 108 additions and 46 deletions
|
|
@ -10,10 +10,10 @@
|
|||
#define MAX_COUNTER 10000
|
||||
#define MAX_RETRY 3
|
||||
|
||||
static void *THREAD_FUNC thread_rwlock_func(void *data);
|
||||
static void *THREAD_FUNC thread_mutex_function(void *data);
|
||||
static void *THREAD_FUNC thread_cond_producer(void *data);
|
||||
static void *THREAD_FUNC thread_cond_consumer(void *data);
|
||||
static void *THREAD_FUNC thread_rwlock_func(thread_id id, void *data);
|
||||
static void *THREAD_FUNC thread_mutex_function(thread_id id, void *data);
|
||||
static void *THREAD_FUNC thread_cond_producer(thread_id id, void *data);
|
||||
static void *THREAD_FUNC thread_cond_consumer(thread_id id, void *data);
|
||||
|
||||
static mutex_id mutex;
|
||||
static rwlock_id rwlock;
|
||||
|
|
@ -37,7 +37,7 @@ struct {
|
|||
static mutex_id timeout_mutex;
|
||||
static cond_id timeout_cond;
|
||||
|
||||
static void *THREAD_FUNC thread_rwlock_func(void *data)
|
||||
static void *THREAD_FUNC thread_rwlock_func(thread_id id, void *data)
|
||||
{
|
||||
int exitLoop = 1;
|
||||
|
||||
|
|
@ -62,7 +62,7 @@ static void *THREAD_FUNC thread_rwlock_func(void *data)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static void *THREAD_FUNC thread_mutex_function(void *data)
|
||||
static void *THREAD_FUNC thread_mutex_function(thread_id id, void *data)
|
||||
{
|
||||
int exitLoop = 1;
|
||||
|
||||
|
|
@ -87,7 +87,7 @@ static void *THREAD_FUNC thread_mutex_function(void *data)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static void *THREAD_FUNC thread_cond_producer(void *data)
|
||||
static void *THREAD_FUNC thread_cond_producer(thread_id id, void *data)
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
|
|
@ -114,7 +114,7 @@ static void *THREAD_FUNC thread_cond_producer(void *data)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static void *THREAD_FUNC thread_cond_consumer(void *data)
|
||||
static void *THREAD_FUNC thread_cond_consumer(thread_id id, void *data)
|
||||
{
|
||||
int i;
|
||||
|
||||
|
|
@ -133,7 +133,7 @@ static void *THREAD_FUNC thread_cond_consumer(void *data)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static void *THREAD_FUNC thread_semaphore_function(void *data)
|
||||
static void *THREAD_FUNC thread_semaphore_function(thread_id id, void *data)
|
||||
{
|
||||
int exitLoop = 1;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,24 +1,6 @@
|
|||
#include "core_msgq.h"
|
||||
#include "testutil.h"
|
||||
|
||||
#if 0
|
||||
static thread_id *s1;
|
||||
static thread_id *r1;
|
||||
|
||||
static void *THREAD_FUNC thread_send(void *data);
|
||||
static void *THREAD_FUNC thread_recv(void *data);
|
||||
|
||||
static void *THREAD_FUNC thread_send(void *data)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static void *THREAD_FUNC thread_recv(void *data)
|
||||
{
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
char msg[16][24] = {
|
||||
{0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18},
|
||||
{0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28},
|
||||
|
|
|
|||
|
|
@ -5,12 +5,14 @@
|
|||
static mutex_id lock;
|
||||
static int x = 0;
|
||||
|
||||
static status_t exit_ret_val = 123;
|
||||
|
||||
static thread_id t1;
|
||||
static thread_id t2;
|
||||
static thread_id t3;
|
||||
static thread_id t4;
|
||||
|
||||
static void *THREAD_FUNC thread_func1(void *data)
|
||||
static void *THREAD_FUNC thread_func1(thread_id id, void *data)
|
||||
{
|
||||
int i;
|
||||
|
||||
|
|
@ -20,6 +22,7 @@ static void *THREAD_FUNC thread_func1(void *data)
|
|||
x++;
|
||||
mutex_unlock(lock);
|
||||
}
|
||||
thread_exit(id, exit_ret_val);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -45,18 +48,18 @@ static void create_threads(abts_case *tc, void *data)
|
|||
ABTS_INT_EQUAL(tc, CORE_OK, rv);
|
||||
}
|
||||
|
||||
static void delete_threads(abts_case *tc, void *data)
|
||||
static void join_threads(abts_case *tc, void *data)
|
||||
{
|
||||
status_t s;
|
||||
|
||||
s = thread_delete(t1);
|
||||
ABTS_INT_EQUAL(tc, CORE_OK, s);
|
||||
s = thread_delete(t2);
|
||||
ABTS_INT_EQUAL(tc, CORE_OK, s);
|
||||
s = thread_delete(t3);
|
||||
ABTS_INT_EQUAL(tc, CORE_OK, s);
|
||||
s = thread_delete(t4);
|
||||
ABTS_INT_EQUAL(tc, CORE_OK, s);
|
||||
thread_join(&s, t1);
|
||||
ABTS_INT_EQUAL(tc, exit_ret_val, s);
|
||||
thread_join(&s, t2);
|
||||
ABTS_INT_EQUAL(tc, exit_ret_val, s);
|
||||
thread_join(&s, t3);
|
||||
ABTS_INT_EQUAL(tc, exit_ret_val, s);
|
||||
thread_join(&s, t4);
|
||||
ABTS_INT_EQUAL(tc, exit_ret_val, s);
|
||||
}
|
||||
|
||||
static void check_locks(abts_case *tc, void *data)
|
||||
|
|
@ -70,7 +73,7 @@ abts_suite *testthread(abts_suite *suite)
|
|||
|
||||
abts_run_test(suite, init_thread, NULL);
|
||||
abts_run_test(suite, create_threads, NULL);
|
||||
abts_run_test(suite, delete_threads, NULL);
|
||||
abts_run_test(suite, join_threads, NULL);
|
||||
abts_run_test(suite, check_locks, NULL);
|
||||
|
||||
return suite;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue