![]() |
kinetic-c
v0.12.0
Seagate Kinetic Protocol Client Library for C
|
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
#include <string.h>
#include <assert.h>
#include <err.h>
#include <poll.h>
#include <errno.h>
#include "threadpool_internals.h"
Go to the source code of this file.
Macros | |
#define | MIN_DELAY 10 /* msec */ |
#define | DEFAULT_MAX_DELAY 10000 /* msec */ |
#define | INFINITE_DELAY -1 /* poll will only return upon an event */ |
#define | DEFAULT_TASK_RINGBUF_SIZE2 8 |
#define | DEFAULT_MAX_THREADS 8 |
Functions | |
static void | notify_new_task (struct threadpool *t) |
static bool | notify_shutdown (struct threadpool *t) |
static bool | spawn (struct threadpool *t) |
static void * | thread_task (void *thread_info) |
static void | commit_current_task (struct threadpool *t, struct marked_task *task, size_t wh) |
static void | release_current_task (struct threadpool *t, struct marked_task *task, size_t rh) |
static void | set_defaults (struct threadpool_config *cfg) |
struct threadpool * | Threadpool_Init (struct threadpool_config *cfg) |
Initialize a threadpool, according to a config. More... | |
bool | Threadpool_Schedule (struct threadpool *t, struct threadpool_task *task, size_t *pushback) |
Schedule a task in the threadpool. More... | |
void | Threadpool_Stats (struct threadpool *t, struct threadpool_info *info) |
If TI is non-NULL, fill out some statistics about the operating state of the thread pool. More... | |
bool | Threadpool_Shutdown (struct threadpool *t, bool kill_all) |
Notify the threadpool's threads that the system is going to shut down soon. More... | |
void | Threadpool_Free (struct threadpool *t) |
Free a threadpool. More... | |
#define MIN_DELAY 10 /* msec */ |
Definition at line 31 of file threadpool.c.
#define DEFAULT_MAX_DELAY 10000 /* msec */ |
Definition at line 32 of file threadpool.c.
#define INFINITE_DELAY -1 /* poll will only return upon an event */ |
Definition at line 33 of file threadpool.c.
#define DEFAULT_TASK_RINGBUF_SIZE2 8 |
Definition at line 34 of file threadpool.c.
#define DEFAULT_MAX_THREADS 8 |
Definition at line 35 of file threadpool.c.
|
static |
Definition at line 208 of file threadpool.c.
References threadpool::live_threads, threadpool::max_threads, NOTIFY_MSG, NOTIFY_MSG_LEN, thread_info::parent_fd, spawn(), SPIN_ADJ, thread_info::status, STATUS_ASLEEP, and threadpool::threads.
|
static |
Definition at line 233 of file threadpool.c.
References threadpool::live_threads, thread_info::parent_fd, thread_info::status, STATUS_JOINED, STATUS_SHUTDOWN, thread_info::t, and threadpool::threads.
|
static |
Definition at line 258 of file threadpool.c.
References thread_info::child_fd, threadpool::live_threads, threadpool::max_threads, thread_info::parent_fd, thread_info::status, STATUS_AWAKE, thread_info::t, thread_context::t, thread_task(), and threadpool::threads.
|
static |
Definition at line 292 of file threadpool.c.
References ATOMIC_BOOL_COMPARE_AND_SWAP, thread_info::child_fd, marked_task::cleanup, marked_task::mark, NOTIFY_MSG_LEN, read_buf, release_current_task(), thread_info::status, STATUS_ASLEEP, STATUS_AWAKE, STATUS_SHUTDOWN, thread_context::t, marked_task::task, threadpool::task_commit_head, threadpool::task_request_head, threadpool::task_ringbuf_mask, threadpool::tasks, thread_context::ti, and marked_task::udata.
|
static |
Definition at line 135 of file threadpool.c.
References ATOMIC_BOOL_COMPARE_AND_SWAP, marked_task::mark, threadpool::task_commit_head, threadpool::task_request_head, threadpool::task_ringbuf_mask, and threadpool::tasks.
|
static |
Definition at line 353 of file threadpool.c.
References ATOMIC_BOOL_COMPARE_AND_SWAP, marked_task::mark, threadpool::task_release_head, threadpool::task_ringbuf_mask, and threadpool::tasks.
|
static |
Definition at line 44 of file threadpool.c.
References DEFAULT_MAX_THREADS, DEFAULT_TASK_RINGBUF_SIZE2, threadpool_config::max_threads, and threadpool_config::task_ringbuf_size2.
struct threadpool* Threadpool_Init | ( | struct threadpool_config * | cfg | ) |
Initialize a threadpool, according to a config.
Returns NULL on error.
Definition at line 52 of file threadpool.c.
References threadpool_config::max_threads, threadpool::max_threads, set_defaults(), thread_info::t, threadpool::task_ringbuf_mask, threadpool::task_ringbuf_size, threadpool_config::task_ringbuf_size2, threadpool::task_ringbuf_size2, threadpool::tasks, THREADPOOL_MAX_RINGBUF_SIZE2, and threadpool::threads.
bool Threadpool_Schedule | ( | struct threadpool * | t, |
struct threadpool_task * | task, | ||
size_t * | pushback | ||
) |
Schedule a task in the threadpool.
Returns whether the task was successfully registered or not. If Threadpool_Shutdown has been called, this function will always return false, due to API misuse.
If *pushback is non-NULL, it will be set to the number of tasks in the backlog, so code upstream can provide counterpressure.
TASK is copied into the threadpool by value.
Definition at line 99 of file threadpool.c.
References ATOMIC_BOOL_COMPARE_AND_SWAP, threadpool_task::cleanup, marked_task::cleanup, commit_current_task(), notify_new_task(), threadpool::shutting_down, threadpool_task::task, marked_task::task, threadpool::task_release_head, threadpool::task_reserve_head, threadpool::task_ringbuf_size, threadpool::tasks, threadpool_task::udata, and marked_task::udata.
void Threadpool_Stats | ( | struct threadpool * | t, |
struct threadpool_info * | ti | ||
) |
If TI is non-NULL, fill out some statistics about the operating state of the thread pool.
Definition at line 149 of file threadpool.c.
References threadpool_info::active_threads, threadpool_info::backlog_size, threadpool_info::dormant_threads, threadpool::live_threads, thread_info::status, STATUS_AWAKE, threadpool::task_commit_head, threadpool::task_request_head, and threadpool::threads.
bool Threadpool_Shutdown | ( | struct threadpool * | t, |
bool | kill_all | ||
) |
Notify the threadpool's threads that the system is going to shut down soon.
Returns whether all previously active threads have shut down.
kill_all will eventually permit immediately shutting down all active threads (possibly with memory leaks), but is not yet implemented.
Returns whether everything has halted.
Definition at line 163 of file threadpool.c.
References ATOMIC_BOOL_COMPARE_AND_SWAP, marked_task::cleanup, threadpool::live_threads, notify_shutdown(), threadpool::shutting_down, SPIN_ADJ, thread_info::status, STATUS_SHUTDOWN, thread_info::t, threadpool::task_commit_head, threadpool::task_release_head, threadpool::task_request_head, threadpool::task_ringbuf_mask, threadpool::tasks, threadpool::threads, and marked_task::udata.
void Threadpool_Free | ( | struct threadpool * | t | ) |
Free a threadpool.
Assumes either Threadpool_Shutdown() has been repeatedly called already, or leaking memory and other resources is acceptable.
Definition at line 200 of file threadpool.c.
References threadpool::tasks, and threadpool::threads.