Пример #1
0
cache_t *lru_cache_create(void *arg, data_attr_t *da, int timeout)
{
    cache_t *cache;
    cache_lru_t *c;

    type_malloc_clear(cache, cache_t, 1);
    type_malloc_clear(c, cache_lru_t, 1);
    cache->fn.priv = c;

    cache_base_create(cache, da, timeout);

    cache->shutdown_request = 0;
    c->stack = new_stack();
    c->waiting_stack = new_stack();
    c->pending_free_tasks = new_stack();
    c->max_bytes = 100*1024*1024;
    c->bytes_used = 0;
    c->dirty_fraction = 0.1;
    cache->n_ppages = 0;
    cache->max_fetch_fraction = 0.1;
    cache->max_fetch_size = cache->max_fetch_fraction * c->max_bytes;
    cache->write_temp_overflow_used = 0;
    cache->write_temp_overflow_fraction = 0.01;
    cache->write_temp_overflow_size = cache->write_temp_overflow_fraction * c->max_bytes;

    c->dirty_bytes_trigger = c->dirty_fraction * c->max_bytes;
    c->dirty_max_wait = apr_time_make(1, 0);
    c->flush_in_progress = 0;
    c->limbo_pages = 0;
    c->free_pending_tables = new_pigeon_coop("free_pending_tables", 50, sizeof(list_t *), cache->mpool, free_pending_table_new, free_pending_table_free);
    c->free_page_tables = new_pigeon_coop("free_page_tables", 50, sizeof(page_table_t), cache->mpool, free_page_tables_new, free_page_tables_free);

    cache->fn.create_empty_page = lru_create_empty_page;
    cache->fn.adjust_dirty = lru_adjust_dirty;
    cache->fn.destroy_pages = lru_pages_destroy;
    cache->fn.cache_update = lru_update;
    cache->fn.cache_miss_tag = lru_miss_tag;
    cache->fn.s_page_access = lru_page_access;
    cache->fn.s_pages_release = lru_pages_release;
    cache->fn.destroy = lru_cache_destroy;
    cache->fn.adding_segment = lru_adding_segment;
    cache->fn.removing_segment = lru_removing_segment;
    cache->fn.get_handle = cache_base_handle;

    apr_thread_cond_create(&(c->dirty_trigger), cache->mpool);
    thread_create_assert(&(c->dirty_thread), NULL, lru_dirty_thread, (void *)cache, cache->mpool);

    return(cache);
}
Пример #2
0
main()
{
  Queue q;
  Stack s;
  Jval v;
  IS is;
  int i;

  q = new_queue();
  s = new_stack();
  i = 0;
  is = new_inputstruct(NULL);

  while (get_line(is) >= 0) {
    if (i % 2 == 0) {
      queue_enqueue(q, new_jval_s(strdup(is->fields[0])));
    } else {
      stack_push(s, new_jval_s(strdup(is->fields[0])));
    }
    i++;
  }
  while (!queue_empty(q)) { 
    v = queue_dequeue(q);
    printf("%s\n", v.s);
  }
  while (!stack_empty(s)) { 
    v = stack_pop(s);
    printf("%s\n", v.s);
  }
}
char		*str_to_btree_it(t_def *def, int first, int last)
{
  t_stack	*node;
  t_number	*nbr;
  char		*number;
  int		i;

  if ((node = new_stack(NULL, 0, first, 0)) == NULL)
    return (NULL);
  node->last = last;
  if ((nbr = new_number(NULL, NULL)) == NULL)
    return (NULL);
  while (node != NULL)
    {
      find_first_last(&first, &last, def, node);
      if ((i = find_the_operator(def, first, last)) == -1)
	nbr = calc_in_bt(&node, &nbr, def);
      else
	number = stack_me_that(def, &node, &nbr, i);
      if (nbr == NULL || number == NULL)
	return (NULL);
    }
  number = nbr->nbr;
  free(nbr->prev);
  free(nbr);
  return (number);
}
int main(int argc, char *argv[])
{
    stack *s;
	item_type item;
	item = 10;

    if (new_stack(&s) < 0 ) {
		printf("Error in initializing the stack\n");
		return 0;
	}
    push(s, &item);
    printf("Item:%d, Empty?%s, size:%d\n", size(s), empty(s)? "Yes": "No", item);
	if (pop(s, &item) < 0) {
		printf("Invalid pop access\n");
		return 0;
	}

    printf("Item:%d, Empty?%s, size:%d\n", size(s), empty(s)? "Yes": "No", item);

	if (pop(s, &item) ) {
		printf("Invalid pop access\n");
		return 0;
	}
    printf("Item:%d, Empty?%s, size:%d\n", size(s), empty(s)? "Yes": "No", item);
    return 0;
}
Пример #5
0
main()
{
  IS is;
  Queue q;
  Stack s;
  Dllist l;
  int i;
  Jval j;

  is = new_inputstruct(NULL);

  while (get_line(is) > 0) {
    q = new_queue();
    s = new_stack();
    l = new_dllist();
    for (i = 0; i < strlen(is->fields[0]); i++) {
      queue_enqueue(q, new_jval_c(is->fields[0][i]));
      stack_push(s, new_jval_c(is->fields[0][i]));
      dll_append(l, new_jval_c(is->fields[0][i]));
      dll_prepend(l, new_jval_c(is->fields[0][i]));
    }
    while (!queue_empty(q)) {
      j = queue_dequeue(q); printf("%c", j.c);
      j = stack_pop(s); printf("%c", j.c);
      printf("%c", l->flink->val.c); dll_delete_node(l->flink);
      printf("%c", l->flink->val.c); dll_delete_node(l->flink);
      printf(" ");
    }
    printf("\n");
    free_queue(q);
    free_stack(s);
    free_dllist(l);
  }
}
Пример #6
0
int main (int argc, char **argv) {
   program_name = basename (argv[0]);
   scan_options (argc, argv);
   stack *stack = new_stack ();
   token *scanner = new_token (stdin);
   for (;;) {
      int token = scan_token (scanner);
      if (token == EOF) break;
      switch (token) {
         case NUMBER: do_push (stack, peek_token (scanner)); break;
         case '+': do_binop (stack, add_bigint); break;
         case '-': do_binop (stack, sub_bigint); break;
         case '*': do_binop (stack, mul_bigint); break;
         case 'c': do_clear (stack); break;
         case 'f': do_print_all (stack); break;
         case 'p': do_print (stack); break;
         default: unimplemented (token); break;
      }
   }
   
   do_clear(stack);
   free_stack(stack);
   free_token(scanner);
   DEBUGF ('m', "EXIT %d\n", exit_status);
   return EXIT_SUCCESS;
}
Пример #7
0
int main(int argc, char **argv) {
  int i;
  int x;
  int p;
  Stack stack = new_stack(argc);
  for(i=0; i <= argc; i++){
    if(argv[i] == NULL){
      printf("you have no args %d", i);
      break;
    }
    else if(isdigit(argv[i][0])){
      p = atoi(argv[i]);
      printf("arg %d\n", p);
      push_stack(stack, p);
    }
    else if(strcmp(argv[i],"+")==0 || strcmp(argv[i],"-")==0 || strcmp(argv[i],"x")==0 || strcmp(argv[i],"/")==0){
      printf("arg %s\n", argv[i]);
      char* arg = argv[i];
      calc(arg, stack);
    }
    else{
      printf("args %s", argv[i]);
    }
  }
}
Пример #8
0
int main (int argc, char **argv) {
   program_name = basename (argv[0]);
   scan_options (argc, argv);
   stack *stack = new_stack ();
   bool quit = false;
   yy_flex_debug = false;
   while (! quit) {
      int token = yylex();
      if (token == YYEOF) break;
      switch (token) {
         case NUMBER: do_push (stack, yytext); break;
         case '+': do_binop (stack, add_bigint); break;
         case '-': do_binop (stack, sub_bigint); break;
         case '*': do_binop (stack, mul_bigint); break;
         case 'c': do_clear (stack); break;
         case 'f': do_print_all (stack); break;
         case 'p': do_print (stack); break;
         case 'q': quit = true; break;
         default: unimplemented (token); break;
      }
   }
   yycleanup();
   DEBUGF ('m', "EXIT %d\n", exit_status);
   do_clear(stack);
   free_stack(stack);
   return EXIT_SUCCESS;
}
Пример #9
0
Stack *Read_LSM_Stack(char *file_name)
{
  Stack *stack;

  TIFF  *tif;
  int    depth, width, height, kind;

  tif = Open_Tiff(file_name,"r");
  if (!tif) return 0; //070805, bu Hanchuan Peng
	
  depth = 1;
  while (TIFFReadDirectory(tif))
    depth += 1;
  TIFFClose(tif);
  depth = depth / 2;		/* half the dirs are thumbnails */

  tif = Open_Tiff(file_name,"r");
  TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &width);
  TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &height);

  kind  = determine_kind(tif);
  stack = new_stack(depth*height*width*kind,"Read_Stack");

  stack->width  = width;
  stack->height = height;
  stack->depth  = depth;
  stack->kind   = kind;

  printf("test1 done\n");

  int d;

  d = 0;
  /* read every other directory (real data, the in between are thumbnails */
  while (1)
  {
	  read_directory(tif,Select_Plane(stack,d),"Read_Stack");
	  
	  d += 1;
	  if (!TIFFReadDirectory(tif)) break;
	  /* skip the one we just read, it's a thumbnail  */

	  if (!TIFFReadDirectory(tif)) break;
	  
	  TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &width);
	  TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &height);
	  if (width != stack->width || height != stack->height)
          error("Images of stack are not of the same dimensions!",NULL);
	  
	  kind = determine_kind(tif);
	  if (kind != stack->kind)
          error("Images of stack are not of the same type (GREY, GREY16, or COLOR)!",NULL);
  }
  
  TIFFClose(tif);

  return (stack);
}
Пример #10
0
void push(stack_t* stack, void* d)
{
    stack_t		*s;

    s = new_stack();
    s->data = d;
    s->next = stack->next;
    stack->next = s;
}
Пример #11
0
double farmer(int numprocs) {
	
	MPI_Status status;
	stack* bag_of_tasks = new_stack();
	
	int i,id;
	int tag = -1;
	double area = 0.0;
	
	/* slackers is a variable to keep track of the free ("slacking") processes.*/
	int slackers = numprocs-1; 
	int* is_worker_busy = (int*) malloc(sizeof(int)*(numprocs-1)); 
	
	/* An integer array for workers. If 1 then the worker is busy if 0 then it is not doing any tasks.
	We fill the array with zeroes initially since none of the workers are working. */
	for (i=0;i<slackers;i++){
		is_worker_busy[i] = 0;
	}
		
	double point[2];
	point[0] = A;
	point[1] = B;
	/* We push the initial task on the bag of tasks stack*/	
	push(point, bag_of_tasks);
	
	
	while ((!is_empty(bag_of_tasks)||slackers!=0)&&(tag!=READY_TAG)){
		
		MPI_Recv(point, 2, MPI_DOUBLE, MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &status); 
		
		id = status.MPI_SOURCE;
		tag = status.MPI_TAG;
		is_worker_busy[id-1] = 1;
		slackers--;

		if ( tag == AREA_TAG) { 
			area += point[0];
		}
		else if (tag == SPLIT_TAG) { 
			push(point,bag_of_tasks);
      			MPI_Recv(point, 2, MPI_DOUBLE, id, tag, MPI_COMM_WORLD, &status);
      			push(point,bag_of_tasks);
		} 
		
		
		slackers=send_tasks(bag_of_tasks,is_worker_busy,slackers,tasks_per_process);
		
	}	


	// Signal all the workers that we are ready.
	for (i=1;i<numprocs;i++) { 

		MPI_Send(NULL, 0, MPI_INT, i, READY_TAG, MPI_COMM_WORLD);
	}
	return area;
}
Пример #12
0
Stack *Read_Stack_Planes(char *prefix, int num_width, int first_num)
{ Stack *stack;

  char  sname[1000];
  int   width, height, depth, kind;
  TIFF *tif;

  depth = 0;
  while (1)
    { FILE *fd;

      sprintf(sname,"%s%0*d.tif",prefix,num_width,first_num+depth);
      if ((fd = fopen(sname,"r")) == NULL)
        break;
      fclose(fd);

      depth += 1;
    }

  sprintf(sname,"%s%0*d.tif",prefix,num_width,first_num);
  tif = Open_Tiff(sname,"r");
  TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &width);
  TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &height);

  kind  = determine_kind(tif);
  stack = new_stack(depth*height*width*kind,"Read_Stack_Planes");

  stack->width  = width;
  stack->height = height;
  stack->depth  = depth;
  stack->kind   = kind;

  { int d;

    d = 0;
    while (1)
      { read_directory(tif,Select_Plane(stack,d),"Read_Stack_Planes");
        TIFFClose(tif);

        d += 1;
        if (d >= depth) break;

        sprintf(sname,"%s%0*d.tif",prefix,num_width,first_num+d);
        tif = Open_Tiff(sname,"r");
        TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &width);
        TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &height);
        if (width != stack->width || height != stack->height)
          error("Images of stack are not of the same dimensions!",NULL);

        kind = determine_kind(tif);
        if (kind != stack->kind)
          error("Images of stack are not of the same type (GREY, GREY16, or COLOR)!",NULL);
      }
  }

  return (stack);
}
Пример #13
0
int main() {
    node* stack = new_stack();
    int i;
    for (i=0; i<10; i++) {
       stack_push(stack, i);
    }
    assert(stack_peek(stack) == 9);
    assert(stack_pop(stack) == 9);
    assert(stack_peek(stack) == 8);
}
Пример #14
0
Stack *Copy_Stack(Stack *stack)
{ Stack *copy = new_stack(stack_vsize(stack),"Copy_Stack");

  copy->kind   = stack->kind;
  copy->width  = stack->width;
  copy->height = stack->height;
  copy->depth  = stack->depth;
  memcpy(copy->array,stack->array,stack_vsize(stack));
  return (copy);
}
Пример #15
0
/**
 * Pushes a value onto the stack.
 * @param value The value to be pushed onto the stack.
 * @return 0 upon success or 1 if an memory error occurs.
 */
