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-07-18 15:51:13 +02:00
|
|
|
#include <pthread.h>
|
|
|
|
|
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
|
2014-07-04 11:28:17 +02:00
|
|
|
#define KORE_TASK_STATE_ABORT 4
|
2014-06-29 20:20:13 +02:00
|
|
|
|
2015-06-04 10:29:22 +02:00
|
|
|
#define KORE_TASK_THREADS 2
|
|
|
|
|
2015-04-01 13:25:10 +02:00
|
|
|
#if defined(__cplusplus)
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2015-11-27 16:22:50 +01:00
|
|
|
#if !defined(KORE_NO_HTTP)
|
2014-06-29 20:20:13 +02:00
|
|
|
struct http_request;
|
2015-11-27 16:22:50 +01:00
|
|
|
#endif
|
2014-06-29 20:20:13 +02:00
|
|
|
|
2014-06-28 16:17:18 +02:00
|
|
|
struct kore_task {
|
2018-10-09 19:34:40 +02:00
|
|
|
struct kore_event evt;
|
2014-07-04 11:28:17 +02:00
|
|
|
int state;
|
|
|
|
int result;
|
|
|
|
pthread_rwlock_t lock;
|
2014-06-29 20:20:13 +02:00
|
|
|
|
2015-11-27 16:22:50 +01:00
|
|
|
#if !defined(KORE_NO_HTTP)
|
2014-06-29 20:20:13 +02:00
|
|
|
struct http_request *req;
|
2015-11-27 16:22:50 +01:00
|
|
|
#endif
|
|
|
|
|
2014-06-29 20:20:13 +02:00
|
|
|
int fds[2];
|
2014-06-30 14:23:04 +02:00
|
|
|
int (*entry)(struct kore_task *);
|
2015-07-01 11:03:54 +02:00
|
|
|
void (*cb)(struct kore_task *);
|
2014-06-28 16:17:18 +02:00
|
|
|
|
2014-06-29 14:15:40 +02:00
|
|
|
struct kore_task_thread *thread;
|
2014-08-14 22:05:34 +02:00
|
|
|
|
2014-06-29 14:15:40 +02:00
|
|
|
TAILQ_ENTRY(kore_task) list;
|
2014-08-14 22:05:34 +02:00
|
|
|
LIST_ENTRY(kore_task) rlist;
|
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);
|
2018-10-09 19:34:40 +02:00
|
|
|
void kore_task_handle(void *, int);
|
2014-06-30 14:35:32 +02:00
|
|
|
void kore_task_run(struct kore_task *);
|
2014-06-28 16:17:18 +02:00
|
|
|
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 *);
|
|
|
|
|
2015-11-27 16:22:50 +01:00
|
|
|
#if !defined(KORE_NO_HTTP)
|
2014-06-29 20:20:13 +02:00
|
|
|
void kore_task_bind_request(struct kore_task *,
|
|
|
|
struct http_request *);
|
2015-11-27 16:22:50 +01:00
|
|
|
#endif
|
2015-07-01 11:03:54 +02:00
|
|
|
void kore_task_bind_callback(struct kore_task *,
|
|
|
|
void (*cb)(struct kore_task *));
|
2014-08-14 22:05:34 +02:00
|
|
|
void kore_task_create(struct kore_task *,
|
2014-06-30 14:23:04 +02:00
|
|
|
int (*entry)(struct kore_task *));
|
2014-06-28 16:17:18 +02:00
|
|
|
|
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);
|
|
|
|
|
2014-07-04 11:28:17 +02:00
|
|
|
void kore_task_set_state(struct kore_task *, int);
|
|
|
|
void kore_task_set_result(struct kore_task *, int);
|
|
|
|
|
|
|
|
int kore_task_state(struct kore_task *);
|
|
|
|
int kore_task_result(struct kore_task *);
|
2015-06-04 10:29:22 +02:00
|
|
|
|
|
|
|
extern u_int16_t kore_task_threads;
|
|
|
|
|
2015-04-01 13:25:10 +02:00
|
|
|
#if defined(__cplusplus)
|
|
|
|
}
|
|
|
|
#endif
|
2014-07-04 11:28:17 +02:00
|
|
|
|
2014-06-28 16:17:18 +02:00
|
|
|
#endif
|