00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00020 #include <cubeos.h>
00021 #include <sys_var.h>
00022 #include <ptimer.h>
00023 #include <schedule.h>
00024 #include <list.h>
00025
00026
00027
00028
00029
00030
00031 int KERN_psleep (unsigned int howlong)
00032 {
00033 int deltatrack = 0;
00034 int savetime;
00035 struct process *currentprocess;
00036 struct process *thisprocess;
00037 entry *listentry;
00038 int quit = 0;
00039
00040 disable ();
00041
00042
00043 if (LIST_entries (&_KERN_delta) == 0) {
00044
00045 _KERN_ptable[getpid ()].time_delta = howlong;
00046 LIST_insert_head (&_KERN_delta, &(_KERN_ptable[getpid ()].me));
00047 enable ();
00048 return (KERN_suspend (-1));
00049 }
00050 listentry = LIST_head (&_KERN_delta);
00051 thisprocess = &(_KERN_ptable[getpid ()]);
00052 while (!quit) {
00053 currentprocess = (struct process *) (listentry->data);
00054 deltatrack += currentprocess->time_delta;
00055 if (howlong <= deltatrack) {
00056
00057
00058
00059
00060 LIST_insert_before (&(thisprocess->me), listentry);
00061
00062
00063 currentprocess->time_delta = -howlong;
00064
00065
00066 thisprocess->time_delta = howlong - deltatrack;
00067 quit = 1;
00068 } else {
00069 if (listentry->next) {
00070 listentry = listentry->next;
00071 } else {
00072
00073 LIST_insert_after (&(thisprocess->me), listentry);
00074 thisprocess->time_delta = howlong - deltatrack;
00075 quit = 1;
00076 }
00077 }
00078 }
00079
00080 enable ();
00081 return (-1);
00082 }
00083
00084
00085
00086
00087
00088
00089
00090
00091 int KERN_ssleep (unsigned int howlong)
00092 {
00093 unsigned int seconds;
00094 unsigned int ticks;
00095
00096 disable ();
00097 seconds = _time_seconds;
00098 ticks = _time_ticks;
00099 enable ();
00100
00101 seconds += howlong;
00102
00103 while (seconds > _time_seconds);
00104 while ((seconds == _time_seconds) && (ticks > _time_ticks));
00105 return (0);
00106 }
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116 int KERN_usleep (unsigned int howlong)
00117 {
00118 unsigned int seconds;
00119 unsigned int ticks;
00120
00121
00122 disable ();
00123 seconds = _time_seconds;
00124 ticks = _time_ticks;
00125 enable ();
00126 ticks += howlong * TICKS_PER_SECOND / 1000000;
00127 seconds += ticks / TICKS_PER_SECOND;
00128 ticks = ticks % TICKS_PER_SECOND;
00129 while (seconds > _time_seconds);
00130 while ((seconds == _time_seconds) && (ticks > _time_ticks));
00131 return (0);
00132
00133 }