956 const WorkerID worker_id = worker::GetCurrentID();
962 if (
worker->num_allocated_tasks == max_tasks_per_worker)
964 worker::GarbageCollectAllocatedTasks(
worker);
966 if (
worker->num_allocated_tasks == max_tasks_per_worker)
969 system::WakeUpAllWorkers();
971 while (
worker->num_allocated_tasks == max_tasks_per_worker)
973 worker::TryRunTask(
worker);
974 worker::GarbageCollectAllocatedTasks(
worker);
980 Task*
const task = task_pool::AllocateTask(&
worker->task_allocator, name, func, counter);
986 const Byte*
const user_data_end =
task->user_data +
sizeof(
task->user_data);
987 Byte*
const aligned_ptr =
static_cast<Byte*
>(AlignPointer(
task->user_data, user_data_alignment));
988 const Byte*
const aligned_ptr_end = aligned_ptr + user_data_size;
989 const std::ptrdiff_t alignment_offset = aligned_ptr -
task->user_data;
991 JobAssert(aligned_ptr_end <= user_data_end,
"Userdata could not be stored in task.");
992 JobAssert(alignment_offset <= std::uint8_t(-1),
"Alignment delta too large.");
994 InitUserData(aligned_ptr, user_data);
995 task->userdata_align =
static_cast<std::uint8_t
>(alignment_offset);
998 worker->allocated_tasks[
worker->num_allocated_tasks++] = task_hdl;
1003 switch ((num_workers == 1u) ? QueueMode::Default : queue)
1005 case QueueMode::Default:
1007 task::SubmitQPushHelper(task_ptr,
worker, &
worker->normal_queue);
1010 case QueueMode::WorkerOnly:
1012 task::SubmitQPushHelper(task_ptr,
worker, &
worker->worker_queue);
1016#if defined(__GNUC__)
1017 __builtin_unreachable();
1018#elif defined(_MSC_VER)
1026 if (num_pending_jobs >= num_workers)
1028 system::WakeUpAllWorkers();
1032 system::WakeUpOneWorker();
#define JobAssert(expr, msg)
static job::JobSystemContext * g_JobSystem
std::uint16_t WorkerID
The id type of each worker thread.
std::uint32_t num_tasks_per_worker
std::uint16_t NumWorkers() noexcept
Returns the number of workers created by the system. This function can be called by any thread concur...
std::atomic_uint32_t num_available_jobs