home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_08_12 / 8n12074a < prev    next >
Text File  |  1990-08-29  |  2KB  |  54 lines

  1. /* schedcon.c - Scheduling Control task */
  2.  
  3. #include <synrtx.h>
  4.  
  5. static handler IdentifyTheCallerTask(msg_t *msg_ptr) {
  6.     register task_t caller = msg_ptr->srcTid;
  7.  
  8.     io_putf("Interrupted by task #%w named: %s\n", caller, task_nameOf(caller));
  9. }
  10.  
  11. task SchedulingControl(void) {
  12.     task_t       myChild, self;
  13.     priority_t   myPriority;
  14.     timeslice_t  myTimeslice;
  15.  
  16.     /* creation of a child named ChildTask, priority 1, timeslice 20ms */
  17.     myChild = task_create(ChildTask, "ChildTask", 1, 20, NO_ARG, NO_VAR);
  18.  
  19.     /* print the child taskid in three different ways
  20.     io_putw(myChild);
  21.     io_putw(task_child());
  22.     io_putw(task_idOf("ChildTask"));
  23.  
  24.     /* Start the execution of myChild */
  25.     task_resume(myChild);
  26.  
  27.     /* Print my task id and my parent task id */
  28.     io_putw(task_self());
  29.     io_putw(task_parent());
  30.  
  31.     /* Save my priority and my time slice */
  32.     self = task_self();
  33.     myPriority  = task_priorityOf(self);
  34.     myTimeslice = task_timesliceOf(self);
  35.  
  36.     /* Raise my priority */
  37.     task_setPriorityOf(self, myPriority + 1);
  38.  
  39.     /* Suspend my child, give him my old priority, and start him again */
  40.     task_suspend(myChild);
  41.     task_setPriorityOf(myChild, myPriority);
  42.     task_resume(myChild);
  43.  
  44.     /* Raise my time slice by 10 real-time units */
  45.     task_setTimesliceOf(self, myTimeslice + 10);
  46.  
  47.     /* Give up the cpu */
  48.     task_reschedule();
  49.  
  50.     /* When get back here, kill my child, and suicide */
  51.     task_terminate(myChild);
  52.     task_terminate(self);
  53. }
  54.