Fixed race condition in xcb plugin logging (when debugging is enabled).

Change-Id: I8fa11ba26037d8f78e7c5131326d94836d0de9d4
Reviewed-on: http://codereview.qt-project.org/4647
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Gunnar Sletta <gunnar.sletta@nokia.com>
This commit is contained in:
Samuel Rødal 2011-09-12 10:43:13 +02:00 committed by Gunnar Sletta
parent f48b526c3d
commit 2ce969d7f0
2 changed files with 4 additions and 0 deletions

View File

@ -419,6 +419,7 @@ const char *xcb_protocol_request_codes[] =
#ifdef Q_XCB_DEBUG #ifdef Q_XCB_DEBUG
void QXcbConnection::log(const char *file, int line, int sequence) void QXcbConnection::log(const char *file, int line, int sequence)
{ {
QMutexLocker locker(&m_callLogMutex);
CallInfo info; CallInfo info;
info.sequence = sequence; info.sequence = sequence;
info.file = file; info.file = file;
@ -438,6 +439,7 @@ void QXcbConnection::handleXcbError(xcb_generic_error_t *error)
int(error->major_code), xcb_protocol_request_codes[clamped_major_code], int(error->major_code), xcb_protocol_request_codes[clamped_major_code],
int(error->minor_code)); int(error->minor_code));
#ifdef Q_XCB_DEBUG #ifdef Q_XCB_DEBUG
QMutexLocker locker(&m_callLogMutex);
int i = 0; int i = 0;
for (; i < m_callLog.size(); ++i) { for (; i < m_callLog.size(); ++i) {
if (m_callLog.at(i).sequence == error->sequence) { if (m_callLog.at(i).sequence == error->sequence) {
@ -459,6 +461,7 @@ void QXcbConnection::handleXcbEvent(xcb_generic_event_t *event)
{ {
#ifdef Q_XCB_DEBUG #ifdef Q_XCB_DEBUG
{ {
QMutexLocker locker(&m_callLogMutex);
int i = 0; int i = 0;
for (; i < m_callLog.size(); ++i) for (; i < m_callLog.size(); ++i)
if (m_callLog.at(i).sequence >= event->sequence) if (m_callLog.at(i).sequence >= event->sequence)

View File

@ -375,6 +375,7 @@ private:
int line; int line;
}; };
QVector<CallInfo> m_callLog; QVector<CallInfo> m_callLog;
QMutex m_callLogMutex;
void log(const char *file, int line, int sequence); void log(const char *file, int line, int sequence);
template <typename cookie_t> template <typename cookie_t>
friend cookie_t q_xcb_call_template(const cookie_t &cookie, QXcbConnection *connection, const char *file, int line); friend cookie_t q_xcb_call_template(const cookie_t &cookie, QXcbConnection *connection, const char *file, int line);