static int fbcon_init(void) { make_task(0, true); make_task(1, true); return diag_setup(&DIAG_IMPL_NAME(__EMBUILD_MOD__)); /*return 0;*/ }
int main(int argc, char** argv) { GQueue* q = g_queue_new(); g_queue_push_tail(q, make_task("Reboot server", 2)); g_queue_push_tail(q, make_task("Pull cable", 2)); g_queue_push_tail(q, make_task("Nethack", 1)); g_queue_push_tail(q, make_task("New monitor", 3)); printf("Original queue: "); g_queue_foreach(q, (GFunc)prt, NULL); g_queue_sort(q, (GCompareDataFunc)sorter, NULL); printf("\nSorted queue: "); g_queue_foreach(q, (GFunc)prt, NULL); g_queue_free(q); return 0; }
int main(int argc, char *argv[]) { signal(SIGINT, intercept); srand(time(0)); int fd = shm_open("/mem", O_RDWR, 0660); shared = (mem*) mmap(NULL, sizeof(mem), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); mutex = sem_open("/mutex", O_RDWR); empty = sem_open("/empty", O_RDWR); int i; for(;;) { sem_wait(mutex); for(i = 0; i < MAX_READERS; i++) { sem_wait(empty); } make_task(shared->numbers); for(i = 0; i < MAX_READERS; i++) { sem_post(empty); } sem_post(mutex); } return 0; }
virtual std::unique_ptr<TaskBase> generateTask () override { return make_task(EventVarTable<Args...>::t); }
void load_compiled_files__may_heapclean ( // ================================== // const char* compiled_files_to_load_filename, Heapcleaner_Args* heap_parameters, // See struct cleaner_args in src/c/h/heap.h Roots* extra_roots ){ // Load into the runtime heap all the .compiled files // listed one per line in given compiled_files_to_load file: // // This function is called from exactly one spot, in // // src/c/main/runtime-main.c int max_boot_path_len; char* filename_buf; int seen_runtime_package_picklehash = FALSE; // FALSE until we see the picklehash naming our runtime. open_logfile(); Task* task = make_task( // make_task def in src/c/main/runtime-state.c TRUE, // is_boot heap_parameters ); // Set up handlers for ^C, divide-by-zero, // integer overflow etc: // set_up_fault_handlers (); // set_up_fault_handlers def in src/c/machine-dependent/posix-arithmetic-trap-handlers.c // set_up_fault_handlers def in src/c/machine-dependent/win32-fault.c // set_up_fault_handlers def in src/c/machine-dependent/cygwin-fault.c // Set up RunVec in CStruct in // // runtime_package__global. // // This constitutes an ersatz exports list implementing // // src/lib/core/init/runtime.api // // which we will later substitute for the (useless) code from // // src/lib/core/init/runtime.pkg // // thus providing access to critical assembly fns including // // find_cfun // // implemented in one of // // src/c/machine-dependent/prim.sparc32.asm // src/c/machine-dependent/prim.pwrpc32.asm // src/c/machine-dependent/prim.intel32.asm // src/c/machine-dependent/prim.intel32.masm // construct_runtime_package__global( task ); // construct_runtime_package__global def in src/c/main/construct-runtime-package.c // Construct the list of files to be loaded: // Val compiled_file_list = read_in_compiled_file_list__may_heapclean ( task, compiled_files_to_load_filename, &max_boot_path_len, extra_roots ); Roots roots1 = { &compiled_file_list, extra_roots }; // This space is ultimately wasted: XXX BUGGO FIXME // if (! (filename_buf = MALLOC( max_boot_path_len ))) { // die ("unable to allocate space for boot file names"); } // Load all requested compiled_files into the heap: // while (compiled_file_list != LIST_NIL) { // char* filename = filename_buf; // Need to make a copy of the filename because // load_compiled_file__may_heapclean is going to scribble into it: // strcpy( filename_buf, HEAP_STRING_AS_C_STRING( LIST_HEAD( compiled_file_list ))); compiled_file_list = LIST_TAIL( compiled_file_list ); // Remove above filename from list of files to process. // If 'filename' does not begin with "RUNTIME_PACKAGE_PICKLEHASH=" ... // if (strstr(filename,"RUNTIME_PACKAGE_PICKLEHASH=") != filename) { // // ... then we can load it normally: // load_compiled_file__may_heapclean( task, filename, &roots1 ); } else { // We're processing the // // RUNTIME_PACKAGE_PICKLEHASH=... // // set up for us by // // src/app/makelib/mythryl-compiler-compiler/find-set-of-compiledfiles-for-executable.pkg while (*filename++ != '='); // Step over "RUNTIME_PACKAGE_PICKLEHASH=" prefix. if (seen_runtime_package_picklehash) { // if (log_fd) fclose( log_fd ); die ("Runtime system picklehash registered more than once!\n"); exit(1); // Just for gcc's sake -- cannot exectute. } // Most parts of the Mythryl implementation treat the C-coded // runtime functions as being just like library functions // coded in Mythryl -- to avoid special cases, we go to great // lengths to hide the differences. // // But this is one of the places where the charade breaks // down -- there isn't actually any (useful) .compiled file // corresponding to the runtime picklehash: Instead, we // must link runtime calls directly down into our C code. // // For more info, see the comments in // src/lib/core/init/runtime.pkg // // So here we implement some of that special handling: // Register the runtime system under the given picklehash: // Picklehash picklehash; int l = strlen( filename ); for (int i = 0; i < PICKLEHASH_BYTES; i++) { // int i2 = 2 * i; if (i2 + 1 < l) { int c1 = filename[i2+0]; int c2 = filename[i2+1]; picklehash.bytes[i] = (hex(c1) << 4) + hex(c2); } } fprintf( log_fd ? log_fd : stderr, "\n load-compiledfiles.c: Runtime system picklehash is %s\n\n", filename ); register_compiled_file_exports__may_heapclean( task, &picklehash, runtime_package__global, &roots1 ); seen_runtime_package_picklehash = TRUE; // Make sure that we register the runtime system picklehash only once. } } if (log_fd) fclose( log_fd ); } // load_compiled_files__may_heapclean
void Storage_FillTaskList(TaskList & tl) { make_task(ItemPrototypeStorage, ItemPrototype, ArrayStorageContainer, "items", gItemPrototypeFormat); make_task(CreatureNameStorage, CreatureInfo, HashMapStorageContainer, "creature_names", gCreatureNameFormat); make_task(GameObjectNameStorage, GameObjectInfo, HashMapStorageContainer, "gameobject_names", gGameObjectNameFormat); make_task(CreatureProtoStorage, CreatureProto, HashMapStorageContainer, "creature_proto", gCreatureProtoFormat); make_task(DisplayBoundingStorage, DisplayBounding, HashMapStorageContainer, "display_bounding_boxes", gDisplayBoundingFormat); make_task(VendorRestrictionEntryStorage, VendorRestrictionEntry, ArrayStorageContainer, "vendor_restrictions", gVendorRestrictionEntryFormat); make_task(AreaTriggerStorage, AreaTrigger, HashMapStorageContainer, "areatriggers", gAreaTriggerFormat); make_task(ItemPageStorage, ItemPage, HashMapStorageContainer, "itempages", gItemPageFormat); make_task(GraveyardStorage, GraveyardTeleport, HashMapStorageContainer, "graveyards", gGraveyardFormat); make_task(TeleportCoordStorage, TeleportCoords, HashMapStorageContainer, "teleport_coords", gTeleportCoordFormat); make_task(FishingZoneStorage, FishingZoneEntry, HashMapStorageContainer, "fishing", gFishingFormat); make_task(NpcTextStorage, GossipText, HashMapStorageContainer, "npc_text", gNpcTextFormat); make_task(WorldMapInfoStorage, MapInfo, ArrayStorageContainer, "worldmap_info", gWorldMapInfoFormat); make_task(ZoneGuardStorage, ZoneGuardEntry, HashMapStorageContainer, "zoneguards", gZoneGuardsFormat); make_task(CreatureTextStorage, CreatureText, HashMapStorageContainer, "npc_script_text", gCreatureTextFormat); make_task(GossipMenuOptionStorage, GossipMenuOption, HashMapStorageContainer, "gossip_menu_option", gGossipMenuOptionFormat); make_task(WorldStringTableStorage, WorldStringTable, HashMapStorageContainer, "worldstring_tables", gWorldStringTableFormat); make_task(WorldBroadCastStorage, WorldBroadCast, HashMapStorageContainer, "worldbroadcast", gWorldBroadCastFormat); make_task(BGMasterStorage, BGMaster, HashMapStorageContainer, "battlemasters", gBattleMasterFormat); make_task(SpellClickSpellStorage, SpellClickSpell, HashMapStorageContainer, "spellclickspells", gSpellClickSpellsFormat); make_task(TotemDisplayIdStorage, TotemDisplayIdEntry, HashMapStorageContainer, "totemdisplayids", gTotemDisplayIDsFormat); make_task(PointOfInterestStorage, PointOfInterest, HashMapStorageContainer, "points_of_interest", gPointOfInterestFormat); }
Task* import_heap_image__may_heapclean (const char* fname, Heapcleaner_Args* params, Roots* extra_roots) { // ================================ // // This fn is called (only) by load_and_run_heap_image__may_heapclean in src/c/main/load-and-run-heap-image.c // Task* task; Heapfile_Header image_header; Heap_Header heap_header; Val *externs; Pthread_Image image; Inbuf inbuf; if (fname != NULL) { // // Resolve the name of the image. // If the file exists use it, otherwise try the // pathname with the machine ID as an extension. if ((inbuf.file = fopen(fname, "rb"))) { // if (verbosity__global > 0) say("loading %s ", fname); } else { // if ((inbuf.file = fopen(fname, "rb"))) { // if (verbosity__global > 0) say("loading %s ", fname); } else { die ("unable to open heap image \"%s\"\n", fname); } } inbuf.needs_to_be_byteswapped = FALSE; inbuf.buf = NULL; inbuf.nbytes = 0; } else { // // fname == NULL, so try to find // an in-core heap image: #if defined(DLOPEN) && !defined(OPSYS_WIN32) // void *lib = dlopen (NULL, RTLD_LAZY); void *vimg, *vimglenptr; if ((vimg = dlsym(lib,HEAP_IMAGE_SYMBOL )) == NULL) die("no in-core heap image found\n"); if ((vimglenptr = dlsym(lib,HEAP_IMAGE_LEN_SYMBOL)) == NULL) die("unable to find length of in-core heap image\n"); inbuf.file = NULL; inbuf.needs_to_be_byteswapped = FALSE; inbuf.base = vimg; inbuf.buf = inbuf.base; inbuf.nbytes = *(long*)vimglenptr; #else die("in-core heap images not implemented\n"); #endif } READ(&inbuf, image_header); if (image_header.byte_order != ORDER) die ("incorrect byte order in heap image\n"); if (image_header.magic != IMAGE_MAGIC) die ("bad magic number (%#x) in heap image\n", image_header.magic); if ((image_header.kind != EXPORT_HEAP_IMAGE) && (image_header.kind != EXPORT_FN_IMAGE)) die ("bad image kind (%d) in heap image\n", image_header.kind); READ(&inbuf, heap_header); // Check for command-line overrides of heap parameters: // if (params->agegroup0_buffer_bytesize == 0) { params->agegroup0_buffer_bytesize = heap_header.agegroup0_buffer_bytesize; } if (params->active_agegroups < heap_header.active_agegroups) { params->active_agegroups = heap_header.active_agegroups; } if (params->oldest_agegroup_retaining_fromspace_sibs_between_heapcleanings < 0) { params->oldest_agegroup_retaining_fromspace_sibs_between_heapcleanings = heap_header.oldest_agegroup_retaining_fromspace_sibs_between_heapcleanings; } task = make_task( /*is_boot:*/FALSE, params ); // make_task def in src/c/main/runtime-state.c // Get the run-time pointers into the heap: // *PTR_CAST( Val*, PERVASIVE_PACKAGE_PICKLE_LIST_REFCELL__GLOBAL ) = heap_header.pervasive_package_pickle_list; // This carefully constructed fake looks like a normal // compiled package from the Mythryl side but actually // links to compile C code -- see the hack in // // src/c/main/load-compiledfiles.c // runtime_package__global = heap_header.runtime_pseudopackage; #ifdef ASM_MATH mathvec__global = heap_header.math_package; #endif externs = heapio__read_externs_table (&inbuf); // Read the externals table. READ(&inbuf, image); // Read and initialize the Mythryl state info. // if (image_header.kind == EXPORT_HEAP_IMAGE) { // Load the live registers: // ASSIGN( POSIX_INTERPROCESS_SIGNAL_HANDLER_REFCELL__GLOBAL, image.posix_interprocess_signal_handler ); // task->argument = image.stdArg; task->fate = image.stdCont; task->current_closure = image.stdClos; task->program_counter = image.pc; task->exception_fate = image.exception_fate; task->current_thread = image.current_thread; // task->callee_saved_registers[0] = image.calleeSave[0]; task->callee_saved_registers[1] = image.calleeSave[1]; task->callee_saved_registers[2] = image.calleeSave[2]; read_heap (&inbuf, &heap_header, task, externs); // Read the Mythryl heap. /* heapcleaner_messages_are_enabled__global = TRUE; */ // Heapcleaning messages are on by default for interactive images. } else { // EXPORT_FN_IMAGE // Restore the signal handler: // ASSIGN( POSIX_INTERPROCESS_SIGNAL_HANDLER_REFCELL__GLOBAL, image.posix_interprocess_signal_handler ); // Read the Mythryl heap: // task->argument = image.stdArg; read_heap (&inbuf, &heap_header, task, externs); // Initialize the calling context (taken from run_mythryl_function__may_heapclean): // run_mythryl_function__may_heapclean def in src/c/main/run-mythryl-code-and-runtime-eventloop.c // Val function_to_run = task->argument; // task->exception_fate = PTR_CAST( Val, handle_uncaught_exception_closure_v + 1 ); task->current_thread = HEAP_VOID; // task->fate = PTR_CAST( Val, return_to_c_level_c ); task->current_closure = function_to_run; // task->program_counter = task->link_register = GET_CODE_ADDRESS_FROM_CLOSURE( function_to_run ); // Last use of 'function_to_run'. // Set up the arguments to the imported function: // Val program_name = make_ascii_string_from_c_string__may_heapclean(task, mythryl_program_name__global, extra_roots); Roots roots1 = { &program_name, extra_roots }; // Val args = make_ascii_strings_from_vector_of_c_strings__may_heapclean (task, commandline_args_without_argv0_or_runtime_args__global, &roots1 ); task->argument = make_two_slot_record( task, program_name, args ); // debug_say("arg = %#x : [%#x, %#x]\n", task->argument, GET_TUPLE_SLOT_AS_VAL(task->argument, 0), GET_TUPLE_SLOT_AS_VAL(task->argument, 1)); // Heapcleaner messages are off by // default for spawn_to_disk images: // heapcleaner_messages_are_enabled__global = FALSE; } FREE( externs ); if (inbuf.file) fclose (inbuf.file); if (verbosity__global > 0) say(" done\n"); return task; } // fun import_heap_image__may_heapclean
void Storage_FillTaskList(TaskList & tl) { make_task(ItemPrototypeStorage, ItemPrototype, ArrayStorageContainer, "items", gItemPrototypeFormat); make_task(CreatureNameStorage, CreatureInfo, HashMapStorageContainer, "creature_names", gCreatureNameFormat); make_task(GameObjectNameStorage, GameObjectInfo, HashMapStorageContainer, "gameobject_names", gGameObjectNameFormat); make_task(CreatureProtoStorage, CreatureProto, HashMapStorageContainer, "creature_proto", gCreatureProtoFormat); make_task(AreaTriggerStorage, AreaTrigger, HashMapStorageContainer, "areatriggers", gAreaTriggerFormat); make_task(ItemPageStorage, ItemPage, HashMapStorageContainer, "itempages", gItemPageFormat); make_task(QuestStorage, Quest, HashMapStorageContainer, "quests", gQuestFormat); make_task(GraveyardStorage, GraveyardTeleport, HashMapStorageContainer, "graveyards", gGraveyardFormat); make_task(TeleportCoordStorage, TeleportCoords, HashMapStorageContainer, "teleport_coords", gTeleportCoordFormat); make_task(FishingZoneStorage, FishingZoneEntry, HashMapStorageContainer, "fishing", gFishingFormat); make_task(NpcTextStorage, GossipText, HashMapStorageContainer, "npc_text", gNpcTextFormat); make_task(WorldMapInfoStorage, MapInfo, ArrayStorageContainer, "worldmap_info", gWorldMapInfoFormat); make_task(ZoneGuardStorage, ZoneGuardEntry, HashMapStorageContainer, "zoneguards", gZoneGuardsFormat); }
You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ // ArduSub scheduling, originally copied from ArduCopter #include "Sub.h" /* scheduler table for fast CPUs - all regular tasks apart from the fast_loop() should be listed here, along with how often they should be called (in hz) and the maximum time they are expected to take (in microseconds) */ AP_Task Sub::scheduler_tasks[] = { make_task("fifty_hz_loop", &sub, &Sub::fifty_hz_loop, 50, 75), make_task("update_GPS", &sub, &Sub::update_GPS, 50, 200), #if OPTFLOW == ENABLED make_task("update_optical_flow", &sub, &Sub::update_optical_flow, 200, 160), #endif make_task("update_batt_compass", &sub, &Sub::update_batt_compass, 10, 120), make_task("read_rangefinder", &sub, &Sub::read_rangefinder, 20, 100), make_task("update_altitude", &sub, &Sub::update_altitude, 10, 100), make_task("three_hz_loop", &sub, &Sub::three_hz_loop, 3, 75), make_task("update_turn_counter", &sub, &Sub::update_turn_counter, 10, 50), make_task("compass_accumulate", &sub, &Sub::compass_accumulate, 100, 100), make_task("AP_Baro::accumulate", &sub.barometer, &AP_Baro::accumulate, 50, 90), make_task("AP_Notify::update", &sub.notify, &AP_Notify::update, 50, 90), make_task("one_hz_loop", &sub, &Sub::one_hz_loop, 1, 100), make_task("gcs_check_input", &sub, &Sub::gcs_check_input, 400, 180), make_task("gcs_send_heartbeat", &sub, &Sub::gcs_send_heartbeat, 1, 110),
void Storage_FillTaskList(TaskList & tl) { make_task(ItemPrototypeStorage, ItemPrototype, ArrayStorageContainer, "items", gItemPrototypeFormat); make_task(ItemNameStorage, ItemName, ArrayStorageContainer, "itemnames", gItemNameFormat); make_task(CreatureNameStorage, CreatureInfo, HashMapStorageContainer, "creature_names", gCreatureNameFormat); make_task(GameObjectNameStorage, GameObjectInfo, HashMapStorageContainer, "gameobject_names", gGameObjectNameFormat); make_task(CreatureProtoStorage, CreatureProto, HashMapStorageContainer, "creature_proto", gCreatureProtoFormat); make_task(DisplayBoundingStorage, DisplayBounding, HashMapStorageContainer, "display_bounding_boxes", gDisplayBoundingFormat); make_task(VendorRestrictionEntryStorage, VendorRestrictionEntry, ArrayStorageContainer, "vendor_restrictions", gVendorRestrictionEntryFormat); make_task(AreaTriggerStorage, AreaTrigger, HashMapStorageContainer, "areatriggers", gAreaTriggerFormat); make_task(ItemPageStorage, ItemPage, HashMapStorageContainer, "itempages", gItemPageFormat); make_task(QuestStorage, Quest, HashMapStorageContainer, "quests", gQuestFormat); make_task(GraveyardStorage, GraveyardTeleport, HashMapStorageContainer, "graveyards", gGraveyardFormat); make_task(TeleportCoordStorage, TeleportCoords, HashMapStorageContainer, "teleport_coords", gTeleportCoordFormat); make_task(FishingZoneStorage, FishingZoneEntry, HashMapStorageContainer, "fishing", gFishingFormat); make_task(NpcTextStorage, GossipText, HashMapStorageContainer, "npc_text", gNpcTextFormat); make_task(WorldMapInfoStorage, MapInfo, ArrayStorageContainer, "worldmap_info", gWorldMapInfoFormat); make_task(ZoneGuardStorage, ZoneGuardEntry, HashMapStorageContainer, "zoneguards", gZoneGuardsFormat); make_task(UnitModelSizeStorage, UnitModelSizeEntry, HashMapStorageContainer, "unit_display_sizes", gUnitModelSizeFormat); make_task(WorldStringTableStorage, WorldStringTable, HashMapStorageContainer, "worldstring_tables", gWorldStringTableFormat); make_task(WorldBroadCastStorage, WorldBroadCast, HashMapStorageContainer, "worldbroadcast", gWorldBroadCastFormat); make_task(BGMasterStorage, BGMaster, HashMapStorageContainer, "battlemasters", gBattleMasterFormat); }
time_t see_if_scheduled_event_occurs(void) { time_t now; int which_ev; int count; int lockflag=!islocked(DOS_SEM); int flag; int made_task=-1; task_type which_task; void *task_data; unsigned int stack_size; char task_name[SCHEDULE_DESC_LENGTH+1]; if (lockflag) lock_dos(206); time(&now); if (lockflag) unlock_dos(); if (which_next_event_id == -1) { set_next_scheduled_event(); return (now); }; if (now < next_scheduled_event) return (now); lock(SCHEDULE_SEM); which_ev = find_schedule_with_id(which_next_event_id); if (which_ev == -1) return (now); which_task = schedule[which_ev].call_function; task_data = schedule[which_ev].task_data; stack_size = schedule[which_ev].stack_size; strcpy(task_name,schedule[which_ev].task_name); if ((schedule[which_ev].int_type) == ONE_SHOT_TASK) { unlock(SCHEDULE_SEM); del_task_from_scheduler(which_next_event_id); } else { schedule[which_ev].last_event = now; calc_next_event(which_ev); unlock(SCHEDULE_SEM); }; set_next_scheduled_event(); count=MAX_THREADS-1; flag=1; while (made_task<0) { while ((count>=0) && flag) if (!get_task_status(count)) flag=0; else count--; schedule_data[count] = task_data; if (!flag) #ifdef DEBUG_COMPILE_SCH made_task = 3; #else made_task = make_task(which_task,stack_size,count,6,task_name); #endif DosSleep(3); } return (now); };
auto t4 = make_task([&] { // Perform work in a loop. for (int i = 0; i < 1000; ++i) { // Call a function to perform work. // If the work function fails, cancel all tasks in the tree. bool succeeded = work(i); if (!succeeded) { tg1.cancel(); break; } } });
auto t4 = make_task([&] { // Perform work in a loop. for (int i = 0; i < 1000; ++i) { // Call a function to perform work. // If the work function fails, cancel the parent task // and break from the loop. bool succeeded = work(i); if (!succeeded) { tg2.cancel(); break; } } });