Changeset 4450 for trunk/Ohana/src/opihi/pantasks/run.c
- Timestamp:
- Jul 4, 2005, 5:35:47 PM (21 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/opihi/pantasks/run.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/pantasks/run.c
r3140 r4450 1 # include "basic.h"2 1 # include "scheduler.h" 3 2 4 3 int run (int argc, char **argv) { 5 6 Job *job;7 Task *task;8 Macro *macro;9 int i, found, status;10 int Ntest;11 4 12 5 if (argc != 1) { … … 15 8 } 16 9 17 /* start the clock for all tasks */ 18 while ((task = NextTask ()) != NULL) { 19 gettimeofday (&task[0].last, (void *) NULL); 10 InitTaskTimers (); 11 rl_event_hook = CheckSystem; 12 rl_set_keyboard_input_timeout (1000000); 13 14 return (TRUE); 15 } 16 17 int stop (int argc, char **argv) { 18 19 if (argc != 1) { 20 fprintf (stderr, "USAGE: stop\n"); 21 return (FALSE); 20 22 } 21 23 22 Ntest = 0; 24 rl_event_hook = NULL; 25 rl_set_keyboard_input_timeout (1000000); 23 26 24 /* loop forever, checking for completed jobs and ready tasks */25 while (1) {26 if (Ntest > 5) {27 ListJobs ();28 Ntest = 0;29 }30 usleep (10000);31 Ntest ++;32 33 /** test all tasks: ready to test? ready to run? **/34 while ((task = NextTask ()) != NULL) {35 36 /* ready to test? : check exec period */37 if (GetTaskTimer(task[0].last) < task[0].exec_period) continue;38 39 SetCurrentTask (task[0].name);40 fprintf (stderr, "trying task %s\n", task[0].name);41 42 /* ready to run? : run task.exec macro */43 if (task[0].exec != NULL) {44 status = exec_loop (task[0].exec);45 if (!status) continue;46 }47 48 /* is task valid? check state of task.(argc, argv) */49 /*** ADD CODE HERE ***/50 51 /* construct job from task */52 job = CreateJob (task);53 54 /* execute job - XXX add status test */55 SubmitJob (job);56 57 /* reset timer on task (don't do this if Create/Submit fails)*/58 gettimeofday (&task[0].last, (void *) NULL);59 }60 61 /** test all jobs: ready to test? finished? **/62 while ((job = NextJob ()) != NULL) {63 64 /* check for timeout */65 if (GetTaskTimer(job[0].start) >= job[0].task.timeout_period) {66 fprintf (stderr, "timeout on %s\n", job[0].task.name);67 /* run task.timeout macro, if it exists */68 if (job[0].task.timeout != NULL) {69 exec_loop (job[0].task.timeout);70 }71 DeleteJob (job);72 continue;73 }74 75 /* check poll period (ready to run again?) */76 if (GetTaskTimer(job[0].last) < job[0].task.poll_period) continue;77 78 /* check current status */79 status = CheckJob (job);80 switch (status) {81 case JOB_BUSY:82 fprintf (stderr, "job %s (%d) busy\n", job[0].task.name, job[0].JobID);83 break;84 85 case JOB_CRASH:86 fprintf (stderr, "job %s (%d) crash\n", job[0].task.name, job[0].JobID);87 /* run task.crash macro, if it exists */88 if (job[0].task.crash != NULL) {89 exec_loop (job[0].task.crash);90 }91 DeleteJob (job);92 continue;93 break;94 95 case JOB_EXIT:96 fprintf (stderr, "job %s (%d) exit\n", job[0].task.name, job[0].JobID);97 /* run corresponding task.exit macro, if it exists */98 macro = job[0].task.def;99 for (i = 0; i < job[0].task.Nexit; i++) {100 if (job[0].exit_status == atoi(job[0].task.exit[i][0].name)) {101 macro = job[0].task.exit[i];102 break;103 }104 }105 if (macro != NULL) exec_loop (macro);106 DeleteJob (job);107 continue;108 break;109 110 default:111 fprintf (stderr, "unknown exit status\n");112 /** do something more useful here ?? **/113 break;114 }115 116 /* reset polling clock */117 SetTaskTimer (&job[0].last);118 }119 }120 27 return (TRUE); 121 28 }
Note:
See TracChangeset
for help on using the changeset viewer.
