Esempio n. 1
0
SemaphorePtr SemaphoreFactory::newInstance(FencePtr fence)
{
	ANKI_ASSERT(fence);

	LockGuard<Mutex> lock(m_mtx);

	Semaphore* out = nullptr;

	if(m_semCount > 0)
	{
		releaseFences();

		U count = m_semCount;
		while(count--)
		{
			if(!m_sems[count]->m_fence)
			{
				out = m_sems[count];

				// Pop it
				for(U i = count; i < m_semCount - 1; ++i)
				{
					m_sems[i] = m_sems[i + 1];
				}

				--m_semCount;

				break;
			}
		}
	}

	if(out == nullptr)
	{
		// Create a new one
		out = m_alloc.newInstance<Semaphore>(this, fence);
	}
	else
	{
		out->m_fence = fence;
	}

	ANKI_ASSERT(out->m_refcount.get() == 0);
	return SemaphorePtr(out);
}
Esempio n. 2
0
SemaphorePtr Semaphore::create(unsigned int initial_capacity)
{
  return SemaphorePtr(new Semaphore(initial_capacity));
}