Skip to content

Commit

Permalink
remove SwooleG.main_reactor
Browse files Browse the repository at this point in the history
  • Loading branch information
matyhtf committed Aug 24, 2019
1 parent 5a795cc commit 91b2808
Show file tree
Hide file tree
Showing 35 changed files with 214 additions and 220 deletions.
6 changes: 3 additions & 3 deletions core-tests/include/tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ static void coro_test_fn(void *arg)

static inline void coro_test_wait(int *complete_num, int total_num)
{
SwooleG.main_reactor->once = true;
SwooleTG.reactor->once = true;

while (*complete_num != total_num)
{
SwooleG.main_reactor->wait(SwooleG.main_reactor, nullptr);
SwooleTG.reactor->wait(SwooleTG.reactor, nullptr);
}

SwooleG.main_reactor->once = false;
SwooleTG.reactor->once = false;
}

static inline void coro_test_create(coroutine_func_t fn, void *arg, int *complete_num)
Expand Down
2 changes: 1 addition & 1 deletion core-tests/src/os/signal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ TEST(os_signal, swSignalfd_set)

swSignalfd_init();
swSignal_add(SIGUSR1,sig_usr1);
swSignalfd_setup(SwooleG.main_reactor);
swSignalfd_setup(SwooleTG.reactor);

sigemptyset(&curset);
sigprocmask(SIG_BLOCK, NULL, &curset);
Expand Down
14 changes: 7 additions & 7 deletions gdbinit
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ define timer_list
end

define reactor_info
if SwooleG.main_reactor
printf "\t reactor id: %d\n",SwooleG.main_reactor->id
printf "\t running: %d\n", SwooleG.main_reactor->running
printf "\t event_num: %d\n", SwooleG.main_reactor->event_num
printf "\t max_event_num: %d\n", SwooleG.main_reactor->max_event_num
printf "\t check_timer: %d\n", SwooleG.main_reactor->check_timer
printf "\t timeout_msec: %d\n", SwooleG.main_reactor->timeout_msec
if SwooleTG.reactor
printf "\t reactor id: %d\n",SwooleTG.reactor->id
printf "\t running: %d\n", SwooleTG.reactor->running
printf "\t event_num: %d\n", SwooleTG.reactor->event_num
printf "\t max_event_num: %d\n", SwooleTG.reactor->max_event_num
printf "\t check_timer: %d\n", SwooleTG.reactor->check_timer
printf "\t timeout_msec: %d\n", SwooleTG.reactor->timeout_msec
end
end

Expand Down
6 changes: 3 additions & 3 deletions include/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ typedef struct _swClient
void (*onBufferFull)(struct _swClient *cli);
void (*onBufferEmpty)(struct _swClient *cli);

int (*connect)(struct _swClient *cli, char *host, int port, double _timeout, int sock_flag);
int (*send)(struct _swClient *cli, char *data, int length, int flags);
int (*sendfile)(struct _swClient *cli, char *filename, off_t offset, size_t length);
int (*connect)(struct _swClient *cli, const char *host, int port, double _timeout, int sock_flag);
int (*send)(struct _swClient *cli, const char *data, int length, int flags);
int (*sendfile)(struct _swClient *cli, const char *filename, off_t offset, size_t length);
int (*recv)(struct _swClient *cli, char *data, int len, int flags);
int (*pipe)(struct _swClient *cli, int write_fd, int is_session_id);
int (*close)(struct _swClient *cli);
Expand Down
2 changes: 1 addition & 1 deletion include/coroutine_socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class Socket

static inline swReactor* get_reactor()
{
return SwooleTG.reactor ? SwooleTG.reactor : SwooleG.main_reactor;
return SwooleTG.reactor ? SwooleTG.reactor : SwooleTG.reactor;
}

static inline void init_reactor(swReactor *reactor)
Expand Down
8 changes: 4 additions & 4 deletions include/socks5.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,20 @@ enum swSocks5_method

