正在显示
3 个修改的文件
包含
32 行增加
和
16 行删除
@@ -66,6 +66,7 @@ namespace internal { | @@ -66,6 +66,7 @@ namespace internal { | ||
66 | really_terminated = true; | 66 | really_terminated = true; |
67 | _cid = -1; | 67 | _cid = -1; |
68 | _joinable = joinable; | 68 | _joinable = joinable; |
69 | + disposed = false; | ||
69 | 70 | ||
70 | // in start(), the thread cycle method maybe stop and remove the thread itself, | 71 | // in start(), the thread cycle method maybe stop and remove the thread itself, |
71 | // and the thread start() is waiting for the _cid, and segment fault then. | 72 | // and the thread start() is waiting for the _cid, and segment fault then. |
@@ -115,8 +116,32 @@ namespace internal { | @@ -115,8 +116,32 @@ namespace internal { | ||
115 | 116 | ||
116 | void SrsThread::stop() | 117 | void SrsThread::stop() |
117 | { | 118 | { |
118 | - if (tid) { | 119 | + if (!tid) { |
120 | + return; | ||
121 | + } | ||
122 | + | ||
123 | + loop = false; | ||
124 | + | ||
125 | + dispose(); | ||
126 | + | ||
127 | + tid = NULL; | ||
128 | + } | ||
129 | + | ||
130 | + bool SrsThread::can_loop() | ||
131 | + { | ||
132 | + return loop; | ||
133 | + } | ||
134 | + | ||
135 | + void SrsThread::stop_loop() | ||
136 | + { | ||
119 | loop = false; | 137 | loop = false; |
138 | + } | ||
139 | + | ||
140 | + void SrsThread::dispose() | ||
141 | + { | ||
142 | + if (disposed) { | ||
143 | + return; | ||
144 | + } | ||
120 | 145 | ||
121 | // the interrupt will cause the socket to read/write error, | 146 | // the interrupt will cause the socket to read/write error, |
122 | // which will terminate the cycle thread. | 147 | // which will terminate the cycle thread. |
@@ -145,18 +170,7 @@ namespace internal { | @@ -145,18 +170,7 @@ namespace internal { | ||
145 | srs_warn("core: wait thread to actually terminated"); | 170 | srs_warn("core: wait thread to actually terminated"); |
146 | } | 171 | } |
147 | 172 | ||
148 | - tid = NULL; | ||
149 | - } | ||
150 | - } | ||
151 | - | ||
152 | - bool SrsThread::can_loop() | ||
153 | - { | ||
154 | - return loop; | ||
155 | - } | ||
156 | - | ||
157 | - void SrsThread::stop_loop() | ||
158 | - { | ||
159 | - loop = false; | 173 | + disposed = true; |
160 | } | 174 | } |
161 | 175 | ||
162 | void SrsThread::thread_cycle() | 176 | void SrsThread::thread_cycle() |
@@ -218,8 +232,8 @@ namespace internal { | @@ -218,8 +232,8 @@ namespace internal { | ||
218 | handler->on_thread_stop(); | 232 | handler->on_thread_stop(); |
219 | srs_info("thread %s cycle finished", _name); | 233 | srs_info("thread %s cycle finished", _name); |
220 | 234 | ||
221 | - // when thread terminated normally, set the tid to NULL. | ||
222 | - tid = NULL; | 235 | + // when thread terminated normally, also disposed. |
236 | + disposed = true; | ||
223 | } | 237 | } |
224 | 238 | ||
225 | void* SrsThread::thread_fun(void* arg) | 239 | void* SrsThread::thread_fun(void* arg) |
@@ -100,6 +100,7 @@ namespace internal { | @@ -100,6 +100,7 @@ namespace internal { | ||
100 | bool really_terminated; | 100 | bool really_terminated; |
101 | bool _joinable; | 101 | bool _joinable; |
102 | const char* _name; | 102 | const char* _name; |
103 | + bool disposed; | ||
103 | private: | 104 | private: |
104 | ISrsThreadHandler* handler; | 105 | ISrsThreadHandler* handler; |
105 | int64_t cycle_interval_us; | 106 | int64_t cycle_interval_us; |
@@ -154,6 +155,7 @@ namespace internal { | @@ -154,6 +155,7 @@ namespace internal { | ||
154 | */ | 155 | */ |
155 | virtual void stop_loop(); | 156 | virtual void stop_loop(); |
156 | private: | 157 | private: |
158 | + virtual void dispose(); | ||
157 | virtual void thread_cycle(); | 159 | virtual void thread_cycle(); |
158 | static void* thread_fun(void* arg); | 160 | static void* thread_fun(void* arg); |
159 | }; | 161 | }; |
@@ -905,7 +905,7 @@ namespace _srs_internal | @@ -905,7 +905,7 @@ namespace _srs_internal | ||
905 | } | 905 | } |
906 | 906 | ||
907 | // client c1 time and version | 907 | // client c1 time and version |
908 | - time = ::time(NULL); | 908 | + time = (int32_t)::time(NULL); |
909 | version = 0x80000702; // client c1 version | 909 | version = 0x80000702; // client c1 version |
910 | 910 | ||
911 | // generate signature by schema | 911 | // generate signature by schema |
-
请 注册 或 登录 后发表评论