Toggle navigation
Toggle navigation
此项目
正在载入...
Sign in
胡斌
/
srs
转到一个项目
Toggle navigation
项目
群组
代码片段
帮助
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
winlin
2014-10-26 16:35:12 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
69fdec411f808dbde95cbaf7887905211da5cc38
69fdec41
1 parent
9aba47cb
refs #182: rename to sync test.
隐藏空白字符变更
内嵌
并排对比
正在显示
1 个修改的文件
包含
48 行增加
和
42 行删除
trunk/research/st/srs.c
trunk/research/st/srs.c
查看文件 @
69fdec4
...
...
@@ -5,102 +5,108 @@
#define srs_trace(msg, ...) printf(msg, ##__VA_ARGS__);printf("\n")
st_mutex_t
start
=
NULL
;
st_cond_t
cond
=
NULL
;
st_mutex_t
mutex
=
NULL
;
st_mutex_t
sync_start
=
NULL
;
st_cond_t
sync_cond
=
NULL
;
st_mutex_t
sync_mutex
=
NULL
;
void
*
master
(
void
*
arg
)
void
*
sync_
master
(
void
*
arg
)
{
// wait for main to start this thread.
st_mutex_lock
(
start
);
st_mutex_unlock
(
start
);
// wait for main to sync_start this thread.
st_mutex_lock
(
sync_start
);
st_mutex_unlock
(
sync_start
);
st_usleep
(
100
*
1000
);
st_cond_signal
(
cond
);
st_cond_signal
(
sync_
cond
);
st_mutex_lock
(
mutex
);
st_mutex_lock
(
sync_
mutex
);
srs_trace
(
"2. st mutex is ok"
);
st_mutex_unlock
(
mutex
);
st_mutex_unlock
(
sync_
mutex
);
st_usleep
(
100
*
1000
);
srs_trace
(
"3. st thread is ok"
);
st_cond_signal
(
cond
);
st_cond_signal
(
sync_
cond
);
return
NULL
;
}
void
*
slave
(
void
*
arg
)
void
*
s
ync_s
lave
(
void
*
arg
)
{
// lock mutex to control thread.
st_mutex_lock
(
mutex
);
st_mutex_lock
(
sync_
mutex
);
// wait for main to start this thread.
st_mutex_lock
(
start
);
st_mutex_unlock
(
start
);
// wait for main to sync_start this thread.
st_mutex_lock
(
sync_start
);
st_mutex_unlock
(
sync_start
);
// wait thread to ready.
st_cond_wait
(
cond
);
st_cond_wait
(
sync_
cond
);
srs_trace
(
"1. st cond is ok"
);
// release mutex to control thread
st_usleep
(
100
*
1000
);
st_mutex_unlock
(
mutex
);
st_mutex_unlock
(
sync_
mutex
);
// wait thread to exit.
st_cond_wait
(
cond
);
st_cond_wait
(
sync_
cond
);
srs_trace
(
"4. st is ok"
);
return
NULL
;
}
int
main
(
int
argc
,
char
**
argv
)
int
sync_test
(
)
{
if
(
st_set_eventsys
(
ST_EVENTSYS_ALT
)
<
0
)
{
srs_trace
(
"st_set_eventsys failed"
);
return
-
1
;
}
if
(
st_init
()
<
0
)
{
srs_trace
(
"st_init failed"
);
if
((
sync_start
=
st_mutex_new
())
==
NULL
)
{
srs_trace
(
"st_mutex_new sync_start failed"
);
return
-
1
;
}
st_mutex_lock
(
sync_start
);
if
((
start
=
st_mutex_new
())
==
NULL
)
{
srs_trace
(
"st_mutex_new start failed"
);
return
-
1
;
}
st_mutex_lock
(
start
);
if
((
cond
=
st_cond_new
())
==
NULL
)
{
if
((
sync_cond
=
st_cond_new
())
==
NULL
)
{
srs_trace
(
"st_cond_new cond failed"
);
return
-
1
;
}
if
((
mutex
=
st_mutex_new
())
==
NULL
)
{
if
((
sync_
mutex
=
st_mutex_new
())
==
NULL
)
{
srs_trace
(
"st_mutex_new mutex failed"
);
return
-
1
;
}
if
(
!
st_thread_create
(
master
,
NULL
,
0
,
0
))
{
if
(
!
st_thread_create
(
sync_
master
,
NULL
,
0
,
0
))
{
srs_trace
(
"st_thread_create failed"
);
return
-
1
;
}
if
(
!
st_thread_create
(
slave
,
NULL
,
0
,
0
))
{
if
(
!
st_thread_create
(
s
ync_s
lave
,
NULL
,
0
,
0
))
{
srs_trace
(
"st_thread_create failed"
);
return
-
1
;
}
// run all threads.
st_mutex_unlock
(
start
);
st_mutex_unlock
(
sync_start
);
return
0
;
}
int
main
(
int
argc
,
char
**
argv
)
{
if
(
st_set_eventsys
(
ST_EVENTSYS_ALT
)
<
0
)
{
srs_trace
(
"st_set_eventsys failed"
);
return
-
1
;
}
if
(
st_init
()
<
0
)
{
srs_trace
(
"st_init failed"
);
return
-
1
;
}
if
(
sync_test
()
<
0
)
{
srs_trace
(
"sync_test failed"
);
return
-
1
;
}
// cleanup.
st_thread_exit
(
NULL
);
st_mutex_destroy
(
start
);
st_cond_destroy
(
cond
);
st_mutex_destroy
(
mutex
);
return
0
;
}
...
...
请
注册
或
登录
后发表评论