int push(int value) {
    if (!stack && new_stack(INITIAL_CAPACITY)) {
        return 1;
    }
    if (stack->size == stack->capacity && extend_capacity(stack->capacity * 2)) {
        return 1;
    }
    stack->values[stack->size++] = value;
    return 0;
}
Пример #16
0
Файл: main.c Проект: Ahmed-Z/wf
void parse_input(FILE* input, list__t* w_list)
{
    char c;
    char* str;
    int strlen = 0;

    link__t* w_link;
    
    int str_exist;
    
    stack__t* stack = new_stack();
    
    
    for(;;){
        c = fgetc(input);
        if(isalnum(c) && !isspace(c)){
            stack_push(stack , c);
        }else if(c  != EOF){

            if(stack->next != NULL){//stack empty do nothing
                strlen = stack_size(stack);
                str = xmalloc( strlen + 1 );
                str[strlen] = stack->c;// the head has the value '\0'
                while(stack->next != NULL)
                    str[--strlen] = tolower(stack_pop(stack));
                w_list->word_count ++;
                /**
                 * Loop through the list and check if the word already exist
                 */
                
                link__t* w_link = w_list->first;
                while( w_link != NULL ){
                    
                    if( !strcmp ( str , w_link->word->text) ){
                        w_link->word->count+=1;
                        break;
                    }
                    
                  w_link = w_link->next;      
                }
                
                if(w_link == NULL)
                    insert__last(w_list, str);
                
                free(str);

            }
        }else
            break;
        
    }
    
   free_stack(&stack);       
    
}
Пример #17
0
void gop_dummy_init()
{
    //** Make the variables
    assert_result(apr_pool_create(&gd_pool, NULL), APR_SUCCESS);
    assert_result(apr_thread_mutex_create(&gd_lock, APR_THREAD_MUTEX_DEFAULT, gd_pool), APR_SUCCESS);
    assert_result(apr_thread_cond_create(&gd_cond, gd_pool), APR_SUCCESS);
    gd_stack = new_stack();

    //** and launch the thread
    thread_create_assert(&gd_thread, NULL, gd_thread_func, NULL, gd_pool);
}
Пример #18
0
// List directories in depth first order
void recursive_list (char *path) {
   stack = new_stack ();
   push_stack (stack, path);
   for (;;) {
      char *dir = pop_stack (stack);
      printf ("%s:\n", dir);
      list (dir);
      if (is_empty_stack (stack)) break;
      printf ("\n");
   }
   free_stack (stack);
}
Пример #19
0
void Thread::shrink_execution_stack(int new_stack_size) {
  GCDisabler dont_gc_for_rest_of_this_method;
  ExecutionStack::Raw old_stack = execution_stack();
  GUARANTEE(new_stack_size < old_stack().length(), "sanity check");

  ExecutionStack::Raw new_stack = old_stack().shrink_in_place(new_stack_size);
  // We shrink the stack in place, so we do not need to discard the
  // old stack in any way.  Universe::shrink_object takes care of that.
  set_execution_stack(&new_stack);
  new_stack().set_thread(this);

  set_stack_limit();
}
Пример #20
0
Файл: vu.c Проект: gvx/deja
int main(int argc, char *argv[])
{
	const struct option options[] = {
		{"help", no_argument, NULL, 'h'},
		{"debug", no_argument, NULL, 'd'},
		{"version", no_argument, NULL, 'v'},
		{"silent", no_argument, NULL, 's'},
		{"persist", no_argument, NULL, 'p'},
		{0, 0, 0, 0},
	};
	char opt;
	while ((opt = getopt_long(argc, argv, "+hdvsp", options, NULL)) != -1)
	{
		switch (opt)
		{
		case 'h':
			puts("Usage: vu [OPTIONS] [module [SCRIPT ARGUMENTS]]\n"
			     "  -h, --help     Show this help message and exit\n"
			     "  -v, --version  Show the VM version and exit\n"
			     "  -d, --debug    Enable debugging\n"
			     "  -s, --silent   Do not print the stack after running\n"
			     "  -p, --persist  Use standard input and output to persist the stack\n"
			     "                 This option is intended for internal use; implies --silent");
			return 0;
		case 'v':
			printf("vu virtual machine 0.2\nbyte code protocol %d.%d\n", VERSION >> 4, VERSION & 15);
			return 0;
		case 's':
			vm_silent = true;
			break;
		case 'd':
			vm_debug = true;
			break;
		case 'p':
			vm_persist = true;
			vm_silent = true;
			break;
		}
	}

	signal(SIGINT, handle_interrupt);
	init_module_path();
	init_errors();
	V global = new_global_scope();
	V v_eva = open_std_lib(toHashMap(toScope(global)->env));
	Stack *S = new_stack();
	init_argv(argc - optind, argv + optind, v_eva);
	run(global, S);
	clear_stack(S);
	return 0;
}
Пример #21
0
Task_que_t *create_task_que()
{
  Task_que_t *tq;

//  if ((tq = g_slice_new(Task_que_t)) == NULL) {
  if ((tq = (Task_que_t *)malloc(sizeof(Task_que_t))) == NULL) {
     log_printf(0, "create_task_que: Unable to allocate new struct!\n");
     flush_log();
     return(NULL);
  }

  tq->cid = NULL;
  tq->refcount = 0;
  tq->op = -1;
  tq->owner = -1;
  tq->lock_inuse = 0;
  tq->io_que[TASK_READ_QUE] = new_stack();
  tq->io_que[TASK_WRITE_QUE] = new_stack();

  pthread_mutex_init(&(tq->qlock), NULL);

  return(tq);
}
Пример #22
0
Файл: stack.c Проект: xiaoy/post
int main()
{
    struct Stack* s = new_stack(2);
    int i;
    for(i = 0; i < 100; ++i)
    {
        push(s, i);
    }
    printf("stack len:%d\n", s->len);

    for(i = 0; i < 100; ++i)
    {
        printf("pop:%d\n", pop(s));
    }
}
Пример #23
0
Stack *Read_Stack(char *file_name)
{ Stack *stack;

  TIFF  *tif;
  int    depth, width, height, kind;

  tif = Open_Tiff(file_name,"r");
  depth = 1;
  while (TIFFReadDirectory(tif))
    depth += 1;
  TIFFClose(tif);

  tif = Open_Tiff(file_name,"r");
  TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &width);
  TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &height);

  kind  = determine_kind(tif);
  stack = new_stack(depth*height*width*kind,"Read_Stack");

  stack->width  = width;
  stack->height = height;
  stack->depth  = depth;
  stack->kind   = kind;

  { int d;

    d = 0;
    while (1)
      { read_directory(tif,Select_Plane(stack,d),"Read_Stack");

        d += 1;
        if (!TIFFReadDirectory(tif)) break;

        TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &width);
        TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &height);
        if (width != stack->width || height != stack->height)
          error("Images of stack are not of the same dimensions!",NULL);

        kind = determine_kind(tif);
        if (kind != stack->kind)
          error("Images of stack are not of the same type (GREY, GREY16, or COLOR)!",NULL);
      }
  }

  TIFFClose(tif);

  return (stack);
}
Пример #24
0
/**
 * Extends the capacity of the stack (for big values, allows not to reallocate several successive times the stack).
 * Values added on the stack are left uninitialized.
 * @param size The number of blocs to add.
 * @return 0 upon success or 1 if an memory error occurs.
 */
