Exemple #1
0
status_t memory_pool_release(memory_pool_handle_t pool) {
    void* threadStatus = NULL;
    int err = 0;
    if (NULL == pool) {
        return NO_ERROR;
    }
    /* set kill thread flag */
    err = pthread_mutex_lock(&(pool->mutex));
    pool->kill_thread = 1;
    err = pthread_mutex_unlock(&(pool->mutex));

    /* join thread */
    if (NULL != pool->thread) {
        pthread_join(pool->thread, &threadStatus);
    }

    /* release allocated data */
    _release_stack_chunks(pool->generated);
    _release_stack_chunks(pool->available);
    _release_tree_chunks(pool->claimed);

    rb_tree_release(pool->claimed);
    stack_release(pool->generated);
    stack_release(pool->available);
    free(pool);

    return NO_ERROR;
}
int main(int argc, char const *argv[])
{
	stack *stk = stack_create();
	int str;
	printf("Please input some thing:\n");
	while((str = getchar())) {
		if(str == 40 || str == 123 || str == 91 || str == 60) // (、{、[、<
			stk = stack_push(stk, (void *)str);
		if(str == 41 || str == 125 || str == 93 || str == 62) { // )、}、]、>
			if(stk->size == 0) {
				printf("Error bracket\n");
				exit(0);
			} else {
				Node *node = stack_pop(stk);
				int tp = (int)node->value;
				if((str == 41 && tp == 40) || (str == 125 && tp == 123) || (str == 93 && tp == 91) || (str == 62 && tp == 60)) {
					printf("Great! Right bracket typed.\n");
				} else {
					printf("Error bracket\n");
					//printf("str=%d, tp=%d\n", str, tp);
					exit(0);
				}
				free(node);
			}
		}
	}
	stack_release(stk);
	printf("Exit. Thank you.\n");
	return 0;
}
Exemple #3
0
void gui_release()
{
	int i=0;
	for (i=0; i<gui->search_num;i++)
		free(gui->search_path[i]);
	free(gui->search_path);

	hash_release ( gui->signal_hash );
	hash_release ( gui->font_hash   );
	hash_release ( gui->image_hash  );
	stack_release( gui->win_stack   );
	free(gui);

	gui = NULL;
}
int main(int argc, char const *argv[])
{
	stack *stack = stack_create();
	if(!stack) {
		printf("Allocate memory error!\n");
		exit(0);
	}
	int num;
	printf("Please input some positive numbers.Stop input with number 0.\n");
	scanf("%d", &num);
	while(num > 0) {
		stack = stack_push(stack, (void *)num);
		scanf("%d", &num);
	}
	printf("Print the numbers below.\n\n");
	int value;
	while((value = (int)stack_pop(stack)) != NULL) {
		printf("%d\n", value);
	}
	stack_release(stack);
	printf("\nEnd printing.\n");
	return 0;
}
Exemple #5
0
int main(void)
{
    stack_t *stack;
    int getf,buffer[128],errcode;
    size_t counter,size;
    stack = stack_initialize(sizeof(int),DEFAULT_RELEASE_FUNCTION);
    if(!stack){
        fputs("Error!\n",stderr);
        return -1;
    }
    while(1){
        ignore_space(stdin);
        getf = fgetc(stdin);
        if(getf == 's'){
            fputs("set ",stdout);
            counter = 0;
            while(counter != 128){
                ignore_space(stdin);
                getf = fgetc(stdin);
                ungetc(getf,stdin);
                if(getf == '\n'
                    || (getf != '+' && getf != '-' && !isdigit(getf))){
                    break;
                }
                buffer[counter] = read_integer(stdin);
                fprintf(stdout,"%d ",buffer[counter]);
                counter++;
            }
            ignore_to_newline(stdin);
            errcode = stack_push_many_elements(stack,counter,buffer);
            if(errcode){
                fputs("Error!\n",stderr);
                return -1;
            }
            fputc('\n',stdout);
            fputs("stack trace : ",stdout);
            stack_trace(stack);
        }
        else if(getf == 'g'){
            fputs("get ",stdout);
            ignore_space(stdin);
            size = read_integer(stdin);
            ignore_to_newline(stdin);
            errcode = stack_pop_many_elements(stack,size,buffer);
            if(errcode){
                fputs("Error!\n",stderr);
                return -1;
            }
            counter = 0;
            while(counter != size){
                fprintf(stdout,"%d ",buffer[counter]);
                counter++;
            }
            fputc('\n',stdout);
            fputs("stack trace : ",stdout);
            stack_trace(stack);
        }
        else if(!isspace(getf)){
            break;
        }
    }
    stack_release(stack);
    return 0;
}