mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-25 11:58:55 +00:00
Bug 934317: Mutex-protect the RLogRingBuffer, since more than one thread is using it. r=jesup
This commit is contained in:
parent
790129f3b0
commit
6a296679dc
@ -15,6 +15,7 @@
|
||||
#include <string>
|
||||
#include "mozilla/Assertions.h"
|
||||
#include "mozilla/Move.h" // Pinch hitting for <utility> and std::move
|
||||
#include "mozilla/Mutex.h"
|
||||
#include "mozilla/NullPtr.h"
|
||||
#include <vector>
|
||||
|
||||
@ -43,18 +44,21 @@ namespace mozilla {
|
||||
RLogRingBuffer* RLogRingBuffer::instance;
|
||||
|
||||
RLogRingBuffer::RLogRingBuffer()
|
||||
: log_limit_(4096) {
|
||||
: log_limit_(4096),
|
||||
mutex_("RLogRingBuffer::mutex_") {
|
||||
}
|
||||
|
||||
RLogRingBuffer::~RLogRingBuffer() {
|
||||
}
|
||||
|
||||
void RLogRingBuffer::SetLogLimit(uint32_t new_limit) {
|
||||
OffTheBooksMutexAutoLock lock(mutex_);
|
||||
log_limit_ = new_limit;
|
||||
RemoveOld();
|
||||
}
|
||||
|
||||
void RLogRingBuffer::Log(std::string&& log) {
|
||||
OffTheBooksMutexAutoLock lock(mutex_);
|
||||
log_messages_.push_front(Move(log));
|
||||
RemoveOld();
|
||||
}
|
||||
@ -106,6 +110,7 @@ inline bool AnySubstringMatches(const std::vector<std::string>& substrings,
|
||||
void RLogRingBuffer::FilterAny(const std::vector<std::string>& substrings,
|
||||
uint32_t limit,
|
||||
std::deque<std::string>* matching_logs) {
|
||||
OffTheBooksMutexAutoLock lock(mutex_);
|
||||
if (limit == 0) {
|
||||
// At a max, all of the log messages.
|
||||
limit = log_limit_;
|
||||
|
@ -59,6 +59,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "mozilla/Mutex.h"
|
||||
|
||||
#include "m_cpp_utils.h"
|
||||
|
||||
namespace mozilla {
|
||||
@ -110,6 +112,7 @@ class RLogRingBuffer {
|
||||
std::deque<std::string> log_messages_;
|
||||
/* Max size of log buffer (should we use time-depth instead/also?) */
|
||||
uint32_t log_limit_;
|
||||
OffTheBooksMutex mutex_;
|
||||
|
||||
DISALLOW_COPY_ASSIGN(RLogRingBuffer);
|
||||
}; // class RLogRingBuffer
|
||||
|
Loading…
x
Reference in New Issue
Block a user