| 188 | | int SysTimerCreate() |
| 189 | | { |
| 190 | | return 0; |
| 191 | | } |
| 192 | | |
| 193 | | int SysTimerDestroy() |
| 194 | | { |
| 195 | | return 0; |
| 196 | | } |
| | 200 | int SysTimerCreate(struct UserTimer* timerDesc) |
| | 201 | { |
| | 202 | int i; |
| | 203 | struct KeTimer* curr; |
| | 204 | |
| | 205 | SpinLock(¤t->timerListLock); |
| | 206 | |
| | 207 | if (!current->timers) |
| | 208 | { |
| | 209 | current->numTimers = KE_TIMER_ALLOC_STEP; |
| | 210 | current->timers = (struct KeTimer**)MemAlloc(sizeof(struct KeTimer) * KE_TIMER_ALLOC_STEP); |
| | 211 | } |
| | 212 | |
| | 213 | for (i = 0; i < current->numTimers; i++) |
| | 214 | if (!current->timers[i]) |
| | 215 | break; |
| | 216 | |
| | 217 | if (i == current->numTimers) |
| | 218 | { |
| | 219 | KePrint("TODO: Extend array\n"); |
| | 220 | } |
| | 221 | |
| | 222 | current->timers[i] = (struct KeTimer*)MemAlloc(sizeof(struct KeTimer)); |
| | 223 | curr = current->timers[i]; |
| | 224 | |
| | 225 | curr->thread = currThread; |
| | 226 | memcpy(&curr->uInfo, timerDesc, sizeof(struct UserTimer)); |
| | 227 | curr->timer.func = TimerWakeup; |
| | 228 | curr->timer.data = curr; |
| | 229 | |
| | 230 | SpinUnlock(¤t->timerListLock); |
| | 231 | |
| | 232 | return i; |
| | 233 | } |
| | 234 | |
| | 235 | struct KeTimer* TimerGet(struct Process* process, int timer) |
| | 236 | { |
| | 237 | if (timer < 0 || timer > process->numTimers) |
| | 238 | return NULL; |
| | 239 | |
| | 240 | return process->timers[timer]; |
| | 241 | } |
| | 242 | |
| | 243 | int SysTimerModify(int tid, struct UserTimerSpec* newValue, struct UserTimerSpec* oldValue) |
| | 244 | { |
| | 245 | struct KeTimer* timer; |
| | 246 | |
| | 247 | timer = TimerGet(current, tid); |
| | 248 | |
| | 249 | if (oldValue) |
| | 250 | { |
| | 251 | KePrint("oldValue != NULL\n"); |
| | 252 | return -ENOTIMPL; |
| | 253 | } |
| | 254 | |
| | 255 | if (!newValue) |
| | 256 | return -EFAULT; |
| | 257 | |
| | 258 | /* TODO: Check if timer is already on list */ |
| | 259 | |
| | 260 | timer->timer.expires = newValue->secs * 1000; |
| | 261 | /* useconds */ |
| | 262 | TimerAdd(&timer->timer); |
| | 263 | |
| | 264 | return 0; |
| | 265 | } |
| | 266 | |
| | 267 | int SysTimerDestroy(int timer) |
| | 268 | { |
| | 269 | KePrint("SysTimerDestroy(%d)\n", timer); |
| | 270 | return 0; |
| | 271 | } |
| | 272 | |
| | 273 | int TimerProcessRemove(struct Process* process) |
| | 274 | { |
| | 275 | if (process->timers) |
| | 276 | { |
| | 277 | KePrint("Free timers\n"); |
| | 278 | } |
| | 279 | |
| | 280 | return 0; |
| | 281 | } |
| | 282 | |
| | 283 | static struct SysCall timerSysCallTable[]= |
| | 284 | { |
| | 285 | SysEntry(SysTimerCreate, 4), |
| | 286 | SysEntry(SysTimerModify, 12), |
| | 287 | SysEntry(SysTimerDestroy, 4), |
| | 288 | SysEntryEnd() |
| | 289 | }; |
| | 290 | |
| | 291 | int TimerInit() |
| | 292 | { |
| | 293 | SysRegisterRange(SYS_TIMER_BASE, timerSysCallTable); |
| | 294 | return 0; |
| | 295 | } |