void seed_search( Cell * cell , int x , int y , int groupid ) { int pos = dsat( x , y ); Unit * units = cell->units; if( units[pos].colour != 0xFF || units[pos].id != 0 ) { return; } units[pos].id = groupid; if( x > 0 ) { queue_job( ( Job ){ x - 1 , y , groupid } ); } if( y > 0 ) { queue_job( ( Job ){ x , y - 1 , groupid } ); } if( y < ( cell->h - 1 )) { queue_job( ( Job ){ x , y + 1 , groupid } ); } if( x < ( cell->w - 1 )) { queue_job( ( Job ){ x + 1 , y , groupid } ); } }
/* * Usage: fg * move job to foreground */ void builtin_fg() { job_t *j = job_recent(); if (j != NULL) { printf("%s\n", j->line); tcsetpgrp(0, j->pid); if (kill(-j->pid, SIGCONT) < 0) { perror("kill"); } fg = j; fg->bg = false; job_rm(&root, fg); queue_job(fg); } else { printf("yash: no such job\n"); } }
/* * print prompt, read cmd, parse cmd, evaluation cmd */ void prompt() { char *line = NULL; char *argv[MAXARGS]; int argc = 0; memset(argv, 0, sizeof(argv)); line = readline("$ "); if (line == NULL) { builtin_exit(); } size_t len = strlen(line); if (len <= 1) { free(line); return; } add_history(line); if (builtin(line)) { free(line); return; } job_t *job = (job_t *) malloc(sizeof(job_t)); memset(job, 0, sizeof(job_t)); job->line = strdup(line); argc = tokenize(line, argv); pipeline_t *p = spawn_pipeline(argc, argv); if (p != NULL) { job->pid = execute(p); job->bg = p->bg; if (job->pid > 0) { queue_job(job); } else { job_rm(&root, fg); job_free(&job); } } tcsetpgrp(0, s_pgid); pipeline_free(p); free(line); }
void unitize_cell( Cell * cell ) { jobQueue = ( Job * ) malloc( DS_SIZE * sizeof( Job ) ); printf("Queue size: %d bytes\n", DS_SIZE * sizeof( Job ) ); printf( "Starting grouping:\n" ); // Search for ungrouped sample while( scan_for_seed( cell ) != -1 ) { // Queue the the sample queue_job( ( Job ) { nextSeed % cell->w , nextSeed / cell->w , idPool++ } ); // While the queue isn't empty while( jobQueueIndex ) { // Pop a job from the queue Job currentJob = jobQueue[ --jobQueueIndex ]; // Perform search on the current job sample seed_search( cell , currentJob.x , currentJob.y , currentJob.id ); } } printf("Ended grouping with %d groups.\n", idPool - 1 ); }
void MainThreadJobQueue::queue_job(Job *job) { queue_job(Job_Ptr(job)); }