2014-06-28 16:17:18 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2014 Joris Vink <joris@coders.se>
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __H_KORE_TASKS
|
|
|
|
#define __H_KORE_TASKS
|
|
|
|
|
2014-06-29 20:20:13 +02:00
|
|
|
#define KORE_TASK_STATE_CREATED 1
|
|
|
|
#define KORE_TASK_STATE_RUNNING 2
|
|
|
|
#define KORE_TASK_STATE_FINISHED 3
|
|
|
|
|
|
|
|
struct http_request;
|
|
|
|
|
2014-06-28 16:17:18 +02:00
|
|
|
struct kore_task {
|
2014-06-29 20:20:13 +02:00
|
|
|
u_int8_t type;
|
|
|
|
u_int8_t state;
|
|
|
|
|
|
|
|
struct http_request *req;
|
|
|
|
int fds[2];
|
|
|
|
void (*entry)(struct kore_task *);
|
2014-06-28 16:17:18 +02:00
|
|
|
|
2014-06-29 14:15:40 +02:00
|
|
|
struct kore_task_thread *thread;
|
|
|
|
TAILQ_ENTRY(kore_task) list;
|
2014-06-28 16:17:18 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct kore_task_thread {
|
2014-06-29 14:15:40 +02:00
|
|
|
u_int8_t idx;
|
|
|
|
pthread_t tid;
|
|
|
|
pthread_mutex_t lock;
|
|
|
|
pthread_cond_t cond;
|
|
|
|
TAILQ_HEAD(, kore_task) tasks;
|
2014-06-28 16:17:18 +02:00
|
|
|
|
|
|
|
TAILQ_ENTRY(kore_task_thread) list;
|
|
|
|
};
|
|
|
|
|
|
|
|
void kore_task_init(void);
|
|
|
|
void kore_task_finish(struct kore_task *);
|
|
|
|
void kore_task_destroy(struct kore_task *);
|
2014-06-29 20:20:13 +02:00
|
|
|
int kore_task_finished(struct kore_task *);
|
2014-06-28 16:17:18 +02:00
|
|
|
void kore_task_handle(struct kore_task *, int);
|
2014-06-29 20:20:13 +02:00
|
|
|
|
|
|
|
void kore_task_bind_request(struct kore_task *,
|
|
|
|
struct http_request *);
|
|
|
|
void kore_task_create(struct kore_task **,
|
2014-06-28 16:17:18 +02:00
|
|
|
void (*entry)(struct kore_task *));
|
|
|
|
|
2014-06-29 14:15:40 +02:00
|
|
|
u_int32_t kore_task_channel_read(struct kore_task *, void *, u_int32_t);
|
2014-06-28 16:17:18 +02:00
|
|
|
void kore_task_channel_write(struct kore_task *, void *, u_int32_t);
|
|
|
|
|
|
|
|
#endif
|