GATE
threadpools.h File Reference

Thread pool implementation. More...

#include "gate/gate_core_api.h"
#include "gate/threading.h"

Typedefs

typedef struct gate_threadpool_classgate_threadpool_t
 

Functions

GATE_CORE_API gate_result_t gate_threadpool_create (gate_threadpool_t *ptr_pool, gate_uint32_t thread_count, gate_uint32_t max_tasks)
 Allocates resources for a threadpool.
 
GATE_CORE_API gate_result_t gate_threadpool_start (gate_threadpool_t pool)
 Starts task processing within the thread pool.
 
GATE_CORE_API gate_result_t gate_threadpool_stop (gate_threadpool_t pool)
 Stops task processing within the thread pool.
 
GATE_CORE_API gate_result_t gate_threadpool_destroy (gate_threadpool_t pool)
 Deallocates resources of the threadpool and releases its handle.
 
GATE_CORE_API gate_result_t gate_threadpool_add_task (gate_threadpool_t pool, gate_runnable_t *task)
 Adds a runnable interface as a task to be processed by a free thread in the pool.
 
GATE_CORE_API gate_result_t gate_threadpool_remove_task (gate_threadpool_t pool, gate_runnable_t *task)
 Removes a runnable interface from the list of pending tasks.
 
GATE_CORE_API gate_size_t gate_threadpool_pending_tasks (gate_threadpool_t pool)
 Returns the current amount of pending tasks.
 

Detailed Description

Thread pool implementation.

Function Documentation

◆ gate_threadpool_add_task()

GATE_CORE_API gate_result_t gate_threadpool_add_task ( gate_threadpool_t pool,
gate_runnable_t * task )

Adds a runnable interface as a task to be processed by a free thread in the pool.

Parameters
[in]poolthreadpool handle to be accessed
[in]taskpointer to runnable interface representing the task to be executed
Returns
GATE_RESULT_* result code

◆ gate_threadpool_create()

GATE_CORE_API gate_result_t gate_threadpool_create ( gate_threadpool_t * ptr_pool,
gate_uint32_t thread_count,
gate_uint32_t max_tasks )

Allocates resources for a threadpool.

Parameters
[in,out]ptr_poolpointer to threadpool handle to be initialized
[in]thread_countamount of threads to be managed by this threadpool
[in]max_tasksmaximum amount of allowed pending tasks
Returns
GATE_RESULT_* result code

◆ gate_threadpool_destroy()

GATE_CORE_API gate_result_t gate_threadpool_destroy ( gate_threadpool_t pool)

Deallocates resources of the threadpool and releases its handle.

Parameters
[in]poolthreadpool handle to be stopped
Returns
GATE_RESULT_* result code

◆ gate_threadpool_pending_tasks()

GATE_CORE_API gate_size_t gate_threadpool_pending_tasks ( gate_threadpool_t pool)

Returns the current amount of pending tasks.

Parameters
[in]poolthreadpool handle to be accessed
Returns
GATE_RESULT_* result code, GATE_RESULT_OK_UNCHANGED in case that nothing was changed

◆ gate_threadpool_remove_task()

GATE_CORE_API gate_result_t gate_threadpool_remove_task ( gate_threadpool_t pool,
gate_runnable_t * task )

Removes a runnable interface from the list of pending tasks.

Parameters
[in]poolthreadpool handle to be accessed
[in]taskpointer to runnable interface representing the task to be removed
Returns
GATE_RESULT_* result code, GATE_RESULT_OK_UNCHANGED in case that nothing was changed

◆ gate_threadpool_start()

GATE_CORE_API gate_result_t gate_threadpool_start ( gate_threadpool_t pool)

Starts task processing within the thread pool.

Parameters
[in]poolthreadpool handle to be started
Returns
GATE_RESULT_* result code

◆ gate_threadpool_stop()

GATE_CORE_API gate_result_t gate_threadpool_stop ( gate_threadpool_t pool)

Stops task processing within the thread pool.

Parameters
[in]poolthreadpool handle to be stopped
Returns
GATE_RESULT_* result code