Rejigger the event loop again

This commit is contained in:
Steve Dee 2014-02-28 14:52:00 -08:00 committed by Steven Dee
parent 3f7e6d5e94
commit d045f31f23
5 changed files with 34 additions and 23 deletions

View File

@ -788,15 +788,15 @@
/** Main loop, new style.
**/
/* u2_lo_boot(): restore or create pier.
*/
void
u2_lo_boot(void);
/* u2_lo_loop(): enter main event loop.
*/
void
u2_lo_loop(u2_reck* rec_u);
u2_lo_loop(void);
/* u2_lo_lead(): actions on promotion to leader.
*/
void
u2_lo_lead(u2_reck* rec_u);
/* u2_lo_exit(): shut down io across pier.
*/
@ -1083,10 +1083,10 @@
u2_bean
u2_raft_readopt(u2_ropt* rop_u, const c3_c* arg_c);
/* u2_raft_io_init(): initialize raft I/O.
/* u2_raft_init(): start Raft process.
*/
void
u2_raft_io_init(void);
u2_raft_init(void);
/* u2_raft_work(): poke, kick, and push pending events.
*/

View File

@ -164,7 +164,6 @@ _lo_init()
u2_term_io_init();
u2_http_io_init();
u2_save_io_init();
u2_raft_io_init();
u2_batz_io_init();
}
@ -630,10 +629,10 @@ _lo_slow()
#endif
}
/* u2_lo_boot(): restore or create pier.
/* u2_lo_boot(): begin main event loop.
*/
void
u2_lo_boot()
u2_lo_loop()
{
uv_loop_t* lup_u = uv_default_loop();
@ -643,13 +642,17 @@ u2_lo_boot()
// signal(SIGIO, SIG_IGN); // linux is wont to produce for some reason
_lo_init();
u2_sist_boot();
u2_raft_init();
if ( u2_no == u2_Host.ops_u.bat ) {
uv_run(u2L, UV_RUN_DEFAULT);
}
}
/* u2_lo_loop(): begin main event loop.
/* u2_lo_lead(): actions on promotion to leader.
*/
void
u2_lo_loop(u2_reck* rec_u)
u2_lo_lead(u2_reck* rec_u)
{
_lo_talk();
{

View File

@ -410,10 +410,7 @@ main(c3_i argc,
u2_lo_grab("main", u2_none);
u2_lo_boot();
u2_lo_loop();
if ( u2_no == u2_Host.ops_u.bat ) {
u2_lo_loop(u2_Host.arv_u);
}
return 0;
}

View File

@ -85,6 +85,19 @@ _raft_election_rand()
return ((float) rand() / RAND_MAX) * 150;
}
/* _raft_promote(): actions on raft leader election.
*/
static void
_raft_promote(u2_raft* raf_u)
{
raf_u->typ_e = u2_raty_lead;
u2_sist_boot();
if ( u2_no == u2_Host.ops_u.bat ) {
u2_lo_lead(u2A);
}
}
/* _raft_do_rest(): act on an incoming raft RPC request.
*/
static void
@ -545,13 +558,13 @@ _raft_lone_init(u2_raft* raf_u)
{
uL(fprintf(uH, "raft: single-instance mode\n"));
raf_u->typ_e = u2_raty_lead;
_raft_promote(raf_u);
}
/* u2_raft_io_init(): begin raft I/O.
/* u2_raft_init(): start Raft process.
*/
void
u2_raft_io_init()
u2_raft_init()
{
u2_raft* raf_u = u2R;
@ -782,7 +795,6 @@ void
u2_raft_work(u2_reck* rec_u)
{
if ( u2R->typ_e != u2_raty_lead ) {
uL(fprintf(uH, "raft: working while not leader?!\n"));
c3_assert(rec_u->ova.egg_u == 0);
if ( u2_nul != rec_u->roe ) {
uL(fprintf(uH, "raft: dropping roe!!\n"));

View File

@ -863,5 +863,4 @@ u2_sist_boot(void)
{
u2_http_ef_bake();
}
}