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 (void);
int acquire (int count); int acquire (int count);
int release (void); int release (void);
int release (int count);
auto lock (void) { return acquire (); } auto lock (void) { return acquire (); }
auto unlock (void) { return release (); } auto unlock (void) { return release (); }

View File

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