example/thread-pool/psi.c
static int
transform_handler(INKCont contp, INKEvent event, void *edata)
{
  INKVIO input_vio;
  ContData *data;
  int state, lock, retval;

  /* This section will be called by both TS internal
     and the thread. Protect it with a mutex to avoid
     concurrent calls. */
  lock = INKMutexTryLock(INKContMutexGet(contp));

  /* Handle TryLock result */
  if (!lock) {
    INKCont c = INKContCreate(trylock_handler, NULL);
    TryLockData *d = INKmalloc(sizeof(TryLockData));
    d->contp = contp;
    d->event = event;
    INKContDataSet(c, d);
    INKContSchedule(c, 10);
    return 1;
  }

  data = INKContDataGet(contp);
  INKAssert(data->magic == MAGIC_ALIVE);

  state = data->state;

  /* Check to see if the transformation has been closed */
  retval = INKVConnClosedGet(contp);
  if (retval == INK_ERROR) {
    INKError("[transform_handler] Error while getting close status of transformation");
  }
  if (retval) {
    /* If the thread is still executing its job, we don't want to destroy
       the continuation right away as the thread will call us back
       on this continuation. */
    if (state == STATE_READ_PSI) {
      INKContSchedule(contp, 10);
    } else {
      INKMutexUnlock(INKContMutexGet(contp));
      cont_data_destroy(INKContDataGet(contp));
      INKContDestroy(contp);
      return 1;
    }
  } else {
    switch (event) {
    case INK_EVENT_ERROR:
      input_vio = INKVConnWriteVIOGet(contp);
      if (input_vio == INK_ERROR_PTR) {
        INKError("[transform_handler] Error while getting upstream vio");
      } else {
        INKContCall(INKVIOContGet(input_vio), INK_EVENT_ERROR, input_vio);
      }
      break;

    case INK_EVENT_VCONN_WRITE_COMPLETE:
      INKVConnShutdown(INKTransformOutputVConnGet(contp), 0, 1);
      break;

    case INK_EVENT_VCONN_WRITE_READY:
      /* downstream vconnection is done reading data we've write into it.
         let's read some more data from upstream if we're in read state. */
      if (state == STATE_READ_DATA) {
        handle_transform(contp);
      }
      break;

    case INK_EVENT_IMMEDIATE:
      if (state == STATE_READ_DATA) {
        /* upstream vconnection signals some more data ready to be read
           let's try to transform some more data */
        handle_transform(contp);
      } else if (state == STATE_DUMP_PSI) {
        /* The thread scheduled an event on our continuation to let us
           know it has completed its job
           Let's dump the include content to the output vconnection */
        dump_psi(contp);
        wake_up_streams(contp);
      }
      break;

    default:
      INKAssert(!"Unexpected event");
      break;
    }
  }

  INKMutexUnlock(INKContMutexGet(contp));
  return 1;
}
/*-------------------------------------------------------------------------
  transform_handler
  Handler for all events received during the transformation process

  Input:
    contp      continuation for the current transaction
    event      event received
    data       pointer on optional data
  Output :
  Return Value:
  -------------------------------------------------------------------------*/
transform_handler
Handler for all events received during the transformation process