typedef struct _swSocks5
{
char *host;
const char *host;
int port;

uint8_t state;
uint8_t version;
uint8_t method;
uint8_t dns_tunnel;

char *username;
char *password;
const char *username;
const char *password;
uint16_t l_username;
uint16_t l_password;

char *target_host;
const char *target_host;
int target_port;
uint16_t l_target_host;

Expand Down
1 change: 0 additions & 1 deletion include/swoole.h
Original file line number Diff line number Diff line change
Expand Up @@ -2372,7 +2372,6 @@ typedef struct
swServer *serv;

swMemoryPool *memory_pool;
swReactor *main_reactor;
swTimer timer;

char *task_tmpdir;
Expand Down
2 changes: 1 addition & 1 deletion php_swoole.h
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,7 @@ static sw_inline int php_swoole_check_reactor()
{
return -1;
}
if (sw_unlikely(!SwooleG.main_reactor))
if (sw_unlikely(!SwooleTG.reactor))
{
return php_swoole_reactor_init() == SW_OK ? 1 : -1;
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/base.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ void swoole_clean(void)
{
sw_free(SwooleG.task_tmpdir);
}
if (SwooleG.main_reactor)
if (SwooleTG.reactor)
{
swoole_event_free();
}
Expand Down Expand Up @@ -209,7 +209,7 @@ pid_t swoole_fork(int flags)
/**
* reset eventLoop
*/
if (SwooleG.main_reactor)
if (SwooleTG.reactor)
{
swoole_event_free();
swTraceLog(SW_TRACE_REACTOR, "reactor has been destroyed");
Expand Down
2 changes: 1 addition & 1 deletion src/coroutine/file_lock.cc
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ static inline int lock_nb(char *filename, int fd, int operation)
int swoole_coroutine_flock_ex(char *filename, int fd, int operation)
{
Coroutine *co = Coroutine::get_current();
if (sw_unlikely(SwooleG.main_reactor == nullptr || !co))
if (sw_unlikely(SwooleTG.reactor == nullptr || !co))
{
return ::flock(fd, operation);
}
Expand Down
62 changes: 31 additions & 31 deletions src/coroutine/hook.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ extern "C"

int swoole_coroutine_socket(int domain, int type, int protocol)
{
if (sw_unlikely(SwooleG.main_reactor == nullptr || !Coroutine::get_current()))
if (sw_unlikely(SwooleTG.reactor == nullptr || !Coroutine::get_current()))
{
return socket(domain, type, protocol);
}
Expand All @@ -49,11 +49,11 @@ int swoole_coroutine_socket(int domain, int type, int protocol)

ssize_t swoole_coroutine_send(int sockfd, const void *buf, size_t len, int flags)
{
if (sw_unlikely(SwooleG.main_reactor == nullptr || !Coroutine::get_current()))
if (sw_unlikely(SwooleTG.reactor == nullptr || !Coroutine::get_current()))
{
_no_coro: return ::send(sockfd, buf, len, flags);
}
swSocket *conn = swReactor_get(SwooleG.main_reactor, sockfd);
swSocket *conn = swReactor_get(SwooleTG.reactor, sockfd);
if (conn == nullptr)
{
goto _no_coro;
Expand All @@ -64,11 +64,11 @@ ssize_t swoole_coroutine_send(int sockfd, const void *buf, size_t len, int flags

ssize_t swoole_coroutine_sendmsg(int sockfd, const struct msghdr *msg, int flags)
{
if (sw_unlikely(SwooleG.main_reactor == nullptr || !Coroutine::get_current()))
if (sw_unlikely(SwooleTG.reactor == nullptr || !Coroutine::get_current()))
{
_no_coro: return ::sendmsg(sockfd, msg, flags);
}
swSocket *conn = swReactor_get(SwooleG.main_reactor, sockfd);
swSocket *conn = swReactor_get(SwooleTG.reactor, sockfd);
if (conn == nullptr)
{
goto _no_coro;
Expand All @@ -79,11 +79,11 @@ ssize_t swoole_coroutine_sendmsg(int sockfd, const struct msghdr *msg, int flags

ssize_t swoole_coroutine_recvmsg(int sockfd, struct msghdr *msg, int flags)
{
if (sw_unlikely(SwooleG.main_reactor == nullptr || !Coroutine::get_current()))
if (sw_unlikely(SwooleTG.reactor == nullptr || !Coroutine::get_current()))
{
_no_coro: return ::recvmsg(sockfd, msg, flags);
}
swSocket *conn = swReactor_get(SwooleG.main_reactor, sockfd);
swSocket *conn = swReactor_get(SwooleTG.reactor, sockfd);
if (conn == nullptr)
{
goto _no_coro;
Expand All @@ -94,11 +94,11 @@ ssize_t swoole_coroutine_recvmsg(int sockfd, struct msghdr *msg, int flags)

ssize_t swoole_coroutine_recv(int sockfd, void *buf, size_t len, int flags)
{
if (sw_unlikely(SwooleG.main_reactor == nullptr || !Coroutine::get_current()))
if (sw_unlikely(SwooleTG.reactor == nullptr || !Coroutine::get_current()))
{
_no_coro: return ::recv(sockfd, buf, len, flags);
}
swSocket *conn = swReactor_get(SwooleG.main_reactor, sockfd);
swSocket *conn = swReactor_get(SwooleTG.reactor, sockfd);
if (conn == nullptr)
{
goto _no_coro;
Expand All @@ -116,11 +116,11 @@ ssize_t swoole_coroutine_recv(int sockfd, void *buf, size_t len, int flags)

int swoole_coroutine_close(int fd)
{
if (sw_unlikely(SwooleG.main_reactor == nullptr || !Coroutine::get_current()))
if (sw_unlikely(SwooleTG.reactor == nullptr || !Coroutine::get_current()))
{
_no_coro: return close(fd);
}
swSocket *conn = swReactor_get(SwooleG.main_reactor, fd);
swSocket *conn = swReactor_get(SwooleTG.reactor, fd);
if (conn == nullptr)
{
goto _no_coro;
Expand All @@ -139,11 +139,11 @@ int swoole_coroutine_close(int fd)

int swoole_coroutine_connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen)
{
if (sw_unlikely(SwooleG.main_reactor == nullptr || !Coroutine::get_current()))
if (sw_unlikely(SwooleTG.reactor == nullptr || !Coroutine::get_current()))
{
_no_coro: return connect(sockfd, addr, addrlen);
}
swSocket *conn = swReactor_get(SwooleG.main_reactor, sockfd);
swSocket *conn = swReactor_get(SwooleTG.reactor, sockfd);
if (conn == nullptr)
{
goto _no_coro;
Expand All @@ -154,11 +154,11 @@ int swoole_coroutine_connect(int sockfd, const struct sockaddr *addr, socklen_t

int swoole_coroutine_poll(struct pollfd *fds, nfds_t nfds, int timeout)
{
if (sw_unlikely(SwooleG.main_reactor == nullptr || !Coroutine::get_current() || nfds != 1 || timeout == 0))
if (sw_unlikely(SwooleTG.reactor == nullptr || !Coroutine::get_current() || nfds != 1 || timeout == 0))
{
_poll: return poll(fds, nfds, timeout);
}
swSocket *conn = swReactor_get(SwooleG.main_reactor, fds[0].fd);
swSocket *conn = swReactor_get(SwooleTG.reactor, fds[0].fd);
if (conn == nullptr)
{
goto _poll;
Expand Down Expand Up @@ -258,7 +258,7 @@ static void aio_onCompleted(swAio_event *event)

int swoole_coroutine_open(const char *pathname, int flags, mode_t mode)
{
if (sw_unlikely(SwooleG.main_reactor == nullptr || !Coroutine::get_current()))
if (sw_unlikely(SwooleTG.reactor == nullptr || !Coroutine::get_current()))
{
return open(pathname, flags, mode);
}
Expand All @@ -284,12 +284,12 @@ int swoole_coroutine_open(const char *pathname, int flags, mode_t mode)

ssize_t swoole_coroutine_read(int fd, void *buf, size_t count)
{
if (sw_unlikely(SwooleG.main_reactor == nullptr || !Coroutine::get_current()))
if (sw_unlikely(SwooleTG.reactor == nullptr || !Coroutine::get_current()))
{
return read(fd, buf, count);
}

swSocket *conn = swReactor_get(SwooleG.main_reactor, fd);
swSocket *conn = swReactor_get(SwooleTG.reactor, fd);
if (conn && conn->fdtype == SW_FD_CORO_SOCKET)
{
Socket *socket = (Socket *) conn->object;
Expand Down Expand Up @@ -317,12 +317,12 @@ ssize_t swoole_coroutine_read(int fd, void *buf, size_t count)

ssize_t swoole_coroutine_write(int fd, const void *buf, size_t count)
{
if (sw_unlikely(SwooleG.main_reactor == nullptr || !Coroutine::get_current()))
if (sw_unlikely(SwooleTG.reactor == nullptr || !Coroutine::get_current()))
{
return write(fd, buf, count);
}

swSocket *conn = swReactor_get(SwooleG.main_reactor, fd);
swSocket *conn = swReactor_get(SwooleTG.reactor, fd);
if (conn && conn->fdtype == SW_FD_CORO_SOCKET)
{
Socket *socket = (Socket *) conn->object;
Expand Down Expand Up @@ -350,7 +350,7 @@ ssize_t swoole_coroutine_write(int fd, const void *buf, size_t count)

off_t swoole_coroutine_lseek(int fd, off_t offset, int whence)
{
if (sw_unlikely(SwooleG.main_reactor == nullptr || !Coroutine::get_current()))
if (sw_unlikely(SwooleTG.reactor == nullptr || !Coroutine::get_current()))
{
return lseek(fd, offset, whence);
}
Expand All @@ -376,7 +376,7 @@ off_t swoole_coroutine_lseek(int fd, off_t offset, int whence)

int swoole_coroutine_fstat(int fd, struct stat *statbuf)
{
if (sw_unlikely(SwooleG.main_reactor == nullptr || !Coroutine::get_current()))
if (sw_unlikely(SwooleTG.reactor == nullptr || !Coroutine::get_current()))
{
return fstat(fd, statbuf);
}
Expand All @@ -401,7 +401,7 @@ int swoole_coroutine_fstat(int fd, struct stat *statbuf)

int swoole_coroutine_unlink(const char *pathname)
{
if (sw_unlikely(SwooleG.main_reactor == nullptr || !Coroutine::get_current()))
if (sw_unlikely(SwooleTG.reactor == nullptr || !Coroutine::get_current()))
{
return unlink(pathname);
}
Expand All @@ -425,7 +425,7 @@ int swoole_coroutine_unlink(const char *pathname)

int swoole_coroutine_statvfs(const char *path, struct statvfs *buf)
{
if (sw_unlikely(SwooleG.main_reactor == nullptr || !Coroutine::get_current()))
if (sw_unlikely(SwooleTG.reactor == nullptr || !Coroutine::get_current()))
{
return statvfs(path, buf);
}
Expand All @@ -450,7 +450,7 @@ int swoole_coroutine_statvfs(const char *path, struct statvfs *buf)

int swoole_coroutine_mkdir(const char *pathname, mode_t mode)
{
if (sw_unlikely(SwooleG.main_reactor == nullptr || !Coroutine::get_current()))
if (sw_unlikely(SwooleTG.reactor == nullptr || !Coroutine::get_current()))
{
return mkdir(pathname, mode);
}
Expand All @@ -475,7 +475,7 @@ int swoole_coroutine_mkdir(const char *pathname, mode_t mode)

int swoole_coroutine_rmdir(const char *pathname)
{
if (sw_unlikely(SwooleG.main_reactor == nullptr || !Coroutine::get_current()))
if (sw_unlikely(SwooleTG.reactor == nullptr || !Coroutine::get_current()))
{
return rmdir(pathname);
}
Expand All @@ -499,7 +499,7 @@ int swoole_coroutine_rmdir(const char *pathname)

int swoole_coroutine_rename(const char *oldpath, const char *newpath)
{
if (sw_unlikely(SwooleG.main_reactor == nullptr || !Coroutine::get_current()))
if (sw_unlikely(SwooleTG.reactor == nullptr || !Coroutine::get_current()))
{
return rename(oldpath, newpath);
}
Expand All @@ -524,7 +524,7 @@ int swoole_coroutine_rename(const char *oldpath, const char *newpath)

int swoole_coroutine_access(const char *pathname, int mode)
{
if (sw_unlikely(SwooleG.main_reactor == nullptr || !Coroutine::get_current()))
if (sw_unlikely(SwooleTG.reactor == nullptr || !Coroutine::get_current()))
{
return access(pathname, mode);
}
Expand All @@ -549,7 +549,7 @@ int swoole_coroutine_access(const char *pathname, int mode)

int swoole_coroutine_flock(int fd, int operation)
{
if (sw_unlikely(SwooleG.main_reactor == nullptr || !Coroutine::get_current()))
if (sw_unlikely(SwooleTG.reactor == nullptr || !Coroutine::get_current()))
{
return flock(fd, operation);
}
Expand Down Expand Up @@ -589,7 +589,7 @@ static void handler_readdir(swAio_event *event)

DIR *swoole_coroutine_opendir(const char *name)
{
if (sw_unlikely(SwooleG.main_reactor == nullptr || !Coroutine::get_current()))
if (sw_unlikely(SwooleTG.reactor == nullptr || !Coroutine::get_current()))
{
return opendir(name);
}
Expand All @@ -613,7 +613,7 @@ DIR *swoole_coroutine_opendir(const char *name)

struct dirent *swoole_coroutine_readdir(DIR *dirp)
{
if (sw_unlikely(SwooleG.main_reactor == nullptr || !Coroutine::get_current()))
if (sw_unlikely(SwooleTG.reactor == nullptr || !Coroutine::get_current()))
{
return readdir(dirp);
}
Expand Down
Loading

0 comments on commit 91b2808

Please sign in to comment.