You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
#ifndef TINY_POOL_H_
|
|
|
|
#define TINY_POOL_H_
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <pthread.h>
|
|
|
|
|
|
|
|
typedef struct task_t {
|
|
|
|
void (*func)(void*);
|
|
|
|
void *arg;
|
|
|
|
struct task_t *next;
|
|
|
|
} task_t;
|
|
|
|
|
|
|
|
enum tiny_pool_status {
|
|
|
|
PREPARING,
|
|
|
|
RUNNING,
|
|
|
|
EXITING,
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
|
|
|
pthread_t threads[8];
|
|
|
|
|
|
|
|
enum tiny_pool_status status;
|
|
|
|
pthread_mutex_t status_changing;
|
|
|
|
|
|
|
|
uint32_t busy_thread_num;
|
|
|
|
pthread_mutex_t busy_thread_num_mutex;
|
|
|
|
|
|
|
|
task_t *task_queue_front;
|
|
|
|
task_t *task_queue_rear;
|
|
|
|
uint32_t task_queue_size;
|
|
|
|
pthread_mutex_t task_queue_busy;
|
|
|
|
|
|
|
|
// pthread_cond_t task_queue_empty;
|
|
|
|
pthread_cond_t task_queue_not_empty;
|
|
|
|
|
|
|
|
} pool_t;
|
|
|
|
|
|
|
|
|
|
|
|
pool_t* tiny_pool_create(uint32_t size);
|
|
|
|
|
|
|
|
void tiny_pool_submit(pool_t *pool, void (*func)(void*), void *arg);
|
|
|
|
|
|
|
|
// TODO: confirm just run once
|
|
|
|
void tiny_pool_boot(pool_t *pool);
|
|
|
|
|
|
|
|
// TODO: thread pool status -> preparing / running / exiting / exited
|
|
|
|
|
|
|
|
// TODO: destroy method
|
|
|
|
|
|
|
|
#endif
|