diff --git a/trunk/src/app/srs_app_log.cpp b/trunk/src/app/srs_app_log.cpp index 2ea4079c7f..0faef4fa69 100644 --- a/trunk/src/app/srs_app_log.cpp +++ b/trunk/src/app/srs_app_log.cpp @@ -38,13 +38,6 @@ #include #include -#include - -SrsPps* _srs_thread_sync_10us = new SrsPps(); -SrsPps* _srs_thread_sync_100us = new SrsPps(); -SrsPps* _srs_thread_sync_1000us = new SrsPps(); -SrsPps* _srs_thread_sync_plus = new SrsPps(); - // the max size of a line of log. #define LOG_MAX_SIZE 8192 @@ -235,24 +228,9 @@ void SrsFileLog::write_log(char *str_log, int size, int level) return; } - // It's ok to use cache, because it has been updated in generating log header. - srs_utime_t now = srs_get_system_time(); - // write log to file. if ((err = writer_->write(str_log, size, NULL)) != srs_success) { srs_error_reset(err); // Ignore any error for log writing. } - - // Stat the sync wait of locks. - srs_utime_t elapsed = srs_update_system_time() - now; - if (elapsed <= 10) { - ++_srs_thread_sync_10us->sugar; - } else if (elapsed <= 100) { - ++_srs_thread_sync_100us->sugar; - } else if (elapsed <= 1000) { - ++_srs_thread_sync_1000us->sugar; - } else { - ++_srs_thread_sync_plus->sugar; - } } diff --git a/trunk/src/app/srs_app_threads.cpp b/trunk/src/app/srs_app_threads.cpp index 2a160fe16b..e8c17414d5 100644 --- a/trunk/src/app/srs_app_threads.cpp +++ b/trunk/src/app/srs_app_threads.cpp @@ -35,10 +35,10 @@ using namespace std; #include -extern SrsPps* _srs_thread_sync_10us; -extern SrsPps* _srs_thread_sync_100us; -extern SrsPps* _srs_thread_sync_1000us; -extern SrsPps* _srs_thread_sync_plus; +SrsPps* _srs_thread_sync_10us = new SrsPps(); +SrsPps* _srs_thread_sync_100us = new SrsPps(); +SrsPps* _srs_thread_sync_1000us = new SrsPps(); +SrsPps* _srs_thread_sync_plus = new SrsPps(); SrsThreadMutex::SrsThreadMutex() { @@ -310,9 +310,28 @@ srs_error_t SrsAsyncFileWriter::flush() { srs_error_t err = srs_success; + // The time to wait here, is the time to wait there, because they wait for the same lock + // at queue to push_back or swap all messages. + srs_utime_t now = srs_update_system_time(); + vector flying; - queue_->swap(flying); + if (true) { + queue_->swap(flying); + } + + // Stat the sync wait of locks. + srs_utime_t elapsed = srs_update_system_time() - now; + if (elapsed <= 10) { + ++_srs_thread_sync_10us->sugar; + } else if (elapsed <= 100) { + ++_srs_thread_sync_100us->sugar; + } else if (elapsed <= 1000) { + ++_srs_thread_sync_1000us->sugar; + } else { + ++_srs_thread_sync_plus->sugar; + } + // Flush the flying messages to disk. for (int i = 0; i < (int)flying.size(); i++) { SrsSharedPtrMessage* msg = flying.at(i);