view example/post_function/main.cc @ 203:1eba8570808c draft

fix CreateSpan::run
author gongo@localhost.localdomain
date Mon, 26 Jan 2009 18:30:35 +0900
parents 028ffc9c0375
children c29b7163d6d9
line wrap: on
line source

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "TaskManager.h"
#include "Func.h"

extern void task_init(void);

static int count = 1;

char *help_str = "Usage: ./post [-cpu spe_num] [-count N]\n\
  -count  Number of print \"Hello, World!!\"";

void
func1(void *p)
{
    int i = (int)p;

    printf("post function : %d\n", i--);

    if (i > 0) {
	HTaskPtr next = manager->create_task(HELLO_TASK);
	next->add_param(i);
	next->set_post(func1, (void*)i);
	next->set_cpu(SPE_ANY);
	next->spawn();    
    }
}


int
init(int argc, char **argv)
{
    for (int i = 1; argv[i]; ++i) {
	if (strcmp(argv[i], "-count") == 0) {
            count = atoi(argv[++i]);
        }
        if (strcmp(argv[i], "--help") == 0) {
            printf("%s\n", help_str);
            return -1;
        }
    }

    return 0;
}

void
run_init(void)
{
    HTaskPtr task;

    task = manager->create_task(HELLO_TASK);
    task->add_param(count);
    task->set_post(func1, (void*)count);
    task->set_cpu(SPE_ANY);
    task->spawn();
}

int
cerium_main(int argc, char *argv[])
{
    if (init(argc, argv) < 0) {
	return -1;
    }

    task_init();
    run_init();

    return 0;
}