Skip to content

Commit

Permalink
factor a function, zootcl_queue_null_event, and use it
Browse files Browse the repository at this point in the history
  • Loading branch information
lehenbauer committed Jan 13, 2017
1 parent bac061a commit 2f17f4d
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions generic/zookeepertcl.c
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,29 @@ zootcl_stat_completion_callback (int rc, const struct Stat *stat, const void *co
Tcl_ThreadAlert (evPtr->zo->threadId);
}

/*
*--------------------------------------------------------------
*
* zootcl_queue_null_event -- queue a "no op" event to wake
* up the event loop, but the event doesn't actually do anything.
*
* this helps our pseudo-synchronous functions to work.
*
*--------------------------------------------------------------
*/
void
zootcl_queue_null_event (zootcl_syncCallbackContext *zsc)
{
zootcl_callbackEvent *evPtr;

evPtr = ckalloc (sizeof (zootcl_callbackEvent));
evPtr->event.proc = zootcl_EventProc;
evPtr->callbackType = NULL_CALLBACK;
Tcl_ThreadQueueEvent (zsc->zo->threadId, (Tcl_Event *)evPtr, TCL_QUEUE_TAIL);
Tcl_ThreadAlert (zsc->zo->threadId);
}


/*
*--------------------------------------------------------------
*
Expand All @@ -463,7 +486,6 @@ void
zootcl_sync_stat_completion_callback (int rc, const struct Stat *stat, const void *context)
{
zootcl_syncCallbackContext *zsc = (zootcl_syncCallbackContext *)context;
zootcl_callbackEvent *evPtr;
zsc->rc = rc;
if (stat == NULL) {
zsc->haveStat = 0;
Expand All @@ -473,11 +495,7 @@ zootcl_sync_stat_completion_callback (int rc, const struct Stat *stat, const voi
}
zsc->syncDone = 1;
printf("zootcl_sync_stat_completion_callback: done\n");
evPtr = ckalloc (sizeof (zootcl_callbackEvent));
evPtr->event.proc = zootcl_EventProc;
evPtr->callbackType = NULL_CALLBACK;
Tcl_ThreadQueueEvent (zsc->zo->threadId, (Tcl_Event *)evPtr, TCL_QUEUE_TAIL);
Tcl_ThreadAlert (zsc->zo->threadId);
zootcl_queue_null_event (zsc);
}

/*
Expand All @@ -490,13 +508,8 @@ printf("zootcl_sync_stat_completion_callback: done\n");
void
zootcl_sync_data_completion_callback (int rc, const char *value, int valueLen, const struct Stat *stat, const void *context)
{
zootcl_callbackEvent *evPtr;
zootcl_syncCallbackContext *zsc = (zootcl_syncCallbackContext *)context;

evPtr = ckalloc (sizeof (zootcl_callbackEvent));
evPtr->event.proc = zootcl_EventProc;
evPtr->callbackType = NULL_CALLBACK;

zsc->rc = rc;
zsc->syncDone = 1;

Expand All @@ -516,8 +529,7 @@ zootcl_sync_data_completion_callback (int rc, const char *value, int valueLen, c
zsc->stat = *stat;
}

Tcl_ThreadQueueEvent (zsc->zo->threadId, (Tcl_Event *)evPtr, TCL_QUEUE_TAIL);
Tcl_ThreadAlert (zsc->zo->threadId);
zootcl_queue_null_event (zsc);
}

/*
Expand Down

0 comments on commit 2f17f4d

Please sign in to comment.