@@ -170,7 +170,7 @@ srs_error_t SrsThreadPool::run()
170
170
srs_error_t err = srs_success;
171
171
172
172
while (true ) {
173
- string async_logs = _srs_async_log->desc ();
173
+ string async_logs = _srs_async_log->description ();
174
174
srs_trace (" Thread #%d(%s): cycle threads=%d%s" , entry_->num , entry_->label .c_str (), (int )threads_.size (),
175
175
async_logs.c_str ());
176
176
@@ -205,21 +205,16 @@ SrsThreadPool* _srs_thread_pool = new SrsThreadPool();
205
205
SrsAsyncFileWriter::SrsAsyncFileWriter (std::string p)
206
206
{
207
207
filename_ = p;
208
- lock_ = new SrsThreadMutex ();
209
208
writer_ = new SrsFileWriter ();
209
+ queue_ = new SrsThreadQueue<SrsSharedPtrMessage>();
210
210
}
211
211
212
212
// TODO: FIXME: Before free the writer, we must remove it from the manager.
213
213
SrsAsyncFileWriter::~SrsAsyncFileWriter ()
214
214
{
215
+ // TODO: FIXME: Should we flush dirty logs?
215
216
srs_freep (writer_);
216
- srs_freep (lock_);
217
-
218
- // TODO: FIXME: Should we flush these logs?
219
- for (int i = 0 ; i < (int )dirty_.size (); i++) {
220
- SrsSharedPtrMessage* msg = dirty_.at (i);
221
- srs_freep (msg);
222
- }
217
+ srs_freep (queue_);
223
218
}
224
219
225
220
srs_error_t SrsAsyncFileWriter::open ()
@@ -251,10 +246,7 @@ srs_error_t SrsAsyncFileWriter::write(void* buf, size_t count, ssize_t* pnwrite)
251
246
SrsSharedPtrMessage* msg = new SrsSharedPtrMessage ();
252
247
msg->wrap (cp, count);
253
248
254
- if (true ) {
255
- SrsThreadLocker (lock_);
256
- dirty_.push_back (msg);
257
- }
249
+ queue_->push_back (msg);
258
250
259
251
if (pnwrite) {
260
252
*pnwrite = count;
@@ -288,10 +280,7 @@ srs_error_t SrsAsyncFileWriter::flush()
288
280
srs_error_t err = srs_success;
289
281
290
282
vector<SrsSharedPtrMessage*> flying;
291
- if (true ) {
292
- SrsThreadLocker (lock_);
293
- dirty_.swap (flying);
294
- }
283
+ queue_->swap (flying);
295
284
296
285
for (int i = 0 ; i < (int )flying.size (); i++) {
297
286
SrsSharedPtrMessage* msg = flying.at (i);
@@ -366,7 +355,7 @@ void SrsAsyncLogManager::reopen()
366
355
reopen_ = true ;
367
356
}
368
357
369
- std::string SrsAsyncLogManager::desc ()
358
+ std::string SrsAsyncLogManager::description ()
370
359
{
371
360
SrsThreadLocker (lock_);
372
361
@@ -375,8 +364,9 @@ std::string SrsAsyncLogManager::desc()
375
364
for (int i = 0 ; i < (int )writers_.size (); i++) {
376
365
SrsAsyncFileWriter* writer = writers_.at (i);
377
366
378
- nn_logs += (int )writer->dirty_ .size ();
379
- max_logs = srs_max (max_logs, (int )writer->dirty_ .size ());
367
+ int nn = (int )writer->queue_ ->size ();
368
+ nn_logs += nn;
369
+ max_logs = srs_max (max_logs, nn);
380
370
}
381
371
382
372
static char buf[128 ];
0 commit comments