postpone check for cancellation in some driver callbacks

the purpose of these checks is preventing triggering more driver calls,
while immediate followups to already completed calls should be still
made.

note that some of the checks are strictly speaking redundant, as
chaining into a next phase will return immediately anyway when the
other side isn't ready yet. but we keep them for clarity.
This commit is contained in:
Oswald Buddenhagen 2022-05-13 13:02:35 +02:00
parent f29dbb18f1
commit 4c14123144

View File

@ -255,7 +255,7 @@ check_ret( int sts, void *aux )
cancel_sync( svars ); cancel_sync( svars );
return 1; return 1;
} }
return check_cancel( svars ); return 0;
} }
#define SVARS_CHECK_RET \ #define SVARS_CHECK_RET \
@ -263,6 +263,13 @@ check_ret( int sts, void *aux )
return; \ return; \
DECL_INIT_SVARS(aux) DECL_INIT_SVARS(aux)
// After drv->cancel_cmds() on our side, commands may still complete
// successfully, while the other side is already dead.
#define SVARS_CHECK_RET_CANCEL \
SVARS_CHECK_RET; \
if (check_cancel( svars )) \
return
#define SVARS_CHECK_RET_VARS(type) \ #define SVARS_CHECK_RET_VARS(type) \
type *vars = (type *)aux; \ type *vars = (type *)aux; \
if (check_ret( sts, vars->aux )) { \ if (check_ret( sts, vars->aux )) { \
@ -444,7 +451,7 @@ box_confirmed2( sync_vars_t *svars, int t )
static void static void
box_deleted( int sts, void *aux ) box_deleted( int sts, void *aux )
{ {
SVARS_CHECK_RET; SVARS_CHECK_RET_CANCEL;
delete_state( svars ); delete_state( svars );
svars->drv[t]->finish_delete_box( svars->ctx[t] ); svars->drv[t]->finish_delete_box( svars->ctx[t] );
sync_bail( svars ); sync_bail( svars );
@ -453,7 +460,7 @@ box_deleted( int sts, void *aux )
static void static void
box_created( int sts, void *aux ) box_created( int sts, void *aux )
{ {
SVARS_CHECK_RET; SVARS_CHECK_RET_CANCEL;
svars->drv[t]->open_box( svars->ctx[t], box_opened, AUX ); svars->drv[t]->open_box( svars->ctx[t], box_opened, AUX );
} }
@ -767,7 +774,7 @@ box_loaded( int sts, message_t *msgs, int total_msgs, int recent_msgs, void *aux
uchar sflags, nflags, aflags, dflags; uchar sflags, nflags, aflags, dflags;
uint hashsz, idx; uint hashsz, idx;
SVARS_CHECK_RET; SVARS_CHECK_RET_CANCEL;
svars->state[t] |= ST_LOADED; svars->state[t] |= ST_LOADED;
svars->msgs[t] = msgs; svars->msgs[t] = msgs;
info( "%s: %d messages, %d recent\n", str_fn[t], total_msgs, recent_msgs ); info( "%s: %d messages, %d recent\n", str_fn[t], total_msgs, recent_msgs );
@ -1411,6 +1418,8 @@ msg_copied( int sts, uint uid, copy_vars_t *vars )
new_done[t]++; new_done[t]++;
stats(); stats();
svars->new_pending[t]--; svars->new_pending[t]--;
if (check_cancel( svars ))
return;
msgs_copied( svars, t ); msgs_copied( svars, t );
} }
@ -1484,6 +1493,8 @@ msgs_found_new( int sts, message_t *msgs, void *aux )
int num_lost = match_tuids( svars, t, msgs ); int num_lost = match_tuids( svars, t, msgs );
if (num_lost) if (num_lost)
warn( "Warning: lost track of %d %sed message(s)\n", num_lost, str_hl[t] ); warn( "Warning: lost track of %d %sed message(s)\n", num_lost, str_hl[t] );
if (check_cancel( svars ))
return;
msgs_new_done( svars, t ); msgs_new_done( svars, t );
} }
@ -1512,6 +1523,8 @@ flags_set( int sts, void *aux )
flags_done[t]++; flags_done[t]++;
stats(); stats();
svars->flags_pending[t]--; svars->flags_pending[t]--;
if (check_cancel( svars ))
return;
msgs_flags_set( svars, t ); msgs_flags_set( svars, t );
} }
@ -1710,6 +1723,8 @@ msg_trashed( int sts, void *aux )
trash_done[t]++; trash_done[t]++;
stats(); stats();
svars->trash_pending[t]--; svars->trash_pending[t]--;
if (check_cancel( svars ))
return;
sync_close( svars, t ); sync_close( svars, t );
} }
@ -1734,6 +1749,8 @@ msg_rtrashed( int sts, uint uid ATTR_UNUSED, copy_vars_t *vars )
trash_done[t]++; trash_done[t]++;
stats(); stats();
svars->trash_pending[t]--; svars->trash_pending[t]--;
if (check_cancel( svars ))
return;
sync_close( svars, t ); sync_close( svars, t );
} }
@ -1782,7 +1799,7 @@ sync_close( sync_vars_t *svars, int t )
static void static void
box_closed( int sts, int reported, void *aux ) box_closed( int sts, int reported, void *aux )
{ {
SVARS_CHECK_RET; SVARS_CHECK_RET_CANCEL;
if (!reported) { if (!reported) {
for (sync_rec_t *srec = svars->srecs; srec; srec = srec->next) { for (sync_rec_t *srec = svars->srecs; srec; srec = srec->next) {
if (srec->status & S_DEAD) if (srec->status & S_DEAD)