-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmulq.h
132 lines (106 loc) · 3.02 KB
/
mulq.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
* File: mulq.h
* Author: dryoung
*
* Created on 2012年11月11日, 下午3:58
*/
#ifndef MULQ_H
#define MULQ_H
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <alloca.h>
#include <pthread.h>
#include <sys/types.h>
#include <mysql.h>
#include "php.h"
#include <zend.h>
#include <zend_API.h>
#include <zend_hash.h>
#include <zend_alloc.h>
#ifdef ZTS
#include <TSRM.h>
#endif
#define MULQ_HOST_SIZE 30
#define MULQ_UNIT_ATTACHED 0x1
#define MULQ_UNIT_CALLBACKED 0x4
#define MULQ_THREAD_STARTED 0x2
#define MULQ_THREAD_CONNECTED 0x1
typedef void (*MULQ_UNIT_CALLBACK)(void *data, const char **row, ulong *rlength, const char **field, uint *flength, uint fnum, void *arg TSRMLS_DC);
typedef void *(*MULQ_RUN)(void *unit);
typedef struct _MulqHost {
char host[MULQ_HOST_SIZE];
char user[MULQ_HOST_SIZE];
char pass[MULQ_HOST_SIZE];
uint port;
char unix_socket[MULQ_HOST_SIZE];
} MulqHost;
typedef struct _MulqServer {
zend_object zobject;
HashTable ht;
} MulqServer;
typedef struct _MulqThread {
struct _MulqHost *host;
char *sql;
pthread_t tid;
MYSQL mysql;
uint flag;
struct _MulqUnit *unit;
} MulqThread;
typedef struct _MulqUnit {
zend_object zobject;
HashTable ht;
struct _Mulq *mulq;
ulong h;
void *data;
uint flag;
pthread_mutex_t *lock;
MYSQL_RES *result;
MULQ_RUN run;
pthread_t tid;
HashTable ht_sql;
MULQ_UNIT_CALLBACK callback;
void *arg;
uint run_thread;
zval func_name;
#ifdef ZTS
TSRMLS_D;
#endif
} MulqUnit;
typedef struct _MulqSet {
zend_object zobject;
HashTable ht;
struct _Mulq *mulq;
ulong h;
void *data;
uint flag;
pthread_mutex_t *lock;
MYSQL_RES *result;
MULQ_RUN run;
pthread_t tid;
} MulqSet;
typedef struct _Mulq {
zend_object zobject;
HashTable ht;
} Mulq;
int mulq_server_init(MulqServer **server);
int mulq_server_host(MulqServer *server, char *key, uint key_len, ulong h, const char *host, const char *user, const char *pass, uint port);
int mulq_server_clean(MulqServer *server);
int mulq_server_destroy(MulqServer **server);
int mulq_unit_init(MulqUnit **unit);
int mulq_unit_server(MulqUnit *unit, MulqServer *server);
int mulq_unit_sql(MulqUnit *unit, HashTable *ht_sql);
int mulq_unit_callback(MulqUnit *unit, MULQ_UNIT_CALLBACK callback, zval **func_name, void *arg TSRMLS_DC);
int mulq_unit_container(MulqUnit *unit, void *data);
int mulq_unit_destroy(MulqUnit **unit);
int mulq_set_init(MulqSet **set);
int mulq_set_container(MulqSet *set, void *data);
int mulq_set_attach(MulqSet *set, MulqUnit *unit);
int mulq_set_clean(MulqSet *set);
int mulq_set_destroy(MulqSet **set);
int mulq_init(Mulq **mulq);
int mulq_attach(Mulq *mulq, void *unit, uint size);
int mulq_run(Mulq *mulq);
int mulq_clean(Mulq *mulq);
int mulq_destroy(Mulq **mulq);
#endif /* MULQ_H */