예제 #1
0
파일: stream.c 프로젝트: stefankok/snet-rts
void SNetStreamClose(snet_stream_desc_t *sd, int destroy_s)
{
  if (destroy_s) {
    SNetStreamDestroy(sd->stream);
  }
  SNetMemFree(sd);
}
예제 #2
0
파일: stream.c 프로젝트: stefankok/snet-rts
void SNetStreamReplace(snet_stream_desc_t *sd, snet_stream_t *new_stream)
{
  assert( sd->mode == 'r' );
  SNetStreamDestroy(sd->stream);
  pthread_mutex_lock( &new_stream->lock);
  new_stream->consumer = sd;
  new_stream->is_poll = 0;
  pthread_mutex_unlock( &new_stream->lock);
  sd->stream = new_stream;
}
예제 #3
0
파일: xfeedback.c 프로젝트: ra-one/snet-rts
/* Destroy a feedback node. */
void SNetStopFeedback(node_t *node, fifo_t *fifo)
{
  feedback_arg_t *farg = NODE_SPEC(node, feedback);
  trace(__func__);
  if (farg->stopping == 0) {
    farg->stopping = 1;
    SNetStopStream(farg->instance, fifo);
  }
  else if (farg->stopping == 1) {
    farg->stopping = 2;
    SNetStopStream(farg->output, fifo);
    SNetVariantListDestroy(farg->back_patterns);
    SNetExprListDestroy(farg->guards);
    SNetStreamDestroy(farg->selfref2);
    SNetStreamDestroy(farg->selfref4);
    SNetEntityDestroy(farg->entity);
    SNetDelete(node);
  }
}
예제 #4
0
파일: xstream.c 프로젝트: ra-one/snet-rts
/* Deallocate a stream, but remember it's destination node. */
void SNetStopStream(snet_stream_t *stream, fifo_t *fifo)
{
  SNetFifoPut(fifo, STREAM_DEST(stream));
  SNetStreamDestroy(stream);
}
예제 #5
0
/**
 * Convenience function for creating
 * Star, DetStar, StarIncarnate or DetStarIncarnate,
 * dependent on parameters is_incarnate and is_det.
 */
static snet_stream_t *CreateStar(
    snet_stream_t       *input,
    snet_info_t         *info,
    int                  location,
    snet_variant_list_t *exit_patterns,
    snet_expr_list_t    *guards,
    snet_startup_fun_t   box_a,
    snet_startup_fun_t   box_b,
    bool                 is_incarnate,
    bool                 is_det)
{
  snet_stream_t *output;
  node_t        *node;
  star_arg_t    *sarg;
  snet_locvec_t *locvec;

  locvec = SNetLocvecGet(info);
  if (!is_incarnate) {
    SNetLocvecStarEnter(locvec);
  } else {
    assert(false);
  }

  output = SNetStreamCreate(0);
  node = SNetNodeNew(NODE_star, location, &input, 1, &output, 1,
                     SNetNodeStar, SNetStopStar, SNetTermStar);
  sarg = NODE_SPEC(node, star);
  sarg->input = input;
  sarg->collector = output;
  sarg->exit_patterns = exit_patterns;
  sarg->guards = guards;
  sarg->is_incarnate = is_incarnate;
  sarg->is_det = is_det;
  sarg->is_detsup = (SNetDetGetLevel() > 0);
  sarg->stopping = 0;

  /* create operand A */
  sarg->instance = SNetNodeStreamCreate(node);
  (void) SNetLocvecStarSpawn(locvec);
  SNetSubnetIncrLevel();
  sarg->internal = (*box_a)(sarg->instance, info, location);
  SNetSubnetDecrLevel();
  (void) SNetLocvecStarSpawnRet(locvec);
  /* direct destination of operand back to this node */
  STREAM_DEST(sarg->internal) = node;

  /* Is this a Star followed by only a Sync? */
  if (SNetZipperEnabled() &&
      NODE_TYPE(STREAM_DEST(sarg->instance)) == NODE_sync &&
      STREAM_FROM(sarg->internal) == STREAM_DEST(sarg->instance))
  {
    /* Replace the combination of star + sync with a fused sync-star. */
    sync_arg_t *sync = NODE_SPEC(STREAM_DEST(sarg->instance), sync);
    /* if (SNetVerbose()) {
      printf("Replacing a star + sync with a fused sync-star.\n");
    } */
    output = SNetZipper(input, info, location, exit_patterns, guards,
                        sync->patterns, sync->guard_exprs);
    SNetEntityDestroy(sync->entity);
    SNetVariantDestroy(sync->merged_pattern);
    SNetDelete(STREAM_DEST(sarg->instance));
    SNetStreamDestroy(sarg->instance);
    SNetStreamDestroy(sarg->internal);
    SNetStreamDestroy(sarg->collector);
    SNetMemFree(node);
  } else {
    sarg->entity = SNetEntityCreate( ENTITY_star, location, locvec,
                                     "<star>", NULL, (void *) sarg);
    if (!is_incarnate) {
      /* the "top-level" star also creates a collector */
      output = SNetCollectorDynamic(sarg->collector, location, info,
                                    is_det, node);
      SNetNodeTableAdd(sarg->internal);
    }
  }

  if (!is_incarnate) {
    SNetLocvecStarLeave(locvec);
  }

  return output;
}