Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
jkoritzinsky committed Jun 19, 2024
1 parent 33adfba commit 25a0229
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
7 changes: 5 additions & 2 deletions src/interfaces/dispenser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ namespace
public: // IMetaDataDispenserEx
STDMETHOD(SetOption)(
REFGUID optionid,
const VARIANT *value)
VARIANT const *value)
{
if (optionid == MetaDataThreadSafetyOptions)
{
Expand Down Expand Up @@ -273,8 +273,11 @@ HRESULT GetDispenser(
REFGUID riid,
void** ppObj)
{
if (riid != IID_IMetaDataDispenser && riid != IID_IMetaDataDispenserEx)
if (riid != IID_IMetaDataDispenser
&& riid != IID_IMetaDataDispenserEx)
{
return E_INVALIDARG;
}

if (ppObj == nullptr)
return E_INVALIDARG;
Expand Down
24 changes: 14 additions & 10 deletions src/interfaces/pal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ bool pal::ComputeSha1Hash(span<const uint8_t> data, std::array<uint8_t, SHA1_HAS
#endif // defined(BUILD_WINDOWS)

// Read-write lock implementation
// The implementation type matches the C++11 BasicLockable and the C++14 SharedLockable requirements (excluding the try_lock_shared method).
// This allows us to move to exposing the C++14 API surface in the future more easily.
#if defined(BUILD_WINDOWS)
namespace pal
{
Expand Down Expand Up @@ -248,11 +250,6 @@ namespace pal
::ReleaseSRWLockExclusive(&_lock);
}
};

std::unique_ptr<ReadWriteLock> CreateReadWriteLock()
{
return std::make_unique<ReadWriteLock>();
}
}
#else
namespace pal
Expand Down Expand Up @@ -286,22 +283,24 @@ namespace pal
::pthread_rwlock_unlock(&_lock);
}
};

std::unique_ptr<ReadWriteLock> CreateReadWriteLock()
{
return std::make_unique<ReadWriteLock>();
}
}
#endif

pal::ReadWriteLock::ReadWriteLock()
: _impl{ std::make_unique<Impl>() }
, _readLock{ *this }
, _writeLock{ *this }
{
}

// Define here where pal::ReadWriteLock::Impl is defined
pal::ReadWriteLock::~ReadWriteLock() = default;

pal::ReadLock::ReadLock(pal::ReadWriteLock& lock) noexcept
: _lock{ lock }
{
}

void pal::ReadLock::lock() noexcept
{
_lock._impl->lock_shared();
Expand All @@ -312,6 +311,11 @@ void pal::ReadLock::unlock() noexcept
_lock._impl->unlock_shared();
}

pal::WriteLock::WriteLock(pal::ReadWriteLock& lock) noexcept
: _lock{ lock }
{
}

void pal::WriteLock::lock() noexcept
{
_lock._impl->lock();
Expand Down
12 changes: 4 additions & 8 deletions src/interfaces/pal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,7 @@ namespace pal
{
ReadWriteLock& _lock;
public:
ReadLock(ReadWriteLock& lock) noexcept
: _lock{ lock }
{}
ReadLock(ReadWriteLock& lock) noexcept;
void lock() noexcept;
void unlock() noexcept;
};
Expand All @@ -132,9 +130,7 @@ namespace pal
{
ReadWriteLock& _lock;
public:
WriteLock(ReadWriteLock& lock) noexcept
: _lock{ lock }
{}
WriteLock(ReadWriteLock& lock) noexcept;
void lock() noexcept;
void unlock() noexcept;
};
Expand All @@ -145,8 +141,8 @@ namespace pal
friend class WriteLock;
class Impl;
std::unique_ptr<Impl> _impl;
ReadLock _readLock = ReadLock(*this);
WriteLock _writeLock = WriteLock(*this);
ReadLock _readLock;
WriteLock _writeLock;
public:
ReadWriteLock();
~ReadWriteLock();
Expand Down

0 comments on commit 25a0229

Please sign in to comment.