示例#1
0
文件: streamingsort.c 项目: Yankkk/C
void * worker_merge(void * arg){
  task_t * task;
  int * scratch = malloc(nitems * sizeof(int));
  while( (task = dequeue()))  {
    do_tasks(scratch, task);
  }
  free(scratch);
  return NULL;

}
示例#2
0
void Sprinkler::TimeNotification(unsigned int time)
{
	if(needs_to_do_tasks())
		do_tasks();

	unsigned int next_notification = get_next_task_time();
	
	// Watch dog.
	next_notification = std::min(next_notification,TimeManager::GetSystemTime() + 3600);
	
	TimeManager::NotifyAt(this, next_notification);
}
示例#3
0
文件: streamingsort.c 项目: Yankkk/C
void child_finisheds(int* scratch, task_t* task) {
  if(task == NULL) return;

  pthread_mutex_lock(&mm);
  int done = ++ (task->completed_child_tasks);
  pthread_mutex_unlock(&mm);

  assert(done>0 && done<3);
  
  if(done == 2) {
    do_tasks(scratch, task);
  }  
}
示例#4
0
void test_task_manager() {
	task_manager = new TaskManager();
	task_manager->initialize(32);

	fprintf(stdout, "main thread: %lx\n", pthread_self());
	fflush(stdout);

	for (int i = 0; i < 100000; i++) {
		TaskId infinity = task_manager->add(inifinity_task());

		do_tasks(task_manager);

		task_manager->wait(infinity);

		fprintf(stdout, "finish: %d\n", i);
		fflush(stdout);
	}

	fprintf(stdout, "finished\n");
}
示例#5
0
文件: usemem.c 项目: aaronlu/usemem
int main(int argc, char *argv[])
{
	int c;

	ourname = argv[0];
	pagesize = getpagesize();

	while ((c = getopt_long(argc, argv,
				"aAf:FPp:gqowRMm:n:t:ds:T:Sr:u:j:h", opts, NULL)) != -1) {
		switch (c) {
		case 'a':
			opt_malloc++;
			break;
		case 'u':
			unit = memparse(optarg, NULL);
			break;
		case 'j':
			step = memparse(optarg, NULL);
			break;
		case 'A':
			msync_mode = MS_ASYNC;
			break;
		case 'f':
			filename = optarg;
			map_shared = MAP_SHARED;
			break;
		case 'p':
			pid_filename = optarg;
			break;
		case 'g':
			do_getchar = 1;
			break;
		case 'm': /* kept for compatibility */
			bytes = strtol(optarg, NULL, 10);
			bytes <<= 20;
			break;
		case 'n':
			nr_task = strtol(optarg, NULL, 10);
			break;
		case 't':
			nr_thread = strtol(optarg, NULL, 10);
			break;
		case 'P':
			prealloc++;
			break;
		case 'F':
			map_populate = MAP_POPULATE;
			break;
		case 'M':
			do_mlock = 1;
			break;
		case 'q':
			quiet = 1;
			break;
		case 's':
			sleep_secs = strtol(optarg, NULL, 10);
			break;
		case 'T':
			runtime_secs = strtol(optarg, NULL, 10);
			break;
		case 'd':
			opt_detach = 1;
			break;
		case 'r':
			reps = strtol(optarg, NULL, 10);
			break;
		case 'R':
			opt_randomise++;
			break;
		case 'S':
			msync_mode = MS_SYNC;
			break;
		case 'o':
			opt_readonly++;
			break;
		case 'w':
			opt_openrw++;
			break;
		case 'h':
			usage(0);
			break;
		default:
			usage(1);
		}
	}

	if (step < sizeof(long))
		step = sizeof(long);

	if (optind != argc - 1)
		usage(0);

	if (pid_filename && nr_task) {
		fprintf(stderr, "%s: pid file is only for single process\n",
			ourname);
		exit(1);
	}

	if (runtime_secs)
		gettimeofday(&start_time, NULL);

	bytes = memparse(argv[optind], NULL);

	if (!opt_malloc)
		fd = open(filename, ((opt_readonly && !opt_openrw) ?
			  O_RDONLY : O_RDWR) | O_CREAT, 0666);
	if (fd < 0) {
		fprintf(stderr, "%s: failed to open `%s': %s\n",
			ourname, filename, strerror(errno));
		exit(1);
	}

	if (prealloc)
		prealloc = allocate(bytes);

	if (nr_task)
		return do_tasks();

	return do_task();
}
int app_main(int argc, char **argv) {
  app_data_t app_data;
  ui_cmd_t cmd;
  BOOL exit = FALSE;
  UNUSED(argc);
  UNUSED(argv);

  app_data.tasks = NULL;
  app_data.initialized = FALSE;
  app_data.loaded = FALSE;

  do{
	  cmd = get_command();
	  if (!strcmp("exit", cmd.command))
	  {
		  exit = TRUE;
	  }
	  else if (!strcmp("load", cmd.command))
	  {
		  if (!do_load(&cmd, &app_data))
			  continue;
	  }
	  else if (!strcmp("run", cmd.command))
	  {
		  if (!do_run(&cmd, &app_data))
			  continue;
	  }
	  else if (!strcmp("SW", cmd.command))
	  {
		  if (!do_sw(&cmd, &app_data))
			  continue;
	  }
	  else if (!strcmp("MSW", cmd.command))
	  {
		  if (!do_msw(&cmd, &app_data))
			  continue;
	  }
	  else if (!strcmp("ASW", cmd.command))
	  {
		  if (!do_asw(&cmd, &app_data))
			  continue;
	  }
	  else if (!strcmp("switches", cmd.command))
	  {
		  if (!do_switches(&cmd, &app_data))
			  continue;
	  }
	  else if (!strcmp("JW", cmd.command))
	  {
		  if (!do_jw(&cmd, &app_data))
			  continue;
	  }
	  else if (!strcmp("MJW", cmd.command))
	  {
		  if (!do_mjw(&cmd, &app_data))
			  continue;
	  }
	  else if (!strcmp("AJW", cmd.command))
	  {
		  if (!do_ajw(&cmd, &app_data))
			  continue;
	  }
	  else if (!strcmp("tasks", cmd.command))
	  {
		  if (!do_tasks(&cmd, &app_data))
			  continue;
	  }
	  else
	  {
		  printf("Unknown command %s.\n", cmd.command);
	  }
  }while (!exit);

  if (!app_data.initialized)
  {
	  free_app_data(&app_data);
  }

  return 0;
}