aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/compute/skc/scheduler.h
blob: 78da50be2a3d52080b8ecfebbe3c37eb61f36829 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
 * Copyright 2017 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can
 * be found in the LICENSE file.
 *
 */

#pragma once

//
// FIXME -- make the scheduler even more lightweight than it is.  Move
// to an idiom where the scheduled task brings its own state instead
// of relying on an internal table.  This will make it possible to
// reliably report the task's lifecycle and terminating state.
//

#include "types.h"

//
//
//

#define SKC_SCHEDULER_SCHEDULE(s,c,d) skc_scheduler_schedule(s,c,d,#c)

#ifndef NDEBUG

#include <stdio.h>

#define SKC_SCHEDULER_WAIT_WHILE(s,p)           \
  while (p) {                                   \
    fprintf(stderr,"WAITING ON: " #p "\n");     \
    skc_scheduler_wait(s);                      \
  }
#else
#define SKC_SCHEDULER_WAIT_WHILE(s,p)           \
  while (p) {                                   \
    skc_scheduler_wait(s);                      \
  }
#endif

//
//
//

#ifndef NDEBUG
#define SKC_CL_CB(s)  fprintf(stderr,"CB+ %s = %d\n",__func__,s)
#else
#include <stdio.h>
#define SKC_CL_CB(s)
#endif

//
//
//

#define SKC_SCHEDULER_COMMAND_INVALID  SKC_UINT_MAX

typedef skc_uint skc_scheduler_command_t;

typedef void (* skc_scheduler_command_pfn)(void * data);

//
//
//

struct skc_scheduler *
skc_scheduler_create(struct skc_runtime * const runtime, skc_uint const size);

void
skc_scheduler_dispose(struct skc_runtime   * const runtime,
                      struct skc_scheduler * const scheduler);


//
//
//

skc_scheduler_command_t
skc_scheduler_schedule(struct skc_scheduler    * const scheduler,
		       skc_scheduler_command_pfn const pfn,
		       void                    *       data,
                       char              const * const name);

//
//
//

skc_bool
skc_scheduler_yield(struct skc_scheduler * const scheduler);

void
skc_scheduler_wait(struct skc_scheduler * const scheduler);

void
skc_scheduler_wait_one(struct skc_scheduler * const scheduler);

//
// FIXME -- get rid of these
//

#if 0

skc_bool
skc_scheduler_wait_for(struct skc_scheduler  * const scheduler,
                       skc_scheduler_command_t const command);

void
skc_thread_sleep(skc_ulong const msecs);

#endif

//
//
//