Skip to content

Commit

Permalink
Move sw_coro_* to PHPCoroutine.
Browse files Browse the repository at this point in the history
  • Loading branch information
twose committed Dec 26, 2018
1 parent 68c1eb2 commit 8a85ccf
Show file tree
Hide file tree
Showing 25 changed files with 488 additions and 496 deletions.
18 changes: 9 additions & 9 deletions gdbinit
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ define ____get_current
if swCoroG.call_stack_size > 0
set $current_co = (coroutine_t*)swCoroG.call_stack[swCoroG.call_stack_size - 1]
set $current_cid = $current_co->cid
set $current_task = (coro_task *)$current_co->task
set $current_task = (php_coro_task *)$current_co->task
else
set $current_co = null
set $current_cid = -1
Expand All @@ -11,11 +11,11 @@ define ____get_current
end

define co_list
if COROG.coro_num == 0
if PHPCoroutine::coro_num == 0
printf "no coroutines running \n"
end
set $cid = 1
while $cid < COROG.coro_num + 1
while $cid < PHPCoroutine::coro_num + 1
if swCoroG.coroutines[$cid]
printf "coroutine %d ", $cid
set $co = swCoroG.coroutines[$cid]
Expand All @@ -41,7 +41,7 @@ define co_list
end

define co_bt
if COROG.coro_num == 0
if PHPCoroutine::coro_num == 0
printf "no coroutines running \n"
end
____executor_globals
Expand Down Expand Up @@ -82,7 +82,7 @@ define __co_bt
dump_bt $eg.current_execute_data
else
set $co = (coroutine_t *)swCoroG.coroutines[$cid]
set $task = (coro_task *)$co->task
set $task = (php_coro_task *)$co->task
if $task
set $backup = $eg.current_execute_data
dump_bt $task->execute_data
Expand All @@ -97,10 +97,10 @@ end
define co_status
printf "\t stack_size: %d\n", swCoroG.stack_size
printf "\t call_stack_size: %d\n", swCoroG.call_stack_size
printf "\t active: %d\n", COROG.active
printf "\t coro_num: %d\n", COROG.coro_num
printf "\t max_coro_num: %d\n", COROG.max_coro_num
printf "\t peak_coro_num: %d\n", COROG.peak_coro_num
printf "\t active: %d\n", PHPCoroutine::active
printf "\t coro_num: %d\n", PHPCoroutine::coro_num
printf "\t max_coro_num: %d\n", PHPCoroutine::max_coro_num
printf "\t peak_coro_num: %d\n", PHPCoroutine::peak_coro_num
end

define ____executor_globals
Expand Down
5 changes: 0 additions & 5 deletions include/coroutine.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@
#include <string>
#include <unordered_map>

#define SW_DEFAULT_MAX_CORO_NUM 3000
#define SW_DEFAULT_STACK_SIZE 8192
#define SW_DEFAULT_SOCKET_CONNECT_TIMEOUT 1
#define SW_DEFAULT_SOCKET_TIMEOUT -1

