Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core refactor #155

Merged
merged 7 commits into from
Jul 3, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
run admin evloop on main thread to simplify thread setup a bit
  • Loading branch information
Yao Yue committed Jul 3, 2017
commit ff373abd49b23d5128691937eeb69df1dbde68d3
7 changes: 2 additions & 5 deletions src/core/admin/admin.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,6 @@ core_admin_register(uint64_t intvl_ms, timeout_cb_fn cb, void *arg)
{
struct timeout delay;

ASSERT(!__atomic_load_n(&admin_running, __ATOMIC_RELAXED));
ASSERT(admin_init);

timeout_set_ms(&delay, intvl_ms);
Expand All @@ -327,8 +326,8 @@ _admin_evwait(void)
return CC_OK;
}

void *
core_admin_evloop(void *arg)
void
core_admin_evloop(void)
{
for(;;) {
if (_admin_evwait() != CC_OK) {
Expand All @@ -339,7 +338,5 @@ core_admin_evloop(void *arg)
timing_wheel_execute(tw);
}

__atomic_store_n(&admin_running, false, __ATOMIC_RELAXED);

exit(1);
}
4 changes: 1 addition & 3 deletions src/core/admin/admin.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,11 @@ typedef struct {
ADMIN_OPTION(OPTION_DECLARE)
} admin_options_st;

extern bool admin_running;

void core_admin_setup(admin_options_st *options);
void core_admin_teardown(void);

/* add a periodic action to be executed on the admin thread, which uses timing wheel */
struct timeout_event *
core_admin_register(uint64_t intvl_ms, timeout_cb_fn cb, void *arg);

void *core_admin_evloop(void *arg);
void core_admin_evloop(void);
9 changes: 4 additions & 5 deletions src/core/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ core_teardown(void)
void
core_run(void *arg_worker)
{
pthread_t worker, admin;
pthread_t worker, server;
int ret;

if (!core_init) {
Expand All @@ -92,14 +92,13 @@ core_run(void *arg_worker)
goto error;
}

__atomic_store_n(&admin_running, true, __ATOMIC_RELAXED);
ret = pthread_create(&admin, NULL, core_admin_evloop, NULL);
ret = pthread_create(&server, NULL, core_server_evloop, NULL);
if (ret != 0) {
log_crit("pthread create failed for admin thread: %s", strerror(ret));
log_crit("pthread create failed for server thread: %s", strerror(ret));
goto error;
}

core_server_evloop();
core_admin_evloop();

error:
core_teardown();
Expand Down
6 changes: 4 additions & 2 deletions src/core/data/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,13 +280,15 @@ _server_evwait(void)
return CC_OK;
}

void
core_server_evloop(void)
void *
core_server_evloop(void *arg)
{
for(;;) {
if (_server_evwait() != CC_OK) {
log_crit("server core event loop exited due to failure");
break;
}
}

exit(1);
}
2 changes: 1 addition & 1 deletion src/core/data/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ struct addrinfo;

void core_server_setup(server_options_st *options, server_metrics_st *metrics);
void core_server_teardown(void);
void core_server_evloop(void);
void *core_server_evloop(void *arg); /* arg is ignored, signature for pthread_create compatibility */