Mercurial > hg > Game > Cerium
view example/string_args/main.cc @ 1782:7245548995a8 draft
refactoring in string_args
author | Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 26 Nov 2013 18:57:06 +0900 |
parents | a96cf4e50524 |
children | 6790d1d83bb7 |
line wrap: on
line source
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/stat.h> #include <sys/time.h> #include "TaskManager.h" #include "Func.h" extern void task_init(void); static int spe_num = 1; static int task_num = 1; static CPU_TYPE spe_cpu = SPE_ANY; static int one_task_size = 4096 * 4; extern TaskManager *manager; const char *usr_help_str = "Usage: ./string_args [-cpu cpu_num] [-sw search_word] [-t task_num]\n"; static char* init(int argc, char **argv) { char *search_word = 0; for (int i = 1; argv[i]; ++i) { if (strcmp(argv[i], "-cpu") == 0) { spe_num = atoi(argv[i+1]); i++; } else if (strcmp(argv[i], "-sw") == 0) { search_word = argv[i+1]; i++; } else if (strcmp(argv[i], "-t") == 0) { task_num = atoi(argv[i+1]); i++; } } if (search_word==0){ puts(usr_help_str); exit(1); } return search_word; } static void run_start(TaskManager *manager,char *search_word,int search_word_len) { HTask *exec; exec = manager->create_task(TASK_EXEC); exec->set_cpu(spe_cpu); //ファイルディスクリプタをそのままタスクに渡してあげる exec->set_inData(0,search_word,search_word_len); exec->set_param(0,(unsigned long long)one_task_size); //1つのタスクが読み込む量 exec->iterate(task_num); //タスク数分イテレートする } int TMmain(TaskManager *manager, int argc, char *argv[]) { const char *search_word = init(argc,argv); int search_word_len = strlen(search_word); char *sword = (char*)manager->allocate(search_word_len+1); memcpy(sword,search_word,search_word_len); // to get correct alignment task_init(); run_start(manager, sword, search_word_len); return 0; }