xref: /ext-fiber/src/php_fiber.c (revision b6fe057c)
1 /*
2   +--------------------------------------------------------------------+
3   | ext-fiber                                                          |
4   +--------------------------------------------------------------------+
5   | Redistribution and use in source and binary forms, with or without |
6   | modification, are permitted provided that the conditions mentioned |
7   | in the accompanying LICENSE file are met.                          |
8   +--------------------------------------------------------------------+
9   | Authors: Aaron Piotrowski <aaron@trowski.com>                      |
10   |          Martin Schröder <m.schroeder2007@gmail.com>               |
11   +--------------------------------------------------------------------+
12 */
13 
14 #ifdef HAVE_CONFIG_H
15 # include "config.h"
16 #endif
17 
18 #include "php.h"
19 #include "ext/standard/info.h"
20 
21 #include "php_fiber.h"
22 #include "fiber.h"
23 
24 ZEND_DECLARE_MODULE_GLOBALS(fiber)
25 
PHP_INI_MH(OnUpdateFiberStackSize)26 static PHP_INI_MH(OnUpdateFiberStackSize)
27 {
28 	if (new_value) {
29 		FIBER_G(stack_size) = zend_atol(ZSTR_VAL(new_value), ZSTR_LEN(new_value));
30 	} else {
31 		FIBER_G(stack_size) = ZEND_FIBER_DEFAULT_C_STACK_SIZE;
32 	}
33 	return SUCCESS;
34 }
35 
36 PHP_INI_BEGIN()
37 	STD_PHP_INI_ENTRY("fiber.stack_size", NULL, PHP_INI_ALL, OnUpdateFiberStackSize, stack_size, zend_fiber_globals, fiber_globals)
PHP_INI_END()38 PHP_INI_END()
39 
40 
41 static PHP_GINIT_FUNCTION(fiber)
42 {
43 #if defined(ZTS) && defined(COMPILE_DL_FIBER)
44 	ZEND_TSRMLS_CACHE_UPDATE();
45 #endif
46 
47 	memset(fiber_globals, 0, sizeof(zend_fiber_globals));
48 }
49 
PHP_MINIT_FUNCTION(fiber)50 PHP_MINIT_FUNCTION(fiber)
51 {
52 	zend_register_fiber_ce();
53 
54 	REGISTER_INI_ENTRIES();
55 
56 	return SUCCESS;
57 }
58 
59 
PHP_MSHUTDOWN_FUNCTION(fiber)60 PHP_MSHUTDOWN_FUNCTION(fiber)
61 {
62 	zend_fiber_shutdown();
63 
64 	UNREGISTER_INI_ENTRIES();
65 
66 	return SUCCESS;
67 }
68 
69 
PHP_MINFO_FUNCTION(fiber)70 static PHP_MINFO_FUNCTION(fiber)
71 {
72 	php_info_print_table_start();
73 	php_info_print_table_row(2, "Fiber backend", zend_fiber_backend_info());
74 	php_info_print_table_end();
75 
76 	DISPLAY_INI_ENTRIES();
77 }
78 
79 
PHP_RINIT_FUNCTION(fiber)80 static PHP_RINIT_FUNCTION(fiber)
81 {
82 #if defined(ZTS) && defined(COMPILE_DL_FIBER)
83 	ZEND_TSRMLS_CACHE_UPDATE();
84 #endif
85 
86 	zend_fiber_init();
87 
88 	return SUCCESS;
89 }
90 
PHP_RSHUTDOWN_FUNCTION(fiber)91 static PHP_RSHUTDOWN_FUNCTION(fiber)
92 {
93 	return SUCCESS;
94 }
95 
PHP_GSHUTDOWN_FUNCTION(fiber)96 static PHP_GSHUTDOWN_FUNCTION(fiber)
97 {
98 }
99 
100 zend_module_entry fiber_module_entry = {
101 	STANDARD_MODULE_HEADER,
102 	"fiber",
103 	NULL,
104 	PHP_MINIT(fiber),
105 	PHP_MSHUTDOWN(fiber),
106 	PHP_RINIT(fiber),
107 	PHP_RSHUTDOWN(fiber),
108 	PHP_MINFO(fiber),
109 	PHP_FIBER_VERSION,
110 	PHP_MODULE_GLOBALS(fiber),
111 	PHP_GINIT(fiber),
112 	PHP_GSHUTDOWN(fiber),
113 	NULL,
114 	STANDARD_MODULE_PROPERTIES_EX
115 };
116 
117 
118 #ifdef COMPILE_DL_FIBER
119 # ifdef ZTS
120 ZEND_TSRMLS_CACHE_DEFINE()
121 # endif
122 ZEND_GET_MODULE(fiber)
123 #endif
124 
125 /*
126  * vim: sw=4 ts=4
127  * vim600: fdm=marker
128  */
129