Bug 184442
| Summary: | Bmalloc should have its own lockers instead of lock_guard and unique_lock | ||
|---|---|---|---|
| Product: | WebKit | Reporter: | Saam Barati <saam> |
| Component: | JavaScriptCore | Assignee: | Saam Barati <saam> |
| Status: | NEW | ||
| Severity: | Normal | CC: | benjamin, fpizlo, ggaren, gskachkov, jfbastien, keith_miller, mark.lam, msaboff, rmorisset, ticaiolima, ysuzuki |
| Priority: | P2 | ||
| Version: | Safari Technology Preview | ||
| Hardware: | Unspecified | ||
| OS: | Unspecified | ||
| Bug Depends on: | 184176 | ||
| Bug Blocks: | |||
Saam Barati
std::unique_lock and std::lock_guard are incompatible types. With bug #184176, I need to use unique_lock in just a few places since we may drop it to wait on a condition variable. However, since we pass this locker to things we call, I need to change the function of a bunch of signatures that don't actually need the API unique_lock provides. Same with things that call this API, they now need to pass in unique_lock.
A lot less code would be changed if we just had a class hierarchy like this:
```
// I'm just picking same names as std, but we could do something different.
template <typename Lock>
class LockGuard {
public:
LockGuard(Lock& lock)
: m_lock(lock)
{
m_lock.lock();
}
~LockGuard(Lock& lock)
{
if (m_locked)
m_lock.unlock();
}
protected:
Lock& m_lock;
bool m_locked { true };
};
template <typename Lock>
class UniqueLock : public LockGuard<Lock> {
using Base = LockGuard<Lock>;
public:
UniqueLock(Lock& l) : Base(l) { }
void lock() { m_locked = true; m_lock.lock(); }
void unlock() { m_locked = false; m_lock.unlock(); }
};
```
Or something along those lines.
| Attachments | ||
|---|---|---|
| Add attachment proposed patch, testcase, etc. |