kinetic-c  v0.12.0
Seagate Kinetic Protocol Client Library for C
Macros | Functions
threadpool.c File Reference
#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 threadpoolThreadpool_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...
 

Macro Definition Documentation

#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.

Function Documentation

static void notify_new_task ( struct threadpool t)
static
static bool notify_shutdown ( struct threadpool t)
static
static bool spawn ( struct threadpool t)
static
static void * thread_task ( void *  thread_info)
static
static void commit_current_task ( struct threadpool t,
struct marked_task task,
size_t  wh 
)
static
static void release_current_task ( struct threadpool t,
struct marked_task task,
size_t  rh 
)
static
static void set_defaults ( struct threadpool_config cfg)
static
struct threadpool* Threadpool_Init ( struct threadpool_config cfg)
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 
)
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.