triton_p.h 1.9 KB
Newer Older
1 2 3
#ifndef TRITON_P_H
#define TRITON_P_H

K
Kozlov Dmitry 已提交
4 5
#include <pthread.h>
#include <sys/epoll.h>
6
#include <ucontext.h>
K
Kozlov Dmitry 已提交
7

8 9
#include "triton.h"
#include "list.h"
K
Kozlov Dmitry 已提交
10
#include "spinlock.h"
11
#include "mempool.h"
K
Kozlov Dmitry 已提交
12

13 14
#define CTX_STACK_SIZE 8196

K
Kozlov Dmitry 已提交
15 16 17 18 19 20
struct _triton_thread_t
{
	struct list_head entry;
	struct list_head entry2;
	pthread_t thread;
	int terminate:1;
21 22
	struct _triton_context_t *ctx;
	ucontext_t uctx;
K
Kozlov Dmitry 已提交
23 24
};

25
struct _triton_context_t
K
Kozlov Dmitry 已提交
26 27 28
{
	struct list_head entry;
	struct list_head entry2;
29
	
K
Kozlov Dmitry 已提交
30
	spinlock_t lock;
31 32
	struct _triton_thread_t *thread;
	
K
Kozlov Dmitry 已提交
33 34 35 36
	struct list_head handlers;
	struct list_head timers;
	struct list_head pending_handlers;
	struct list_head pending_timers;
37
	struct list_head pending_calls;
38 39 40

	ucontext_t uctx;

D
Dmitry Kozlov 已提交
41 42 43 44 45 46 47
	int queued;
	int sleeping;
	int wakeup;
	int need_close;
	int need_free;
	int pending;
	int priority;
K
Kozlov Dmitry 已提交
48

49
	struct triton_context_t *ud;
50
	void *bf_arg;
K
Kozlov Dmitry 已提交
51 52 53 54 55 56
};

struct _triton_md_handler_t
{
	struct list_head entry;
	struct list_head entry2;
57
	struct _triton_context_t *ctx;
K
Kozlov Dmitry 已提交
58 59 60
	struct epoll_event epoll_event;
	uint32_t trig_epoll_events;
	int pending:1;
K
Kozlov Dmitry 已提交
61
	int trig_level:1;
K
Kozlov Dmitry 已提交
62 63 64 65 66 67 68 69
	struct triton_md_handler_t *ud;
};

struct _triton_timer_t
{
	struct list_head entry;
	struct list_head entry2;
	struct epoll_event epoll_event;
70
	struct _triton_context_t *ctx;
K
Kozlov Dmitry 已提交
71 72 73 74 75
	int fd;
	int pending:1;
	struct triton_timer_t *ud;
};

K
Kozlov Dmitry 已提交
76 77 78 79 80
struct _triton_event_t
{
	struct list_head handlers;
};

81 82 83 84 85 86 87 88
struct _triton_ctx_call_t
{
	struct list_head entry;

	void *arg;
	void (*func)(void *);
};

K
Kozlov Dmitry 已提交
89 90
int log_init(void);
int md_init();
K
Kozlov Dmitry 已提交
91 92 93
int timer_init();
int event_init();

K
Kozlov Dmitry 已提交
94 95 96 97
void md_run();
void md_terminate();
void timer_run();
void timer_terminate();
98
extern struct triton_context_t default_ctx;
99
int triton_queue_ctx(struct _triton_context_t*);
K
Kozlov Dmitry 已提交
100
void triton_thread_wakeup(struct _triton_thread_t*);
K
Kozlov Dmitry 已提交
101
int conf_load(const char *fname);
D
Dmitry Kozlov 已提交
102 103
void triton_log_error(const char *fmt,...);
void triton_log_debug(const char *fmt,...);
K
Kozlov Dmitry 已提交
104
int load_modules(const char *name);
105 106

#endif