void Scheduler::operator()(){ //get the bit patterns and sort by node id (like the available algos) std::vector<state_type> bits = compute_dependencies(); // some book keeping vectors size_t size = algos_->size(); std::vector<EventState*> event_states(0); //TODO - has to move to init do { // BEGIN TODO: replace by thread safe code in start event // loop through all events that need to be started bool queue_full(false); do { unsigned int event_number(0); queue_full = new_events_queue_.try_pop(event_number); if (queue_full){ Context* context(0); bool whiteboard_available = wb_.get_context(context); if (whiteboard_available){ EventState* event_state = new EventState(size); event_states.push_back(event_state); event_state->context = context; context->write(event_number, "event","event"); } } } while(queue_full); for (unsigned int algo = 0; algo < size; ++algo) { // loop through all currently active events for (unsigned int event_id = 0; event_id < event_states.size() ; ++event_id) { EventState*& event_state = event_states[event_id]; // extract event_id specific quantities state_type& current_event_bits = event_state->state; // check whether all dependencies for the algorithm are fulfilled... state_type tmp = (current_event_bits & bits[algo]) ^ bits[algo]; /// ...whether all required products are there... // ... and whether the algo was previously started std::vector<AlgoState>& algo_states = event_state->algo_states; if ((tmp==0) && (algo_states[algo] == NOT_RUN)) { tryRunAlgo ( event_state, algo_states, algo ); } } } task_cleanup(); // check for finished events and clean up for (std::vector<EventState*>::iterator i = event_states.begin(), end = event_states.end(); i != end; ++i){ if ((*i)->state == termination_requirement_) { Context*& context = (*i)->context; wb_.release_context(context); loop_manager_->finished_event(); delete (*i); i = event_states.erase(i); } } std::this_thread::yield(); } while (not has_to_stop_); return; };
static file_entry &compute_dependencies(int srcrootlen, astring &srcfile) { // see if we already have an entry astring normalfile(srcfile); normalfile.replacechr(PATH_SEPARATOR[0], '/'); file_entry *foundfile = file_map.find(normalfile); if (foundfile != NULL) return *foundfile; // create a new header entry file_entry &file = *new file_entry; file.deplist = NULL; file.name = normalfile; file_map.add(file.name, &file); // read the source file UINT32 filelength; char *filedata; if (core_fload(srcfile, (void **)&filedata, &filelength) != FILERR_NONE) { fprintf(stderr, "Unable to read file '%s'\n", srcfile.cstr()); return file; } // find the #include directives in this file for (int index = 0; index < filelength; index++) if (filedata[index] == '#' && strncmp(&filedata[index + 1], "include", 7) == 0) { // first make sure we're not commented or quoted bool just_continue = false; for (int scan = index; scan > 2 && filedata[scan] != 13 && filedata[scan] != 10; scan--) if ((filedata[scan] == '/' && filedata[scan - 1] == '/') || filedata[scan] == '"') { just_continue = true; break; } if (just_continue) continue; // scan forward to find the quotes or bracket index += 7; int scan; for (scan = index; scan < filelength && filedata[scan] != '<' && filedata[scan] != '"' && filedata[scan] != 13 && filedata[scan] != 10; scan++) ; // ignore if not found or if it's bracketed if (scan >= filelength || filedata[scan] != '"') continue; int start = ++scan; // find the closing quote while (scan < filelength && filedata[scan] != '"') scan++; if (scan >= filelength) continue; // find the include file astring filename(&filedata[start], scan - start); astring target; // create a new dependency if (find_include_file(target, srcrootlen, srcfile, filename)) { dependency *dep = new dependency; dep->next = file.deplist; file.deplist = dep; dep->file = &compute_dependencies(srcrootlen, target); } } osd_free(filedata); return file; }
static int recurse_dir(int srcrootlen, astring &srcdir) { static const osd_dir_entry_type typelist[] = { ENTTYPE_DIR, ENTTYPE_FILE }; int result = 0; // iterate first over directories, then over files for (int entindex = 0; entindex < ARRAY_LENGTH(typelist) && result == 0; entindex++) { osd_dir_entry_type entry_type = typelist[entindex]; // open the directory and iterate through it osd_directory *dir = osd_opendir(srcdir); if (dir == NULL) { result = 1; goto error; } // build up the list of files const osd_directory_entry *entry; list_entry *list = NULL; int found = 0; while ((entry = osd_readdir(dir)) != NULL) if (entry->type == entry_type && entry->name[0] != '.') { list_entry *lentry = new list_entry; lentry->name.cpy(entry->name); lentry->next = list; list = lentry; found++; } // close the directory osd_closedir(dir); // skip if nothing found if (found == 0) continue; // allocate memory for sorting list_entry **listarray = new list_entry *[found]; found = 0; for (list_entry *curlist = list; curlist != NULL; curlist = curlist->next) listarray[found++] = curlist; // sort the list qsort(listarray, found, sizeof(listarray[0]), compare_list_entries); // rebuild the list list = NULL; while (--found >= 0) { listarray[found]->next = list; list = listarray[found]; } delete[] listarray; // iterate through each file for (list_entry *curlist = list; curlist != NULL && result == 0; curlist = curlist->next) { astring srcfile; // build the source filename srcfile.printf("%s%c%s", srcdir.cstr(), PATH_SEPARATOR[0], curlist->name.cstr()); // if we have a file, output it if (entry_type == ENTTYPE_FILE) { // make sure we care, first if (core_filename_ends_with(curlist->name, ".c")) { dependency_map depend_map; // find dependencies file_entry &file = compute_dependencies(srcrootlen, srcfile); recurse_dependencies(file, depend_map); // convert the target from source to object (makes assumptions about rules) astring target(file.name); target.replace(0, "src/", "$(OBJ)/"); target.replace(0, ".c", ".o"); printf("\n%s : \\\n", target.cstr()); // iterate over the hashed dependencies and output them as well for (dependency_map::entry_t *entry = depend_map.first(); entry != NULL; entry = depend_map.next(entry)) printf("\t%s \\\n", entry->tag().cstr()); } } // if we have a directory, recurse else result = recurse_dir(srcrootlen, srcfile); } // free all the allocated entries while (list != NULL) { list_entry *next = list->next; delete list; list = next; } } error: return result; }
static file_entry *compute_dependencies(int srcrootlen, const astring *srcfile) { astring *normalfile; UINT32 filelength; file_entry *file; char *filedata; int index; /* see if we already have an entry */ normalfile = astring_dup(srcfile); astring_replacechr(normalfile, PATH_SEPARATOR[0], '/'); file = (file_entry *)tagmap_find(file_map, astring_c(normalfile)); if (file != NULL) return file; /* create a new header entry */ file = (file_entry *)malloc(sizeof(*file)); file->deplist = NULL; file->name = normalfile; tagmap_add(file_map, astring_c(file->name), file, FALSE); /* read the source file */ if (core_fload(astring_c(srcfile), (void **)&filedata, &filelength) != FILERR_NONE) { fprintf(stderr, "Unable to read file '%s'\n", astring_c(srcfile)); return file; } /* find the #include directives in this file */ for (index = 0; index < filelength; index++) if (filedata[index] == '#' && strncmp(&filedata[index + 1], "include", 7) == 0) { astring *filename, *target; int scan = index; dependency *dep; int start; int just_continue = 0; /* first make sure we're not commented or quoted */ for (scan = index; scan > 2 && filedata[scan] != 13 && filedata[scan] != 10; scan--) if ((filedata[scan] == '/' && filedata[scan - 1] == '/') || filedata[scan] == '"') { just_continue = 1; break; } if (just_continue) continue; /* scan forward to find the quotes or bracket */ index += 7; for (scan = index; scan < filelength && filedata[scan] != '<' && filedata[scan] != '"' && filedata[scan] != 13 && filedata[scan] != 10; scan++) ; /* ignore if not found or if it's bracketed */ if (scan >= filelength || filedata[scan] != '"') continue; start = ++scan; /* find the closing quote */ while (scan < filelength && filedata[scan] != '"') scan++; if (scan >= filelength) continue; /* find the include file */ filename = astring_dupch(&filedata[start], scan - start); target = find_include_file(srcrootlen, srcfile, filename); /* create a new dependency */ if (target != NULL) { dep = (dependency *)malloc(sizeof(*dep)); dep->next = file->deplist; file->deplist = dep; dep->file = compute_dependencies(srcrootlen, target); astring_free(target); } astring_free(filename); } osd_free(filedata); return file; }
static int recurse_dir(int srcrootlen, const astring *srcdir) { static const osd_dir_entry_type typelist[] = { ENTTYPE_DIR, ENTTYPE_FILE }; int result = 0; int entindex; /* iterate first over directories, then over files */ for (entindex = 0; entindex < ARRAY_LENGTH(typelist) && result == 0; entindex++) { osd_dir_entry_type entry_type = typelist[entindex]; const osd_directory_entry *entry; list_entry **listarray = NULL; list_entry *list = NULL; list_entry *curlist; osd_directory *dir; int found = 0; /* open the directory and iterate through it */ dir = osd_opendir(astring_c(srcdir)); if (dir == NULL) { result = 1; goto error; } /* build up the list of files */ while ((entry = osd_readdir(dir)) != NULL) if (entry->type == entry_type && entry->name[0] != '.') { list_entry *lentry = (list_entry *)malloc(sizeof(*lentry)); lentry->name = astring_dupc(entry->name); lentry->next = list; list = lentry; found++; } /* close the directory */ osd_closedir(dir); /* skip if nothing found */ if (found == 0) continue; /* allocate memory for sorting */ listarray = (list_entry **)malloc(sizeof(list_entry *) * found); found = 0; for (curlist = list; curlist != NULL; curlist = curlist->next) listarray[found++] = curlist; /* sort the list */ qsort(listarray, found, sizeof(listarray[0]), compare_list_entries); /* rebuild the list */ list = NULL; while (--found >= 0) { listarray[found]->next = list; list = listarray[found]; } free(listarray); /* iterate through each file */ for (curlist = list; curlist != NULL && result == 0; curlist = curlist->next) { astring *srcfile; /* build the source filename */ srcfile = astring_alloc(); astring_printf(srcfile, "%s%c%s", astring_c(srcdir), PATH_SEPARATOR[0], astring_c(curlist->name)); /* if we have a file, output it */ if (entry_type == ENTTYPE_FILE) { /* make sure we care, first */ if (core_filename_ends_with(astring_c(curlist->name), ".c")) { tagmap *depend_map = tagmap_alloc(); tagmap_entry *map_entry; file_entry *file; astring *target; int taghash; /* find dependencies */ file = compute_dependencies(srcrootlen, srcfile); recurse_dependencies(file, depend_map); /* convert the target from source to object (makes assumptions about rules) */ target = astring_dup(file->name); astring_replacec(target, 0, "src/", "$(OBJ)/"); astring_replacec(target, 0, ".c", ".o"); printf("\n%s : \\\n", astring_c(target)); /* iterate over the hashed dependencies and output them as well */ for (taghash = 0; taghash < TAGMAP_HASH_SIZE; taghash++) for (map_entry = depend_map->table[taghash]; map_entry != NULL; map_entry = map_entry->next) printf("\t%s \\\n", astring_c((astring *)map_entry->object)); astring_free(target); tagmap_free(depend_map); } } /* if we have a directory, recurse */ else result = recurse_dir(srcrootlen, srcfile); /* free memory for the names */ astring_free(srcfile); } /* free all the allocated entries */ while (list != NULL) { list_entry *next = list->next; astring_free((astring *)list->name); free(list); list = next; } } error: return result; }
static int recurse_dir(astring &srcdir) { int result = 0; // iterate through each file for (librarylist_entry *lib = librarylist; lib != NULL; lib = lib->next) { for (list_entry *src = lib->sourcefiles; src != NULL; src = src->next) { astring srcfile; // build the source filename srcfile.printf("%s%s.c", srcdir.cstr(), src->name.cstr()); dependency_map depend_map; // find dependencies file_entry &file = compute_dependencies(srcfile); recurse_dependencies(file, depend_map); for (dependency_map::entry_t *entry = depend_map.first(); entry != NULL; entry = depend_map.next(entry)) { astring t(entry->tag()); if (core_filename_ends_with(t, ".h")) { char *foundfile = include_map.find(t); if (foundfile != NULL) { printf("%s\n", foundfile); // we add things just once when needed include_map.remove(t); } } } } } // iterate through each file for (librarylist_entry *lib = librarylist; lib != NULL; lib = lib->next) { // convert the target from source to object (makes assumptions about rules) astring target("$(OBJ)/target/",lib->name.cstr()); target.cat(".a"); printf("\n%s : \\\n", target.cstr()); for (list_entry *src = lib->sourcefiles; src != NULL; src = src->next) { astring srcfile; // build the source filename srcfile.printf("%s%s.c", srcdir.cstr(), src->name.cstr()); dependency_map depend_map; // find dependencies file_entry &file = compute_dependencies(srcfile); recurse_dependencies(file, depend_map); // iterate over the hashed dependencies and output them as well for (dependency_map::entry_t *entry = depend_map.first(); entry != NULL; entry = depend_map.next(entry)) { astring t(entry->tag()); t.replace(0, "src/", "$(OBJ)/"); t.replace(0, ".c", ".o"); if (core_filename_ends_with(t, ".o")) { printf("\t%s \\\n", t.cstr()); } } } printf("\n"); for (list_entry *src = lib->sourcefiles; src != NULL; src = src->next) { astring srcfile; // build the source filename srcfile.printf("%s%s.c", srcdir.cstr(), src->name.cstr()); dependency_map depend_map; // find dependencies file_entry &file = compute_dependencies(srcfile); recurse_dependencies(file, depend_map); for (dependency_map::entry_t *entry = depend_map.first(); entry != NULL; entry = depend_map.next(entry)) { astring t(entry->tag()); if (core_filename_ends_with(t, ".lay")) { astring target2(file.name); target2.replace(0, "src/", "$(OBJ)/"); target2.replace(0, ".c", ".o"); t.replace(0, "src/", "$(OBJ)/"); t.replace(0, ".lay", ".lh"); printf("%s: %s\n", target2.cstr(), t.cstr()); } if (core_filename_ends_with(t, ".inc")) { astring target2(file.name); target2.replace(0, "src/", "$(OBJ)/"); target2.replace(0, ".c", ".o"); printf("%s: %s\n", target2.cstr(), t.cstr()); } } } } return result; }