正在显示
1 个修改的文件
包含
55 行增加
和
1 行删除
@@ -52,15 +52,64 @@ int sleep_test() | @@ -52,15 +52,64 @@ int sleep_test() | ||
52 | srs_trace("sleep test: start"); | 52 | srs_trace("sleep test: start"); |
53 | 53 | ||
54 | srs_trace("1. sleep..."); | 54 | srs_trace("1. sleep..."); |
55 | + st_utime_t start = st_utime(); | ||
55 | st_usleep(sleep_ms * 1000); | 56 | st_usleep(sleep_ms * 1000); |
57 | + st_utime_t end = st_utime(); | ||
56 | 58 | ||
57 | - srs_trace("2. sleep ok"); | 59 | + srs_trace("2. sleep ok, sleep=%dus, deviation=%dus", |
60 | + (int)(sleep_ms * 1000), (int)(end - start - sleep_ms * 1000)); | ||
58 | 61 | ||
59 | srs_trace("sleep test: end"); | 62 | srs_trace("sleep test: end"); |
60 | 63 | ||
61 | return 0; | 64 | return 0; |
62 | } | 65 | } |
63 | 66 | ||
67 | +st_mutex_t sleep_work_cond = NULL; | ||
68 | +void* sleep_deviation_func(void* arg) | ||
69 | +{ | ||
70 | + st_mutex_lock(sleep_work_cond); | ||
71 | + srs_trace("2. work thread start."); | ||
72 | + | ||
73 | + int64_t i; | ||
74 | + for (i = 0; i < 3000000000ULL; i++) { | ||
75 | + } | ||
76 | + | ||
77 | + st_mutex_unlock(sleep_work_cond); | ||
78 | + srs_trace("3. work thread end."); | ||
79 | + | ||
80 | + return NULL; | ||
81 | +} | ||
82 | + | ||
83 | +int sleep_deviation_test() | ||
84 | +{ | ||
85 | + srs_trace("==================================================="); | ||
86 | + srs_trace("sleep deviation test: start"); | ||
87 | + | ||
88 | + sleep_work_cond = st_mutex_new(); | ||
89 | + | ||
90 | + st_thread_create(sleep_deviation_func, NULL, 0, 0); | ||
91 | + st_mutex_lock(sleep_work_cond); | ||
92 | + | ||
93 | + srs_trace("1. sleep..."); | ||
94 | + st_utime_t start = st_utime(); | ||
95 | + | ||
96 | + // other thread to do some complex work. | ||
97 | + st_mutex_unlock(sleep_work_cond); | ||
98 | + st_usleep(1000 * 1000); | ||
99 | + | ||
100 | + st_utime_t end = st_utime(); | ||
101 | + | ||
102 | + srs_trace("4. sleep ok, sleep=%dus, deviation=%dus", | ||
103 | + (int)(sleep_ms * 1000), (int)(end - start - sleep_ms * 1000)); | ||
104 | + | ||
105 | + st_mutex_lock(sleep_work_cond); | ||
106 | + srs_trace("sleep deviation test: end"); | ||
107 | + | ||
108 | + st_mutex_destroy(sleep_work_cond); | ||
109 | + | ||
110 | + return 0; | ||
111 | +} | ||
112 | + | ||
64 | void* thread_func(void* arg) | 113 | void* thread_func(void* arg) |
65 | { | 114 | { |
66 | srs_trace("1. thread run"); | 115 | srs_trace("1. thread run"); |
@@ -361,6 +410,11 @@ int main(int argc, char** argv) | @@ -361,6 +410,11 @@ int main(int argc, char** argv) | ||
361 | return -1; | 410 | return -1; |
362 | } | 411 | } |
363 | 412 | ||
413 | + if (sleep_deviation_test() < 0) { | ||
414 | + srs_trace("sleep_deviation_test failed"); | ||
415 | + return -1; | ||
416 | + } | ||
417 | + | ||
364 | if (thread_test() < 0) { | 418 | if (thread_test() < 0) { |
365 | srs_trace("thread_test failed"); | 419 | srs_trace("thread_test failed"); |
366 | return -1; | 420 | return -1; |
-
请 注册 或 登录 后发表评论