#include "threadpool.h"
#include <stdlib.h>
#include <stdio.h>
#include <pthread.h>
◆ __attribute__() [1/2]
__attribute__ |
( |
(constructor) |
| ) |
|
Constructor of the exception handler.
Initialize block_mask with SIGINT. Set handling function and flags.
◆ __attribute__() [2/2]
__attribute__ |
( |
(destructor) |
| ) |
|
Destructor of the handler.
Deallocate exception handler.
◆ defer()
Add a new task to the pool.
- Parameters
-
[in,out] | pool | – pointer to thread-pool; |
[in] | runnable | – task that will be run on the pool. |
- Returns
0
, if defer was finished correctly. Non-zero value, if errors occurred.
◆ free_queue()
static void free_queue |
( |
queue_t * |
queue | ) |
|
|
static |
Deallocate the queue.
Iterate through every node in queue and free them.
- Parameters
-
[in,out] | queue | – pointer to the queue; |
◆ pop()
Read and pop the first element in queue.
Return the first element in the queue. Pop the node from the queue and assign new first node.
- Parameters
-
[in,out] | queue | – pointer to the queue; |
- Returns
- runnable with the first element in the queue.
◆ push()
Add a new element to the queue.
Allocate a new node and copy the runnable to it. Push it at the end of the queue.
- Parameters
-
[in,out] | queue | – pointer to the queue; |
[in] | runnable | – nowe dane do dołączenia do listy; |
◆ sigint_destroy()
static void sigint_destroy |
( |
| ) |
|
|
static |
Destroy all pools after receiving SIGINT.
After SIGINT is catched wait for all pools to finish their tasks and destroy them.
◆ thread_function()
static void* thread_function |
( |
void * |
arg | ) |
|
|
static |
Function run by every thread.
If there is a task to run pop it from the queue and run. If not, sleep on the semaphore. Repeat until the thread-pool is destroyed.
◆ thread_pool_destroy()
Destroy the thread-pool.
Finish all of the tasks and remove the pool.
- Parameters
-
[in,out] | pool | – pointer to the thread-pool; |
◆ thread_pool_init()
Initialize the thread-pool.
Create a thread_pool_t object at argument pool with number of thread passed as pool_size argument.
- Parameters
-
[in,out] | pool | – pointer to the thread-pool; |
[in] | pool_size | – size of the thread-pool; |
- Returns
0
, if init was finished correctly. Non-zero value, if errors occurred.