job/semaphore: add multi-release

This commit is contained in:
Danny Robson 2018-03-22 13:39:16 +11:00
parent 848b9951e8
commit 53255ca4a0
2 changed files with 12 additions and 3 deletions

View File

@ -34,6 +34,7 @@ namespace util::job {
int acquire (void);
int acquire (int count);
int release (void);
int release (int count);
auto lock (void) { return acquire (); }
auto unlock (void) { return release (); }

View File

@ -89,15 +89,23 @@ semaphore::acquire (void)
//-----------------------------------------------------------------------------
int
semaphore::release (void)
semaphore::release (int count)
{
auto res = ++m_value;
if (sys_futex (&m_value, FUTEX_WAKE, 1, nullptr, nullptr, 0) < 0)
auto res = m_value += count;
if (sys_futex (&m_value, FUTEX_WAKE, count, nullptr, nullptr, 0) < 0)
posix::error::throw_code ();
return res;
}
//-----------------------------------------------------------------------------
int
semaphore::release (void)
{
return release (1);
}
///////////////////////////////////////////////////////////////////////////////
int
semaphore::value (void) const