int extend_stack(int size) {
	int required_cap = stack->size + size, new_size;
	if (!stack && new_stack(size > INITIAL_CAPACITY ? size : INITIAL_CAPACITY)) {
		return 1;
	}

	if (required_cap > stack->capacity) {
		new_size = stack->capacity * 2;
		if (extend_capacity(new_size > required_cap ? new_size : required_cap)) {
			return 1;
		}
	}

	stack->size += size;
	return 0;
}
Пример #25
0
int main( int argc, char** argv ) {

  screen s;
  struct matrix *edges;
  struct stack *transform;

  edges = new_matrix(4, 4);
  transform = new_stack();

  if ( argc == 2 )
    parse_file( argv[1], transform, edges, s );
  else
    parse_file( "stdin", transform, edges, s );

  free_stack( transform );
  free_matrix( edges );
}  
Пример #26
0
Stack *Make_Stack(int kind, int width, int height, int depth)
{ Stack *stack;

  if (Warnings)
    { Warnings = 0;
      TIFFSetWarningHandler(NULL);
    }

  stack = new_stack(depth*height*width*kind,"Make_Stack");

  stack->width  = width;
  stack->height = height;
  stack->depth  = depth;
  stack->kind   = kind;

  return (stack);
}
Пример #27
0
Stack * dijkstra(List_adj * la,int source,int target,enum dijkstra_mode mode){
	Stack * stack = new_stack();
	int i,current;
	Cell * tmp_list;
	int link_value[3][3]= {{1,1},{1,100},{1,3}};
	int tmp;
	dijkstra_t * dij = new_dijkstra_s(la->size);
	if(mode>3 || mode<0)mode=0;
	if(source>la->size || source<0)return NULL;
	if(target>la->size || target<0)return NULL;
	if(la==NULL)return NULL;
	for (i=0;i<dij->size;i++){
		dij->visited[i] = white;
		dij->parent[i] = -2;
		dij->distance[i] = 1000000;
	}
	dij->distance[source] = 0;
	dij->parent[source] = -1;
	/*printf("dij->size %d\n",dij->size);*/
	
	current = min_distance(dij);
	while(current!=-1) {
		dij->visited[current] = black;
		tmp_list = la->list[current];
		while (tmp_list != NULL){
			/*printf("a visiter current=%d,target=%d\n",current,tmp_list->target);*/
			if ( dij->visited[tmp_list->target] == white){
				if (dij->distance[tmp_list->target] > dij->distance[current] + link_value[mode][tmp_list->linkvalue]){

					dij->distance[tmp_list->target]	= dij->distance[current] + link_value[mode][tmp_list->linkvalue];
					dij->parent[tmp_list->target] = current;
				}
			}
			tmp_list = tmp_list->next;
		}
		current = min_distance(dij);
	}
	tmp=target;
	while(dij->parent[tmp] != -1){
		push(stack,tmp);
		tmp=dij->parent[tmp];
	}
	push(stack,source);
	return stack;
}
Пример #28
0
int main() {
  STACK *init = new_stack();
  STACK **stack = &init;
  push(stack, 3);
  push(stack, 2);
  push(stack, 1);
  int one = pop(stack);
  printf("one: %d\n", one);
  int two = pop(stack);
  printf("two: %d\n", two);
  int three = pop(stack);
  printf("three: %d\n", three);
  //int hmm = pop(stack);
  push(stack, 5);
  printf("peek: %d", peek(stack));
  free(init);
  return 0;
}
Пример #29
0
// Tasks
rust_task::rust_task(rust_sched_loop *sched_loop, rust_task_state state,
                     rust_task *spawner, const char *name,
                     size_t init_stack_sz) :
    ref_count(1),
    id(0),
    notify_enabled(false),
    stk(NULL),
    runtime_sp(0),
    sched(sched_loop->sched),
    sched_loop(sched_loop),
    kernel(sched_loop->kernel),
    name(name),
    list_index(-1),
    rendezvous_ptr(0),
    local_region(&sched_loop->local_region),
    boxed(sched_loop->kernel->env, &local_region),
    unwinding(false),
    propagate_failure(true),
    cc_counter(0),
    total_stack_sz(0),
    task_local_data(NULL),
    task_local_data_cleanup(NULL),
    state(state),
    cond(NULL),
    cond_name("none"),
    event_reject(false),
    event(NULL),
    killed(false),
    reentered_rust_stack(false),
    disallow_kill(0),
    c_stack(NULL),
    next_c_sp(0),
    next_rust_sp(0),
    supervisor(spawner)
{
    LOGPTR(sched_loop, "new task", (uintptr_t)this);
    DLOG(sched_loop, task, "sizeof(task) = %d (0x%x)",
         sizeof *this, sizeof *this);

    new_stack(init_stack_sz);
    if (supervisor) {
        supervisor->ref();
    }
}
Пример #30
0
int main(int argc, char* argv[])
{
  Stack my_stack;

  my_stack.push(5);
  my_stack.push(10);
  my_stack.push(20);

 // my_stack.view_stack();

  Stack new_stack(my_stack);
  
  new_stack.view_stack();
  std::cout << "Here is the top of the stack " << new_stack.top() << std::endl;
  std::cout << new_stack.get_size() << std::endl;

  std::cout << "popping top of stack..." << std::endl << std::endl;

  new_stack.pop();
  new_stack.pop();
  new_stack.pop();

  new_stack.view_stack();

  std::cout << "Size of the stack is " << new_stack.get_size() << std::endl;

  /*Doubly_Linked_List my_list;

  my_list.insert_at_head(5);
  my_list.insert_at_head(10);
  my_list.insert_at_head(20);

  my_list.print_list_head();

  my_list.remove_at_head();

  std::cout << std::endl; 

  my_list.print_list_head();*/


  return 0;
}