blob: 78da50be2a3d52080b8ecfebbe3c37eb61f36829 [file] [log] [blame]
Allan MacKinnon4359d522018-06-19 13:57:04 -07001/*
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 Canary14195342018-07-11 16:10:14 -040021//
Allan MacKinnon4359d522018-06-19 13:57:04 -070022//
23
24#define SKC_SCHEDULER_SCHEDULE(s,c,d) skc_scheduler_schedule(s,c,d,#c)
25
Hal Canary14195342018-07-11 16:10:14 -040026#ifndef NDEBUG
Allan MacKinnon4359d522018-06-19 13:57:04 -070027
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
59typedef skc_uint skc_scheduler_command_t;
60
61typedef void (* skc_scheduler_command_pfn)(void * data);
62
63//
64//
65//
66
67struct skc_scheduler *
68skc_scheduler_create(struct skc_runtime * const runtime, skc_uint const size);
69
70void
71skc_scheduler_dispose(struct skc_runtime * const runtime,
72 struct skc_scheduler * const scheduler);
Hal Canary14195342018-07-11 16:10:14 -040073
Allan MacKinnon4359d522018-06-19 13:57:04 -070074
75//
76//
77//
78
79skc_scheduler_command_t
80skc_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
89skc_bool
90skc_scheduler_yield(struct skc_scheduler * const scheduler);
91
92void
93skc_scheduler_wait(struct skc_scheduler * const scheduler);
94
95void
96skc_scheduler_wait_one(struct skc_scheduler * const scheduler);
97
98//
99// FIXME -- get rid of these
100//
101
102#if 0
103
104skc_bool
105skc_scheduler_wait_for(struct skc_scheduler * const scheduler,
106 skc_scheduler_command_t const command);
107
108void
109skc_thread_sleep(skc_ulong const msecs);
110
111#endif
112
113//
114//
115//