ai_threads.h
Go to the documentation of this file.
1// Copyright 2021 Autodesk, Inc. All rights reserved.
2//
3// Use of this software is subject to the terms of the Autodesk license
4// agreement provided at the time of installation or download, or which
5// otherwise accompanies this software in either electronic or hard copy form.
6
12#pragma once
13#include "ai_api.h"
14
22AI_API void* AiThreadCreate(unsigned int (*fn)(void*), void* data, int priority);
23AI_API void AiThreadClose(void* thread);
24AI_API void AiThreadWait(void* thread);
25AI_API AI_CONST void* AiThreadSelf();
26
27typedef void (*AtParallelForFunc)(size_t array_index, void* data, void* payload);
28
29AI_API void AiParallelFor(void* array_of_data, size_t data_size, size_t num_data, void* payload, AtParallelForFunc job);
30
31typedef void* AtParallelJobsID;
32typedef void (*AtParallelJobsFunc)(void* payload);
33
34AI_API AtParallelJobsID AiParallelJobsCreateID();
35AI_API void AiParallelJobsDestroy(AtParallelJobsID jobsID);
36
37AI_API void AiParallelJobsDispatch(AtParallelJobsID jobsID, void* payload, AtParallelJobsFunc job);
38AI_API void AiParallelJobsWait(AtParallelJobsID jobsID);
39
55{
58 void add(void* payload, AtParallelJobsFunc job) { AiParallelJobsDispatch(m_jobs, payload, job); }
59 void wait() { AiParallelJobsWait(m_jobs); }
60 AtParallelJobsID m_jobs;
61};
62
63#define AI_MAX_THREADS 1024
68#define AI_PRIORITY_LOWEST 0x00
69#define AI_PRIORITY_LOW 0x01
70#define AI_PRIORITY_NORMAL 0x02
71#define AI_PRIORITY_HIGH 0x03
72/*\}*/
73
74/*\}*/
DLL export prefix for API functions (necessary for multi-platform development)
AI_API void AiParallelJobsWait(AtParallelJobsID jobsID)
Wait until all jobs of a given work scheduler have ended.
Definition: ai_thread.cpp:196
AI_API void AiThreadWait(void *thread)
Wait for a thread to finish.
AI_API void AiParallelFor(void *array_of_data, size_t data_size, size_t num_data, void *payload, AtParallelForFunc job)
Operate on an array of data in parallel.
Definition: ai_thread.cpp:129
AI_API AI_CONST void * AiThreadSelf()
Returns a handle for the current (calling) thread.
AI_API void * AiThreadCreate(unsigned int(*fn)(void *), void *data, int priority)
Creates a thread and returns a handler for the thread.
AI_API AtParallelJobsID AiParallelJobsCreateID()
Create a work scheduler, for running jobs in parallel.
Definition: ai_thread.cpp:159
AI_API void AiParallelJobsDispatch(AtParallelJobsID jobsID, void *payload, AtParallelJobsFunc job)
Run a new job that will be executed in a separate thread.
Definition: ai_thread.cpp:184
AI_API void AiParallelJobsDestroy(AtParallelJobsID jobsID)
Destroy the parallel work scheduler.
Definition: ai_thread.cpp:169
AI_API void AiThreadClose(void *thread)
Closes thread handle, to avoid resource leaks.
Work scheduler structure that can run jobs in parallel.
Definition: ai_threads.h:55

© 2023 Autodesk, Inc. · All rights reserved · www.arnoldrenderer.com