Skip to content

Commit

Permalink
Bug 1874226 - DebugFilesAutoLock to lock/unlock in ctor/dtor instead …
Browse files Browse the repository at this point in the history
…of via Scoped<> inheritance. r=xpcom-reviewers,emilio

Differential Revision: https://phabricator.services.mozilla.com/D200249
  • Loading branch information
kdashg committed Feb 7, 2024
1 parent 7745990 commit b2be0b2
Showing 1 changed file with 6 additions and 30 deletions.
36 changes: 6 additions & 30 deletions xpcom/build/PoisonIOInterposerBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#include "mozilla/Maybe.h"
#include "mozilla/Mutex.h"
#include "mozilla/Scoped.h"
#include "mozilla/UniquePtr.h"

#include <algorithm>
Expand Down Expand Up @@ -38,40 +37,17 @@ inline mozilla::Maybe<intptr_t> FileDescriptorToHandle(int aFd) {

namespace {

struct DebugFilesAutoLockTraits {
typedef PRLock* type;
typedef const PRLock* const_type;
static const_type empty() { return nullptr; }
static void release(type aL) { PR_Unlock(aL); }
};

class DebugFilesAutoLock : public mozilla::Scoped<DebugFilesAutoLockTraits> {
static PRLock* Lock;

class DebugFilesAutoLock final {
public:
static PRLock* getDebugFileIDsLock() {
// On windows this static is not thread safe, but we know that the first
// call is from
// * An early registration of a debug FD or
// * The call to InitWritePoisoning.
// Since the early debug FDs are logs created early in the main thread
// and no writes are trapped before InitWritePoisoning, we are safe.
if (!Lock) {
Lock = PR_NewLock();
}

// We have to use something lower level than a mutex. If we don't, we
// can get recursive in here when called from logging a call to free.
return Lock;
static PRLock* sLock = PR_NewLock();
return sLock;
}

DebugFilesAutoLock()
: mozilla::Scoped<DebugFilesAutoLockTraits>(getDebugFileIDsLock()) {
PR_Lock(get());
}
};
DebugFilesAutoLock() { PR_Lock(getDebugFileIDsLock()); }

PRLock* DebugFilesAutoLock::Lock;
~DebugFilesAutoLock() { PR_Unlock(getDebugFileIDsLock()); }
};

// The ChunkedList<T> class implements, at the high level, a non-iterable
// list of instances of T. Its goal is to be somehow minimalist for the
Expand Down

0 comments on commit b2be0b2

Please sign in to comment.