contp      continuation for the current transaction
event      event received
data       pointer on optional data
Output :
Return Value.
transform_handler Handler for all events received during the transformation process contp continuation for the current transaction event event received data pointer on optional data Output : Return Value .
static int
transform_handler(INKCont contp, INKEvent event, void *edata)
{
  INKVIO input_vio;
  ContData *data;
  int state, lock, retval;
  lock = INKMutexTryLock(INKContMutexGet(contp));
  if (!lock) {
    INKCont c = INKContCreate(trylock_handler, NULL);
    TryLockData *d = INKmalloc(sizeof(TryLockData));
    d->contp = contp;
    d->event = event;
    INKContDataSet(c, d);
    INKContSchedule(c, 10);
    return 1;
  }
  data = INKContDataGet(contp);
  INKAssert(data->magic == MAGIC_ALIVE);
  state = data->state;
  retval = INKVConnClosedGet(contp);
  if (retval == INK_ERROR) {
    INKError("[transform_handler] Error while getting close status of transformation");
  }
  if (retval) {
    if (state == STATE_READ_PSI) {
      INKContSchedule(contp, 10);
    } else {
      INKMutexUnlock(INKContMutexGet(contp));
      cont_data_destroy(INKContDataGet(contp));
      INKContDestroy(contp);
      return 1;
    }
  } else {
    switch (event) {
    case INK_EVENT_ERROR:
      input_vio = INKVConnWriteVIOGet(contp);
      if (input_vio == INK_ERROR_PTR) {
        INKError("[transform_handler] Error while getting upstream vio");
      } else {
        INKContCall(INKVIOContGet(input_vio), INK_EVENT_ERROR, input_vio);
      }
      break;
    case INK_EVENT_VCONN_WRITE_COMPLETE:
      INKVConnShutdown(INKTransformOutputVConnGet(contp), 0, 1);
      break;
    case INK_EVENT_VCONN_WRITE_READY:
      if (state == STATE_READ_DATA) {
        handle_transform(contp);
      }
      break;
    case INK_EVENT_IMMEDIATE:
      if (state == STATE_READ_DATA) {
        handle_transform(contp);
      } else if (state == STATE_DUMP_PSI) {
        dump_psi(contp);
        wake_up_streams(contp);
      }
      break;
    default:
      INKAssert(!"Unexpected event");
      break;
    }
  }
  INKMutexUnlock(INKContMutexGet(contp));
  return 1;
}
static int transform_handler ( INKCont contp , INKEvent event , void * edata ) { INKVIO input_vio ; ContData * data ; int state , lock , retval ; lock = INKMutexTryLock ( INKContMutexGet ( contp ) ) ; if ( ! lock ) { INKCont c = INKContCreate ( trylock_handler , NULL ) ; TryLockData * d = INKmalloc ( sizeof ( TryLockData ) ) ; d -> contp = contp ; d -> event = event ; INKContDataSet ( c , d ) ; INKContSchedule ( c , 10 ) ; return 1 ; } data = INKContDataGet ( contp ) ; INKAssert ( data -> magic == MAGIC_ALIVE ) ; state = data -> state ; retval = INKVConnClosedGet ( contp ) ; if ( retval == INK_ERROR ) { INKError ( " " ) ; } if ( retval ) { if ( state == STATE_READ_PSI ) { INKContSchedule ( contp , 10 ) ; } else { INKMutexUnlock ( INKContMutexGet ( contp ) ) ; cont_data_destroy ( INKContDataGet ( contp ) ) ; INKContDestroy ( contp ) ; return 1 ; } } else { switch ( event ) { case INK_EVENT_ERROR : input_vio = INKVConnWriteVIOGet ( contp ) ; if ( input_vio == INK_ERROR_PTR ) { INKError ( " " ) ; } else { INKContCall ( INKVIOContGet ( input_vio ) , INK_EVENT_ERROR , input_vio ) ; } break ; case INK_EVENT_VCONN_WRITE_COMPLETE : INKVConnShutdown ( INKTransformOutputVConnGet ( contp ) , 0 , 1 ) ; break ; case INK_EVENT_VCONN_WRITE_READY : if ( state == STATE_READ_DATA ) { handle_transform ( contp ) ; } break ; case INK_EVENT_IMMEDIATE : if ( state == STATE_READ_DATA ) { handle_transform ( contp ) ; } else if ( state == STATE_DUMP_PSI ) { dump_psi ( contp ) ; wake_up_streams ( contp ) ; } break ; default : INKAssert ( ! " " ) ; break ; } } INKMutexUnlock ( INKContMutexGet ( contp ) ) ; return 1 ; }
transform_handler
Handler for all events received during the transformation process
transform_handler Handler for all events received during the transformation process
/* This section will be called by both TS internal
     and the thread. Protect it with a mutex to avoid
     concurrent calls. */ /* Handle TryLock result */ /* Check to see if the transformation has been closed */ /* If the thread is still executing its job, we don't want to destroy
       the continuation right away as the thread will call us back
       on this continuation. */ /* downstream vconnection is done reading data we've write into it.
         let's read some more data from upstream if we're in read state. */ /* upstream vconnection signals some more data ready to be read
           let's try to transform some more data */ /* The thread scheduled an event on our continuation to let us
           know it has completed its job
           Let's dump the include content to the output vconnection */