Exemplo n.º 1
0
int main()
{
    mpmc_queue_init(&the_q);

    pthread_t reader[NUM_THREADS];
    pthread_t writer[NUM_THREADS];
    int i;
    for(i = 0; i < NUM_THREADS; ++i) {
        pthread_create(&reader[i], NULL, &pop_func, (void*)(intptr_t)i);
    }
    for(i = 1; i < NUM_THREADS; ++i) {
        pthread_create(&writer[i], NULL, &push_func, (void*)(intptr_t)i);
    }

    push_func(0);

    for(i = 1; i < NUM_THREADS; ++i) {
        pthread_join(reader[i], NULL);
    }
    for(i = 1; i < NUM_THREADS; ++i) {
        pthread_join(writer[i], NULL);
    }

    return 0;
}
Exemplo n.º 2
0
void generate_FUNCSTART(quad *q){
	SymbolTableEntry *f;
	instruction * t;
	if (funcStack == NULL) funcStack = newStack_func();

	if(q->result) f = q->result->sym;
	f->taddress = NEXTINSTRUCTIONLABEL;

	LIST_INSERT(f->returnList, LABELSTATEMENT(NEXTINSTRUCTIONLABEL), returnElem, ADD_2_BACK);

	q->taddress = NEXTINSTRUCTIONLABEL;

	LIST_INSERT(userFuncs, FUNCTIONSTATEMENT(f->taddress+1, f->totallocals, f->value.funcVal->name), userfunc, ADD_2_BACK);
	
	push_func(funcStack, f);
	totalUserFuncs++;

	t = (instruction *) malloc (sizeof(instruction));
	t->opcode = jump_v;
	RESET_OPERAND(&(t->arg1));
	RESET_OPERAND(&(t->arg2));
	t->result.type = label_a;
	emit_t(t);

	t = (instruction *) malloc (sizeof(instruction));
	t->srcLine= q->line;
	t->opcode = funcenter_v;
	if(q->result) make_operand(q->result, &(t->result));
	emit_t(t);
}
Exemplo n.º 3
0
void genfunc(Error_printer *err, Frag *frag, Node * args, Node * body)
{
	Pseudo *cod = codegen(err, body);
	Func *o;
	int argc = cntlst(args);
	char *quote;
	/* FIXME:�argc can be zero */
	char **argv = (char **) malloc(argc * sizeof(char *));
	Pseudo **initv = (Pseudo **)malloc(argc * sizeof(Pseudo *));
	quote = (char *)calloc(argc,1);
	genlst(err, argv, initv, quote, args);
	o = mkfunc(cod, argc, argv, initv, quote);
	push_func(frag);
	emitp(frag, o);
}
Exemplo n.º 4
0
void generate_FUNCSTART(quad *q)
{
	SymbolTableEntry *f = q->arg1->sym;

	f->iaddress = nextinstructionlabel();
	q->taddress = nextinstructionlabel();

	userfuncs_newfunc(f);
	push_func(funcstack, f);

	instruction t;
	init_instruction(&t);

	t.srcLine = q->line;

	t.opcode = funcenter_v;
	make_operand(q->arg1, t.arg1);
	emit_icode(t);
	
}