Esempio n. 1
0
/**
 * Creates a vertex
 */
vertex vertex_create()
{
	vertex v;
	vertex_init(&v);

	return v;
}
Esempio n. 2
0
void add_fork(child_pipe *child, int value, vertex *v)
/* Procedure forks vertex. Child process will be initialized with [value] as *
 * value, count equal to one and pipes duped into {0, 1} descriptors.        *
 * Parent process populates [child] structure with analogical descriptors    *
 * providing way to communication. Then sends confirmation signal into       *
 * output.                                                                   *
 *                                                                           *
 * MUTABLE PARAMETERS: v, child                                              */
{
  int result = 1;
  int *in = make_pipe(), *out = make_pipe();
  switch(fork())
  {
    case -1:
      syserr("fork failed");
      break;
    case 0:
      setup_child(in, out);
      vertex_init(v, value);
      break;
    default:
      setup_parent(child, in, out);
      checked_write(1, &result, sizeof(result));
      break;
  }
  free(in);
  free(out);
  return ;
}
Esempio n. 3
0
void graph_add_vertex(struct graph *graph, void *data)
{
	if (vindex_lookup(graph, data) != -1) {
		return;
	}

	if (graph->nr >= graph->sz) {
		graph_grow(graph);
	}

	vertex_init(&graph->vertices[graph->nr]);
	graph->vertices[graph->nr].data = data;

	/* Required for vindex */
	struct vidx_node node;
	node.data = data;
	node.idx = graph->nr;
	hash_insert(graph->vidx, &node);
	graph->nr++;
}
Esempio n. 4
0
int main(int argc, char *argv[])
{
  vertex v;
  command com;
  v.left.in = -1;
  v.right.in = -1; 
 
  vertex_init(&v, 0);
  sscanf(argv[1], "%d", &v.value);

  while(checked_read(0, &com, sizeof(com)))
  {
    switch(com.code)
    {
      case COM_ADD:
        add(&v, com);
        break;
      case COM_FIND:
        find(&v, com);
        break;
      case COM_WALK:
        walk(&v);
        break;
      case COM_STOP:
        if(v.left.in != -1) destroy_child(&v.left);
        if(v.right.in != -1) destroy_child(&v.right);
        close(0);
        close(1);
        exit(0);
        break;
      default:
        fatal("code unknown");
        break;
    }
  }
  return 0;
}