job/semaphore: add multi-release
This commit is contained in:
parent
848b9951e8
commit
53255ca4a0
@ -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 (); }
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user