Allan MacKinnon | 4359d52 | 2018-06-19 13:57:04 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can |
| 5 | * be found in the LICENSE file. |
| 6 | * |
| 7 | */ |
| 8 | |
| 9 | #pragma once |
| 10 | |
| 11 | // |
| 12 | // FIXME -- make the scheduler even more lightweight than it is. Move |
| 13 | // to an idiom where the scheduled task brings its own state instead |
| 14 | // of relying on an internal table. This will make it possible to |
| 15 | // reliably report the task's lifecycle and terminating state. |
| 16 | // |
| 17 | |
| 18 | #include "types.h" |
| 19 | |
| 20 | // |
Hal Canary | 1419534 | 2018-07-11 16:10:14 -0400 | [diff] [blame] | 21 | // |
Allan MacKinnon | 4359d52 | 2018-06-19 13:57:04 -0700 | [diff] [blame] | 22 | // |
| 23 | |
| 24 | #define SKC_SCHEDULER_SCHEDULE(s,c,d) skc_scheduler_schedule(s,c,d,#c) |
| 25 | |
Hal Canary | 1419534 | 2018-07-11 16:10:14 -0400 | [diff] [blame] | 26 | #ifndef NDEBUG |
Allan MacKinnon | 4359d52 | 2018-06-19 13:57:04 -0700 | [diff] [blame] | 27 | |
| 28 | #include <stdio.h> |
| 29 | |
| 30 | #define SKC_SCHEDULER_WAIT_WHILE(s,p) \ |
| 31 | while (p) { \ |
| 32 | fprintf(stderr,"WAITING ON: " #p "\n"); \ |
| 33 | skc_scheduler_wait(s); \ |
| 34 | } |
| 35 | #else |
| 36 | #define SKC_SCHEDULER_WAIT_WHILE(s,p) \ |
| 37 | while (p) { \ |
| 38 | skc_scheduler_wait(s); \ |
| 39 | } |
| 40 | #endif |
| 41 | |
| 42 | // |
| 43 | // |
| 44 | // |
| 45 | |
| 46 | #ifndef NDEBUG |
| 47 | #define SKC_CL_CB(s) fprintf(stderr,"CB+ %s = %d\n",__func__,s) |
| 48 | #else |
| 49 | #include <stdio.h> |
| 50 | #define SKC_CL_CB(s) |
| 51 | #endif |
| 52 | |
| 53 | // |
| 54 | // |
| 55 | // |
| 56 | |
| 57 | #define SKC_SCHEDULER_COMMAND_INVALID SKC_UINT_MAX |
| 58 | |
| 59 | typedef skc_uint skc_scheduler_command_t; |
| 60 | |
| 61 | typedef void (* skc_scheduler_command_pfn)(void * data); |
| 62 | |
| 63 | // |
| 64 | // |
| 65 | // |
| 66 | |
| 67 | struct skc_scheduler * |
| 68 | skc_scheduler_create(struct skc_runtime * const runtime, skc_uint const size); |
| 69 | |
| 70 | void |
| 71 | skc_scheduler_dispose(struct skc_runtime * const runtime, |
| 72 | struct skc_scheduler * const scheduler); |
Hal Canary | 1419534 | 2018-07-11 16:10:14 -0400 | [diff] [blame] | 73 | |
Allan MacKinnon | 4359d52 | 2018-06-19 13:57:04 -0700 | [diff] [blame] | 74 | |
| 75 | // |
| 76 | // |
| 77 | // |
| 78 | |
| 79 | skc_scheduler_command_t |
| 80 | skc_scheduler_schedule(struct skc_scheduler * const scheduler, |
| 81 | skc_scheduler_command_pfn const pfn, |
| 82 | void * data, |
| 83 | char const * const name); |
| 84 | |
| 85 | // |
| 86 | // |
| 87 | // |
| 88 | |
| 89 | skc_bool |
| 90 | skc_scheduler_yield(struct skc_scheduler * const scheduler); |
| 91 | |
| 92 | void |
| 93 | skc_scheduler_wait(struct skc_scheduler * const scheduler); |
| 94 | |
| 95 | void |
| 96 | skc_scheduler_wait_one(struct skc_scheduler * const scheduler); |
| 97 | |
| 98 | // |
| 99 | // FIXME -- get rid of these |
| 100 | // |
| 101 | |
| 102 | #if 0 |
| 103 | |
| 104 | skc_bool |
| 105 | skc_scheduler_wait_for(struct skc_scheduler * const scheduler, |
| 106 | skc_scheduler_command_t const command); |
| 107 | |
| 108 | void |
| 109 | skc_thread_sleep(skc_ulong const msecs); |
| 110 | |
| 111 | #endif |
| 112 | |
| 113 | // |
| 114 | // |
| 115 | // |