Beispiel #1
0
static void *on_empty(struct attach *att,void *d) {
	struct directed *dir = (struct directed *) d;
	dir->is_empty = 1;
	on_empty_attach(dir->attach,NULL,NULL);
	check_done(dir);
	return OOP_CONTINUE;
}
Beispiel #2
0
void
task_set::wait(bool block)
{
    DASSERT(submitter() == std::this_thread::get_id());
    const std::chrono::milliseconds wait_time(0);
    if (m_pool->is_worker(m_submitter_thread))
        block = true;  // don't get into recursive work stealing
    if (block == false) {
        int tries = 0;
        while (1) {
            bool all_finished = true;
            int nfutures = 0, finished = 0;
            for (auto&& f : m_futures) {
                // Asking future.wait_for for 0 time just checks the status.
                ++nfutures;
                auto status = f.wait_for(wait_time);
                if (status != std::future_status::ready)
                    all_finished = false;
                else
                    ++finished;
            }
            if (all_finished)  // All futures are ready? We're done.
                break;
            // We're still waiting on some tasks to complete. What next?
            if (++tries < 4) {  // First few times,
                pause(4);       //   just busy-wait, check status again
                continue;
            }
            // Since we're waiting, try to run a task ourselves to help
            // with the load. If none is available, just yield schedule.
            if (!m_pool->run_one_task(m_submitter_thread)) {
                // We tried to do a task ourselves, but there weren't any
                // left, so just wait for the rest to finish.
#if 1
                yield();
#else
                // FIXME -- as currently written, if we see an empty queue
                // but we're still waiting for the tasks in our set to end,
                // we will keep looping and potentially ourselves do work
                // that was part of another task set. If there a benefit to,
                // once we see an empty queue, only waiting for the existing
                // tasks to finish and not altruistically executing any more
                // tasks?  This is how we would take the exit now:
                for (auto&& f : m_futures)
                    f.wait();
                break;
#endif
            }
        }
    } else {
        // If block is true, just block on completion of all the tasks
        // and don't try to do any of the work with the calling thread.
        for (auto&& f : m_futures)
            f.wait();
    }
#ifndef NDEBUG
    check_done();
#endif
}
static gboolean
on_fd(gint fd, GIOCondition cond, gpointer data)
{
    did_fd = true;
    SOL_DBG("did fd=%d, cond=%#x", fd, cond);
    check_done();
    return false;
}
static gboolean
on_timeout(gpointer data)
{
    did_timeout = true;
    SOL_DBG("did timeout");
    check_done();
    return false;
}
static gboolean
on_idle(gpointer data)
{
    did_idle = true;
    SOL_DBG("did idle");
    check_done();
    return false;
}
Beispiel #6
0
static pfunc scan(struct jv_parser* p, char ch, jv* out) {
  p->column++;
  if (ch == '\n') {
    p->line++;
    p->column = 0;
  }
  presult answer = 0;
  if (p->st == JV_PARSER_NORMAL) {
    chclass cls = classify(ch);
    if (cls != LITERAL) {
      TRY(check_literal(p));
      if (check_done(p, out)) answer = OK;
    }
    switch (cls) {
    case LITERAL:
      tokenadd(p, ch);
      break;
    case WHITESPACE:
      break;
    case QUOTE:
      p->st = JV_PARSER_STRING;
      break;
    case STRUCTURE:
      TRY(token(p, ch));
      break;
    case INVALID:
      return "Invalid character";
    }
    if (check_done(p, out)) answer = OK;
  } else {
    if (ch == '"' && p->st == JV_PARSER_STRING) {
      TRY(found_string(p));
      p->st = JV_PARSER_NORMAL;
      if (check_done(p, out)) answer = OK;
    } else {
      tokenadd(p, ch);
      if (ch == '\\' && p->st == JV_PARSER_STRING) {
        p->st = JV_PARSER_STRING_ESCAPE;
      } else {
        p->st = JV_PARSER_STRING;
      }
    }
  }
  return answer;
}
Beispiel #7
0
void		res_graph(t_info *s, t_graph *g, t_nodes *list)
{
  t_nodes	*elem;

  g->a = 1;
  elem = s->elem_ext;
  while (my_strcmp(elem->name, s->elem_ent->name) == 0)
    {
      if (check_done(g, get_count(elem->name, list, s->nb_nodes)))
	{
	  g->done[g->count_done++] = get_count(elem->name, list, s->nb_nodes);
	  g->done[g->count_done] = -1;
	}
      if (shock_wave(s, g, list, elem))
	elem = s->elem_ent;
      else
	elem = res_graph_suit(g, list, elem);
    }
  s->elem_ent->free = g->a + 1;
  s->elem_ext->free = 0;
  find_path(s, g, list);
}
Beispiel #8
0
int		shock_wave(t_info *s, t_graph *g, t_nodes *list, t_nodes *elem)
{
  t_nodes	*elem_tmp;
  int		a;
  int		b;

  a = get_count(elem->name, list, s->nb_nodes);
  b = 0;
  while (b != s->nb_nodes)
    {
      elem_tmp = get_node(list, b);
      if (elem_tmp->status == 1 && g->links[a][b] > 0)
        return (1);
      else if (g->links[a][b] > 0 && check_done(g, b) && check_to_do(g, b))
        g->to_do[g->count_to_do++] = b;
      b += 1;
    }
  if (my_strcmp(elem->name, s->elem_ext->name))
    g->to_do[g->count_to_do++] = -2;
  g->to_do[g->count_to_do] = -1;
  return (0);
}
Beispiel #9
0
void
check_cover(ldns_rr_list *list, ldns_rdf *qname)
{
	ldns_status status;
	size_t i;
	if(check_done(qname))
		return;
	for(i=0; i<ldns_rr_list_rr_count(list); ++i)
	{
		ldns_rr* nsec3 = ldns_rr_list_rr(list, i);
		if(ldns_rr_get_type(nsec3) != LDNS_RR_TYPE_NSEC3) {
			/* skip non nsec3 */
			continue;
		}
		ldns_rdf* hashed = ldns_nsec3_hash_name_frm_nsec3(
			nsec3, qname);
		status = ldns_dname_cat(hashed, ldns_dname_left_chop(
			ldns_rr_owner(nsec3)));
		if(status != LDNS_STATUS_OK)
			abort_ldns_error("ldns_dname_cat", status);

		if(ldns_dname_compare(hashed, ldns_rr_owner(nsec3)) == 0) {
			ldns_rdf_print(stdout, ldns_rr_owner(nsec3));
			printf(" proves ");
			ldns_rdf_print(stdout, qname);
			printf(" exists.\n");
		}
		else if(ldns_nsec_covers_name(nsec3, hashed)) {
			ldns_rdf_print(stdout, ldns_rr_owner(nsec3));
			printf(" proves ");
			ldns_rdf_print(stdout, qname);
			printf(" does not exist.\n");
		}
		ldns_rdf_free(hashed);
	}
}
Beispiel #10
0
static void *on_timeout(oop_source *src,struct timeval tv,void *d) {
	struct directed *dir = (struct directed *) d;
	dir->is_old = 1;
	check_done(dir);
	return OOP_CONTINUE;
}
int main()
{
    //set up random number generator
    srand(time(NULL));
    
    //set up possible room names
    char names[10][10] = {"Amir", "Suri", "Dave", "Tess", "Dane", "Sara", "Evan", "Ruth", "Thor", "Anne"};
    
    
    /**************************************************
     This section creates the randomized map for each game.
     **************************************************/
    
    
    //select room names
    int chosen_nums[7] = {11,11,11,11,11,11,11};
    int sevNames;
    for (sevNames = 0; sevNames < 7; sevNames++)
    {
        while (1)
        {
            int name_select = rand() % 10;
            if (checkChosen(chosen_nums, name_select))
            {
                chosen_nums[sevNames] = name_select;
                break;
            }
        }
        
    }
    
    //create room matrix
    int rooms[7][8] = {
        {0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0},
    };
    //make rooms unconnectable to themselves
    int index;
    for (index = 0; index < 7; index++)
    {
        rooms[index][index] = 8;
    }
    
    //create random room connections
    //draw a number for a row that is not full
    do {
        int rowAdd = rand() % 7;
        //check that row isn't already full
        if (rooms[rowAdd][7] != 6)
        {
            //draw a column that isnt already chosen
            while (1)
            {
                //draw column number
                int colAdd = rand() % 7;
                //check that it is not the same as the row or already chosen
                if (colAdd != rowAdd && rooms[rowAdd][colAdd] != 9)
                {
                    //mark connections with 9 and incrament counters
                    rooms[rowAdd][colAdd] = 9;
                    rooms[colAdd][rowAdd] = 9;
                    rooms[rowAdd][7]++;
                    rooms[colAdd][7]++;
                    break;
                }
            }
        }
    } while(!check_done(rooms));
    
    //choose start and end
    int startRoom = rand() % 7;
    int endRoom = 8;
    do {
        endRoom = rand() % 7;
    } while (endRoom == startRoom && endRoom < 7);
    
    
    
    /**************************************************
     This section write the created map to the files they
     will be read from. It also creates the directory they
     are in and a temporary file for storing the path history.
     **************************************************/
    
    
    //get process id
    int pid = getpid();
    //create directory pointer
    char *dirName = malloc(20);
    //create dirname from parts
    snprintf(dirName, 20, "breinhoh.rooms.%d", pid);
    
    struct stat st = {0};
    
    //create directory
    if (stat(dirName, &st) == -1) {
        mkdir(dirName, 0755);
    }
    
    //open file in directory
    int fileCount;
    for (fileCount = 0; fileCount < 7; fileCount++)
    {
        //create file
        char filepath[30];
        strcpy(filepath, dirName);
        strcat(filepath, "/");
        strcat(filepath, names[chosen_nums[fileCount]]);
        FILE* f = fopen(filepath, "w");
        if (f < 0) {
            perror("CLIENT:\n");
            exit(1);
        }
        //write data to file
        //write name to file
        fprintf(f, "ROOM NAME: %s\n", names[chosen_nums[fileCount]]);
        //write connections to file
        int conCount2 = 1;
        int conCount;
        for (conCount = 0; conCount < 7; conCount++)
        {
            if (rooms[fileCount][conCount] == 9)
            {
                fprintf(f, "CONNECTION %d: %s\n", conCount2, names[chosen_nums[conCount]]);
                conCount2++;
            }
        }
        //write start, end, or mid
        if (fileCount == startRoom)
        {
            fprintf(f, "ROOM TYPE: START_ROOM");
        }
        else if (fileCount == endRoom)
        {
            fprintf(f, "ROOM TYPE: END_ROOM");
        }
        else
        {
            fprintf(f, "ROOM TYPE: MID_ROOM");
        }
        //close file
        fclose(f);
    }
    //create history file
    char hfilepath[30];
    strcpy(hfilepath, dirName);
    strcat(hfilepath, "/history");
    FILE* hf = fopen(hfilepath, "w+");
    if (hf < 0) {
        perror("CLIENT:\n");
        exit(1);
    }
    
    
    /**************************************************
     This section is the actual game.  It locates the start
     file and reads it.  Then it outputs the right info
     to the screen. Then it takes user input and if it
     checks out it records the right data finds the new
     file and starts over.  If the user data does not it
     reprints the current files data and ask again.
     **************************************************/
    
    
    //get start file name
    char currRoom[5];
    strcpy(currRoom, names[chosen_nums[startRoom]]);
    int stepCount = 0;
    int destNotReached = 1;
    //This loop is the game itself each room is read here
    while (destNotReached)
    {
        int roomNum = 0;
        //open file
        char roomfile[30];
        strcpy(roomfile, dirName);
        strcat(roomfile, "/");
        strcat(roomfile, currRoom);
        int file_descriptor;
        ssize_t nread;
        char buffer[512];
        
        file_descriptor = open(roomfile, O_RDONLY);
        if (file_descriptor == -1)
        {
            exit(1);
        }
        //save name and connections to array
        char data[8][10] = {"", "", "", "", "", "", "", ""};
        nread = read(file_descriptor, buffer, 512);
        char fileText[512];
        strcpy(fileText, buffer);
        memset(buffer, 0, 512);
        char * token = strtok(fileText, ":");
        token = strtok(NULL, " \n");
        strcpy(data[roomNum], token);
        roomNum++;
        token = strtok(NULL, " \n");
        while (token[0] == 'C')
        {
            token = strtok(NULL, " \n");
            token = strtok(NULL, " \n");
            strcpy(data[roomNum], token);
            roomNum++;
            token = strtok(NULL, "\r R");
        }
        token = strtok(NULL, ":");
        token = strtok(NULL, " \n");
        strcpy(data[7], token);
        close(file_descriptor);
        
        int verified = 1;
        //this loop is to verify the user input
        while (verified)
        {
            //check if file is end file
            if (!strcmp(data[7], "END_ROOM"))
            {
                destNotReached = 0;
                break;
            }
            //print info
            printf("CURRENT LOCATION: %s\nPOSSIBLE CONNECTIONS: ", data[0]);
            int conns;
            for (conns = 1; conns < 7; conns++)
            {
                if (strlen(data[conns]) == 0)
                {
                    printf(".\nWHERE TO? >");
                    break;
                }
                else
                {
                    printf("%s", data[conns]);
                    if (conns != 6)
                    {
                        if (strlen(data[conns + 1]) != 0)
                        {
                            printf(", ");
                        }
                    }
                    else
                    {
                        printf(".\nWHERE TO? >");
                    }
                }
            }
            //take user input
            char go2room[100];
            fgets(go2room, 100, stdin);
            go2room[strlen(go2room) - 1] = '\0';
            printf("\n");
            //check if user input is valid
            int roomCheck;
            for (roomCheck = 1; roomCheck < 7; roomCheck++)
            {
                if (!strcmp(go2room, data[roomCheck]))
                {
                    verified = 0;
                    strcpy(currRoom, go2room);
                    stepCount++;
                    //read new room to hostory file
                    fprintf(hf, go2room);
                    fprintf(hf, "\n");
                    
                }
            }
            //find new file or print an error response
            if (!verified)
            {
                break;
            }
            else
            {
                printf("HUH? I DON’T UNDERSTAND THAT ROOM. TRY AGAIN.\n\n");
            }
        }
    }
    //the game is over print the game data and delete the temp file.
    printf("YOU HAVE FOUND THE END ROOM. CONGRATULATIONS!\nYOU TOOK %d STEPS. YOUR PATH TO VICTORY WAS:\n", stepCount);
    rewind(hf);
    char let[512];
    while(fscanf(hf,"%[^\n]\n",let)!=EOF)
    {
        
        printf("%s\n", let);
    }
    // file close
    fclose(hf);
    
    remove(hfilepath);
    
    return 0;
}