Exemple #1
0
/*
 * Initialize stage io thread control structure.  Structure is used
 * to control data movement between io threads.
 */
static void
initIoThread()
{
	size_t size;

	size = sizeof (IoThreadInfo_t);
	SamMalloc(IoThread, size);
	memset(IoThread, 0, size);

	ThreadStateInit(&IoThread->io_readReady);
	ThreadStateInit(&IoThread->io_readDone);

	ThreadStateInit(&IoThread->io_moveReady);
	ThreadStateInit(&IoThread->io_moveDone);

	if (is_disk(Instance->ci_media)) {
		if (is_stk5800(Instance->ci_media)) {
			IoThread->io_flags |= IO_stk5800;
		} else {
			IoThread->io_flags |= IO_disk;
		}
	} else if (Instance->ci_flags & CI_samremote) {
		IoThread->io_flags |= IO_samremote;
	}
}
Exemple #2
0
  void BuildQueueInit(BuildQueue* queue, const BuildQueueConfig* config)
  {
    CHECK(config->m_MaxExpensiveCount > 0 && config->m_MaxExpensiveCount <= config->m_ThreadCount);

    MutexInit(&queue->m_Lock);
    CondInit(&queue->m_WorkAvailable);

    // Compute queue capacity. Allocate space for a power of two number of
    // indices that's at least one larger than the max number of nodes. Because
    // the queue is treated as a ring buffer, we want W=R to mean an empty
    // buffer.
    uint32_t capacity = NextPowerOfTwo(config->m_MaxNodes + 1);

    MemAllocHeap* heap = config->m_Heap;

    queue->m_Queue              = HeapAllocateArray<int32_t>(heap, capacity);
    queue->m_QueueReadIndex     = 0;
    queue->m_QueueWriteIndex    = 0;
    queue->m_QueueCapacity      = capacity;
    queue->m_Config             = *config;
    queue->m_PendingNodeCount   = 0;
    queue->m_FailedNodeCount    = 0;
    queue->m_QuitSignalled      = false;
    queue->m_ExpensiveRunning   = 0;
    queue->m_ExpensiveWaitCount = 0;
    queue->m_ExpensiveWaitList  = HeapAllocateArray<NodeState*>(heap, capacity);

    CHECK(queue->m_Queue);

    if (queue->m_Config.m_ThreadCount > kMaxBuildThreads)
    {
      Log(kWarning, "too many build threads (%d) - clamping to %d",
          queue->m_Config.m_ThreadCount, kMaxBuildThreads);

      queue->m_Config.m_ThreadCount = kMaxBuildThreads;
    }

    Log(kDebug, "build queue initialized; ring buffer capacity = %u", queue->m_QueueCapacity);

    // Block all signals on the main thread.
    SignalBlockThread(true);
    SignalHandlerSetCondition(&queue->m_WorkAvailable);

    // Create build threads.
    for (int i = 0, thread_count = config->m_ThreadCount; i < thread_count; ++i)
    {
      ThreadState* thread_state = &queue->m_ThreadState[i];

      ThreadStateInit(thread_state, queue, MB(64), MB(32), i);

      if (i > 0)
      {
        Log(kDebug, "starting build thread %d", i);
        queue->m_Threads[i] = ThreadStart(BuildThreadRoutine, thread_state);
      }
    }
  }