Bug 1571568 - Update ShmemPool to work in builds with --disable-webrtc. r=ng

1. ShmemPool.cpp is now built for --disable-webrtc builds.
2. ShmemPool no longer uses the gCamerasParentLog logger, it
   uses its own logger.
3. ShmemPool log macros were updated with a SHMEMPOOL_ prefix
   to avoid undef-ing other log macros.

Differential Revision: https://phabricator.services.mozilla.com/D40722

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Michael Froman 2019-08-06 15:09:12 +00:00
Родитель a144a248da
Коммит af196d4cfc
3 изменённых файлов: 45 добавлений и 16 удалений

Просмотреть файл

@ -9,11 +9,17 @@
#include "mozilla/ShmemPool.h"
#include "mozilla/Move.h"
mozilla::LazyLogModule sShmemPoolLog("ShmemPool");
#define SHMEMPOOL_LOG_VERBOSE(args) \
MOZ_LOG(sShmemPoolLog, mozilla::LogLevel::Verbose, args)
namespace mozilla {
ShmemPool::ShmemPool(size_t aPoolSize)
: mMutex("mozilla::ShmemPool"),
mPoolFree(aPoolSize)
mPoolFree(aPoolSize),
mErrorLogged(false)
#ifdef DEBUG
,
mMaxPoolUse(0)
@ -27,6 +33,15 @@ mozilla::ShmemBuffer ShmemPool::GetIfAvailable(size_t aSize) {
// Pool is empty, don't block caller.
if (mPoolFree == 0) {
if (!mErrorLogged) {
// log "out of pool" once as error to avoid log spam
mErrorLogged = true;
SHMEMPOOL_LOG_ERROR(
("ShmemPool is empty, future occurrences "
"will be logged as warnings"));
} else {
SHMEMPOOL_LOG_WARN(("ShmemPool is empty"));
}
// This isn't initialized, so will be understood as an error.
return ShmemBuffer();
}
@ -34,14 +49,14 @@ mozilla::ShmemBuffer ShmemPool::GetIfAvailable(size_t aSize) {
ShmemBuffer& res = mShmemPool[mPoolFree - 1];
if (!res.mInitialized) {
LOG(("No free preallocated Shmem"));
SHMEMPOOL_LOG(("No free preallocated Shmem"));
return ShmemBuffer();
}
MOZ_ASSERT(res.mShmem.IsWritable(), "Pool in Shmem is not writable?");
if (res.mShmem.Size<uint8_t>() < aSize) {
LOG(("Free Shmem but not of the right size"));
SHMEMPOOL_LOG(("Free Shmem but not of the right size"));
return ShmemBuffer();
}
@ -50,7 +65,8 @@ mozilla::ShmemBuffer ShmemPool::GetIfAvailable(size_t aSize) {
size_t poolUse = mShmemPool.Length() - mPoolFree;
if (poolUse > mMaxPoolUse) {
mMaxPoolUse = poolUse;
LOG(("Maximum ShmemPool use increased: %zu buffers", mMaxPoolUse));
SHMEMPOOL_LOG(
("Maximum ShmemPool use increased: %zu buffers", mMaxPoolUse));
}
#endif
return std::move(res);
@ -64,7 +80,7 @@ void ShmemPool::Put(ShmemBuffer&& aShmem) {
#ifdef DEBUG
size_t poolUse = mShmemPool.Length() - mPoolFree;
if (poolUse > 0) {
LOG_VERBOSE(("ShmemPool usage reduced to %zu buffers", poolUse));
SHMEMPOOL_LOG_VERBOSE(("ShmemPool usage reduced to %zu buffers", poolUse));
}
#endif
}

Просмотреть файл

@ -10,11 +10,13 @@
#include "mozilla/ipc/Shmem.h"
#include "mozilla/Mutex.h"
#undef LOG
#undef LOG_ENABLED
extern mozilla::LazyLogModule gCamerasParentLog;
#define LOG(args) MOZ_LOG(gCamerasParentLog, mozilla::LogLevel::Debug, args)
#define LOG_ENABLED() MOZ_LOG_TEST(gCamerasParentLog, mozilla::LogLevel::Debug)
extern mozilla::LazyLogModule sShmemPoolLog;
#define SHMEMPOOL_LOG(args) \
MOZ_LOG(sShmemPoolLog, mozilla::LogLevel::Debug, args)
#define SHMEMPOOL_LOG_WARN(args) \
MOZ_LOG(sShmemPoolLog, mozilla::LogLevel::Warning, args)
#define SHMEMPOOL_LOG_ERROR(args) \
MOZ_LOG(sShmemPoolLog, mozilla::LogLevel::Error, args)
namespace mozilla {
@ -85,6 +87,15 @@ class ShmemPool {
// Pool is empty, don't block caller.
if (mPoolFree == 0) {
if (!mErrorLogged) {
// log "out of pool" once as error to avoid log spam
mErrorLogged = true;
SHMEMPOOL_LOG_ERROR(
("ShmemPool is empty, future occurrences "
"will be logged as warnings"));
} else {
SHMEMPOOL_LOG_WARN(("ShmemPool is empty"));
}
// This isn't initialized, so will be understood as an error.
return ShmemBuffer();
}
@ -92,10 +103,10 @@ class ShmemPool {
ShmemBuffer& res = mShmemPool[mPoolFree - 1];
if (!res.mInitialized) {
LOG(("Initializing new Shmem in pool"));
SHMEMPOOL_LOG(("Initializing new Shmem in pool"));
if (!aInstance->AllocShmem(aSize, ipc::SharedMemory::TYPE_BASIC,
&res.mShmem)) {
LOG(("Failure allocating new Shmem buffer"));
SHMEMPOOL_LOG(("Failure allocating new Shmem buffer"));
return ShmemBuffer();
}
res.mInitialized = true;
@ -106,13 +117,13 @@ class ShmemPool {
// Prepare buffer, increase size if needed (we never shrink as we don't
// maintain seperate sized pools and we don't want to keep reallocating)
if (res.mShmem.Size<char>() < aSize) {
LOG(("Size change/increase in Shmem Pool"));
SHMEMPOOL_LOG(("Size change/increase in Shmem Pool"));
aInstance->DeallocShmem(res.mShmem);
res.mInitialized = false;
// this may fail; always check return value
if (!aInstance->AllocShmem(aSize, ipc::SharedMemory::TYPE_BASIC,
&res.mShmem)) {
LOG(("Failure allocating resized Shmem buffer"));
SHMEMPOOL_LOG(("Failure allocating resized Shmem buffer"));
return ShmemBuffer();
} else {
res.mInitialized = true;
@ -127,7 +138,8 @@ class ShmemPool {
size_t poolUse = mShmemPool.Length() - mPoolFree;
if (poolUse > mMaxPoolUse) {
mMaxPoolUse = poolUse;
LOG(("Maximum ShmemPool use increased: %zu buffers", mMaxPoolUse));
SHMEMPOOL_LOG(
("Maximum ShmemPool use increased: %zu buffers", mMaxPoolUse));
}
#endif
return std::move(res);
@ -136,6 +148,7 @@ class ShmemPool {
private:
Mutex mMutex;
size_t mPoolFree;
bool mErrorLogged;
#ifdef DEBUG
size_t mMaxPoolUse;
#endif

Просмотреть файл

@ -15,7 +15,6 @@ if CONFIG['MOZ_WEBRTC']:
UNIFIED_SOURCES += [
'CamerasChild.cpp',
'CamerasParent.cpp',
'ShmemPool.cpp',
'VideoEngine.cpp',
'VideoFrameUtils.cpp'
]
@ -73,6 +72,7 @@ UNIFIED_SOURCES += [
'MediaSystemResourceManagerParent.cpp',
'MediaSystemResourceService.cpp',
'MediaUtils.cpp',
'ShmemPool.cpp',
]
IPDL_SOURCES += [
'PCameras.ipdl',