Semaphore initial count can now be set in constructor.
git-svn-id: http://voip.null.ro/svn/yate@5939 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
parent
30d2d5af03
commit
daeb8611cc
|
@ -87,7 +87,7 @@ private:
|
|||
|
||||
class SemaphorePrivate {
|
||||
public:
|
||||
SemaphorePrivate(unsigned int maxcount, const char* name);
|
||||
SemaphorePrivate(unsigned int maxcount, const char* name, unsigned int initialCount);
|
||||
~SemaphorePrivate();
|
||||
inline void ref()
|
||||
{ ++m_refcount; }
|
||||
|
@ -365,16 +365,19 @@ bool MutexPrivate::unlock()
|
|||
}
|
||||
|
||||
|
||||
SemaphorePrivate::SemaphorePrivate(unsigned int maxcount, const char* name)
|
||||
SemaphorePrivate::SemaphorePrivate(unsigned int maxcount, const char* name,
|
||||
unsigned int initialCount)
|
||||
: m_refcount(1), m_waiting(0), m_maxcount(maxcount),
|
||||
m_name(name)
|
||||
{
|
||||
if (initialCount > m_maxcount)
|
||||
initialCount = m_maxcount;
|
||||
GlobalMutex::lock();
|
||||
s_count++;
|
||||
#ifdef _WINDOWS
|
||||
m_semaphore = ::CreateSemaphore(NULL,1,maxcount,NULL);
|
||||
m_semaphore = ::CreateSemaphore(NULL,initialCount,maxcount,NULL);
|
||||
#else
|
||||
::sem_init(&m_semaphore,0,1);
|
||||
::sem_init(&m_semaphore,0,initialCount);
|
||||
#endif
|
||||
GlobalMutex::unlock();
|
||||
}
|
||||
|
@ -646,13 +649,13 @@ MutexPool::~MutexPool()
|
|||
}
|
||||
|
||||
|
||||
Semaphore::Semaphore(unsigned int maxcount, const char* name)
|
||||
Semaphore::Semaphore(unsigned int maxcount, const char* name, unsigned int initialCount)
|
||||
: m_private(0)
|
||||
{
|
||||
if (!name)
|
||||
name = "?";
|
||||
if (maxcount)
|
||||
m_private = new SemaphorePrivate(maxcount,name);
|
||||
m_private = new SemaphorePrivate(maxcount,name,initialCount);
|
||||
}
|
||||
|
||||
Semaphore::Semaphore(const Semaphore &original)
|
||||
|
|
|
@ -5136,8 +5136,10 @@ public:
|
|||
* Construct a new unlocked semaphore
|
||||
* @param maxcount Maximum unlock count, must be strictly positive
|
||||
* @param name Static name of the semaphore (for debugging purpose only)
|
||||
* @param initialCount Initial semaphore count, must not be greater than maxcount
|
||||
*/
|
||||
explicit Semaphore(unsigned int maxcount = 1, const char* name = 0);
|
||||
explicit Semaphore(unsigned int maxcount = 1, const char* name = 0,
|
||||
unsigned int initialCount = 1);
|
||||
|
||||
/**
|
||||
* Copy constructor, creates a shared semaphore
|
||||
|
|
Loading…
Reference in New Issue