#define CORO_END 0
#define CORO_LIMIT -1
#define CORO_INVALID -2
Expand Down
1 change: 0 additions & 1 deletion php_swoole.h
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,6 @@ PHPAPI int php_swoole_unserialize(void *buffer, size_t len, zval *return_value,

#ifdef SW_COROUTINE
int php_coroutine_reactor_can_exit(swReactor *reactor);
void sw_coro_check_bind(const char *name, long bind_cid);
#endif

#ifdef SW_USE_OPENSSL
Expand Down
18 changes: 10 additions & 8 deletions swoole_async.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include <string>
#include <unordered_map>

using namespace swoole;

typedef struct
{
zval _callback;
Expand All @@ -48,7 +50,7 @@ typedef struct
zval _domain;
zval *callback;
zval *domain;
php_context *context;
php_coro_context *context;
uint8_t useless;
swTimer_node *timer;
} dns_request;
Expand Down Expand Up @@ -221,7 +223,7 @@ static void coro_onDNSCompleted(char *domain, swDNSResolver_result *result, void
return;
}

int ret = sw_coro_resume(req->context, zaddress, retval);
int ret = PHPCoroutine::resume_m(req->context, zaddress, retval);
if (ret > 0)
{
goto free_zdata;
Expand All @@ -241,7 +243,7 @@ static void dns_timeout_coro(swTimer *timer, swTimer_node *tnode)
{
zval *retval = NULL;
zval *zaddress;
php_context *cxt = (php_context *) tnode->data;
php_coro_context *cxt = (php_coro_context *) tnode->data;
dns_request *req = (dns_request *) cxt->coro_params.value.ptr;

SW_MAKE_STD_ZVAL(zaddress);
Expand All @@ -256,7 +258,7 @@ static void dns_timeout_coro(swTimer *timer, swTimer_node *tnode)
ZVAL_STRING(zaddress, "");
}

int ret = sw_coro_resume(req->context, zaddress, retval);
int ret = PHPCoroutine::resume_m(req->context, zaddress, retval);
if (ret > 0)
{
goto free_zdata;
Expand Down Expand Up @@ -1192,12 +1194,12 @@ PHP_METHOD(swoole_async, exec)
PHP_FUNCTION(swoole_async_dns_lookup_coro)
{
zval *domain;
double timeout = COROG.socket_connect_timeout;
double timeout = PHPCoroutine::socket_connect_timeout;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|d", &domain, &timeout) == FAILURE)
{
RETURN_FALSE;
}
coro_check();
PHPCoroutine::check();
if (Z_TYPE_P(domain) != IS_STRING)
{
swoole_php_fatal_error(E_WARNING, "invalid domain name.");
Expand Down Expand Up @@ -1228,7 +1230,7 @@ PHP_FUNCTION(swoole_async_dns_lookup_coro)
sw_copy_to_stack(req->domain, req->_domain);
req->useless = 0;

php_context *context = (php_context *) emalloc(sizeof(php_context));
php_coro_context *context = (php_coro_context *) emalloc(sizeof(php_coro_context));
context->state = SW_CORO_CONTEXT_RUNNING;
context->coro_params.value.ptr = (void *) req;
req->context = context;
Expand All @@ -1245,6 +1247,6 @@ PHP_FUNCTION(swoole_async_dns_lookup_coro)
{
context->state = SW_CORO_CONTEXT_IN_DELAYED_TIMEOUT_LIST;
}
sw_coro_yield(return_value, context);
PHPCoroutine::yield_m(return_value, context);
}
#endif
4 changes: 2 additions & 2 deletions swoole_channel_coro.cc
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ static PHP_METHOD(swoole_channel_coro, __construct)

static PHP_METHOD(swoole_channel_coro, push)
{
coro_check();
PHPCoroutine::check();

Channel *chan = swoole_get_channel(getThis());
if (chan->closed)
Expand Down Expand Up @@ -201,7 +201,7 @@ static PHP_METHOD(swoole_channel_coro, push)

static PHP_METHOD(swoole_channel_coro, pop)
{
coro_check();
PHPCoroutine::check();

Channel *chan = swoole_get_channel(getThis());
if (chan->closed)
Expand Down
18 changes: 9 additions & 9 deletions swoole_client_coro.cc
Original file line number Diff line number Diff line change
Expand Up @@ -732,8 +732,8 @@ static PHP_METHOD(swoole_client_coro, connect)
sw_coro_socket_set(cli, zset);
}

sw_coro_check_bind("client", cli->has_bound());
cli->set_timeout(timeout == 0 ? COROG.socket_connect_timeout : timeout);
PHPCoroutine::check_bind("client", cli->has_bound());
cli->set_timeout(timeout == 0 ? PHPCoroutine::socket_connect_timeout : timeout);
if (!cli->connect(host, port, sock_flag))
{
swoole_php_error(E_WARNING, "connect to server[%s:%d] failed. Error: %s[%d]", host, (int )port, cli->errMsg, cli->errCode);
Expand All @@ -743,7 +743,7 @@ static PHP_METHOD(swoole_client_coro, connect)
}
else
{
cli->set_timeout(timeout == 0 ? COROG.socket_timeout : timeout);
cli->set_timeout(timeout == 0 ? PHPCoroutine::socket_timeout : timeout);
zend_update_property_bool(swoole_client_coro_ce_ptr, getThis(), ZEND_STRL("connected"), 1);
RETURN_TRUE;
}
Expand Down Expand Up @@ -775,7 +775,7 @@ static PHP_METHOD(swoole_client_coro, send)

//clear errno
SwooleG.error = 0;
sw_coro_check_bind("client", cli->has_bound());
PHPCoroutine::check_bind("client", cli->has_bound());
double persistent_timeout = cli->get_timeout();
cli->set_timeout(timeout);
int ret = cli->send_all(data, data_len);
Expand Down Expand Up @@ -821,7 +821,7 @@ static PHP_METHOD(swoole_client_coro, sendto)
}
cli->socket->active = 1;
}
sw_coro_check_bind("client", cli->has_bound());
PHPCoroutine::check_bind("client", cli->has_bound());
SW_CHECK_RETURN(cli->sendto(ip, port, data, len));
}

Expand Down Expand Up @@ -853,7 +853,7 @@ static PHP_METHOD(swoole_client_coro, recvfrom)
}

zend_string *retval = zend_string_alloc(length + 1, 0);
sw_coro_check_bind("client", cli->has_bound());
PHPCoroutine::check_bind("client", cli->has_bound());
// cli->set_timeout(timeout, true); TODO
ssize_t n_bytes = cli->recvfrom(retval->val, length);
if (n_bytes < 0)
Expand Down Expand Up @@ -901,7 +901,7 @@ static PHP_METHOD(swoole_client_coro, sendfile)
}
//clear errno
SwooleG.error = 0;
sw_coro_check_bind("client", cli->has_bound());
PHPCoroutine::check_bind("client", cli->has_bound());
int ret = cli->sendfile(file, offset, length);
if (ret < 0)
{
Expand Down Expand Up @@ -930,7 +930,7 @@ static PHP_METHOD(swoole_client_coro, recv)
{
RETURN_FALSE;
}
sw_coro_check_bind("client", cli->has_bound());
PHPCoroutine::check_bind("client", cli->has_bound());
double persistent_timeout = cli->get_timeout();
cli->set_timeout(timeout);
ssize_t retval ;
Expand Down Expand Up @@ -1154,7 +1154,7 @@ static PHP_METHOD(swoole_client_coro, enableSSL)
{
sw_coro_socket_set_ssl(cli, zset);
}
sw_coro_check_bind("client", cli->has_bound());
PHPCoroutine::check_bind("client", cli->has_bound());
if (cli->ssl_handshake() == false)
{
RETURN_FALSE;
Expand Down
6 changes: 1 addition & 5 deletions swoole_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,6 @@

#define SW_TABLE_CONFLICT_PROPORTION 0.2 //20%
#define SW_TABLE_KEY_SIZE 64
//#define SW_TABLE_USE_PHP_HASH
//#define SW_TABLE_DEBUG
#define SW_TABLE_USE_SPINLOCK 1

#define SW_SSL_BUFFER_SIZE 16384
Expand Down Expand Up @@ -253,9 +251,7 @@
/**
* Coroutine
*/
#define SW_DEFAULT_MAX_CORO_NUM 3000
#define SW_DEFAULT_STACK_SIZE 8192
#define SW_DEFAULT_C_STACK_SIZE (1024 * 1024 * 2)
#define SW_DEFAULT_C_STACK_SIZE (2 *1024 * 1024)
#define SW_MAX_CORO_NUM_LIMIT 9223372036854775807LL
#define SW_MAX_CORO_NESTING_LEVEL 128

Expand Down
Loading

0 comments on commit 8a85ccf

Please sign in to comment.