forked from brewlin/goos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
php_go.h
80 lines (72 loc) · 2.39 KB
/
php_go.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
/* go extension for PHP */
#ifndef PHP_GO_H
# define PHP_GO_H
#include "php.h"
#include "config.h"
#include "php_ini.h"
#include "ext/standard/info.h"
#include "php_network.h"
#include "php_streams.h"
#include "php_globals.h"
#include "php_main.h"
#include "TSRM.h"
#include "zend_variables.h"
#include "zend_interfaces.h"
#include "zend_closures.h"
#include "zend_exceptions.h"
#include <mutex>
#include <condition_variable>
#include <queue>
#include <iostream>
using namespace std;
using timep = chrono::steady_clock::time_point;
extern zend_module_entry go_module_entry;
extern zend_class_entry *go_coroutine_ce_ptr;
class Coroutine;
ZEND_EXTERN_MODULE_GLOBALS(go)
#ifndef GO_ZG
ZEND_BEGIN_MODULE_GLOBALS(go)
queue<Coroutine*>* free_stack;
queue<Coroutine*>* runq;
pid_t pid;
int signal;
void*** local;
//执行抢占标记检测
timep schedwhen;
int schedtick;
zval _this;
Coroutine* _g;
mutex* _glock;
HashTable resolve;
HashTable filenames;
HashTable* resources;
int hard_copy_interned_strings;
ZEND_END_MODULE_GLOBALS(go)
/**
* MACRO FETCH TSRM
*/
# define FETCH_CTX(ls, id, type, element) (((type) (*((void ***) ls))[TSRM_UNSHUFFLE_RSRC_ID(id)])->element)
# define FETCH_CTX_ALL(ls, id, type) ((type) (*((void ***) ls))[TSRM_UNSHUFFLE_RSRC_ID(id)])
# define GO_CG(ls, v) FETCH_CTX(ls, compiler_globals_id, zend_compiler_globals*, v)
# define GO_FETCH(ls, v) FETCH_CTX(ls, go_globals_id, zend_go_globals*, v)
# define GO_ZG(v) TSRMG(go_globals_id, zend_go_globals *, v)
# define GO_PID() GO_ZG(pid) ? GO_ZG(pid) : (GO_ZG(pid)=getpid())
# define GO_SG(ls, v) FETCH_CTX(ls, sapi_globals_id, sapi_globals_struct*, v)
#endif
# define PHP_GO_VERSION "0.1.0"
# if defined(ZTS) && defined(COMPILE_DL_GO)
ZEND_TSRMLS_CACHE_EXTERN()
# endif
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
static zend_string *zend_string_new(zend_string *s)
{
if (ZSTR_IS_INTERNED(s)) {
if (!GO_ZG(hard_copy_interned_strings)) {
return s;
}
return zend_new_interned_string(zend_string_init(ZSTR_VAL(s), ZSTR_LEN(s), GC_FLAGS(s) & IS_STR_PERSISTENT));
}
return zend_string_dup(s, GC_FLAGS(s) & IS_STR_PERSISTENT);
}
#endif /* PHP_GO_H */