The manual
ginnOS
The reference: libc, the libraries and the kernel
Toggle main menu visibility
Loading...
Searching...
No Matches
completion.h
Go to the documentation of this file.
1
#pragma once
2
3
/**
4
* @file completion.h
5
* @brief wait for a device: sleep until its interrupt, or poll.
6
*
7
* a driver starts a command, then calls completion_wait_until with a
8
* function that reads the device status. its interrupt handler calls
9
* completion_signal. the waiting process sleeps between interrupts, so the
10
* CPU runs other processes while the device works.
11
*
12
* the wait polls instead of sleeping when:
13
* - the driver has no interrupt (use_irq is false),
14
* - the caller cannot sleep (before the scheduler runs, or with
15
* interrupts off),
16
* - the interrupt did not come: if the device is ready after a short
17
* sleep without an interrupt, the interrupt does not work, and the
18
* completion polls from then on (and says so in the kernel log).
19
*/
20
21
#include "
common/stdint.h
"
22
#include "
kernel/time/timer.h
"
23
24
typedef
struct
25
{
26
volatile
bool
done
;
// set by completion_signal, cleared by the waiter
27
spinlock_t
lock
;
// guards done
28
bool
use_irq
;
// the device has a working interrupt
29
const
char
*
name
;
// for the kernel log
30
timed_queue_t
queue
;
// the sleeping waiter
31
}
completion_t
;
32
33
/**
34
* a function that reads the device status.
35
* @return true when the command is done (or has failed).
36
*/
37
typedef
bool
(*
completion_ready_t
)(
void
*context);
38
39
/**
40
* initialize a completion. call once (it registers a timed queue).
41
* @param use_irq true if the driver has an interrupt handler.
42
*/
43
void
completion_init
(
completion_t
*completion,
const
char
*name,
bool
use_irq);
44
45
/**
46
* the device has something to report. safe in an interrupt handler.
47
*/
48
void
completion_signal
(
completion_t
*completion);
49
50
/**
51
* wait until ready(context) returns true.
52
* @param timeout_ms how long the device may take.
53
* @return false if the device was not ready in time.
54
*/
55
bool
completion_wait_until
(
completion_t
*completion,
completion_ready_t
ready,
void
*context,
56
uint32_t
timeout_ms);
stdint.h
completion_wait_until
bool completion_wait_until(completion_t *completion, completion_ready_t ready, void *context, uint32_t timeout_ms)
wait until ready(context) returns true.
Definition
completion.c:53
completion_init
void completion_init(completion_t *completion, const char *name, bool use_irq)
initialize a completion.
Definition
completion.c:18
completion_signal
void completion_signal(completion_t *completion)
the device has something to report.
Definition
completion.c:27
completion_ready_t
bool(*) completion_ready_t(void *context)
a function that reads the device status.
Definition
completion.h:37
uint32_t
unsigned int uint32_t
Definition
fb.h:17
bool
#define bool
Definition
stdbool.h:8
completion_t
Definition
completion.h:25
completion_t::done
volatile bool done
Definition
completion.h:26
completion_t::queue
timed_queue_t queue
Definition
completion.h:30
completion_t::use_irq
bool use_irq
Definition
completion.h:28
completion_t::lock
spinlock_t lock
Definition
completion.h:27
completion_t::name
const char * name
Definition
completion.h:29
spinlock_t
kernel locking rules:
Definition
spinlock.h:67
timer.h
timed_queue_t
struct timed_queue timed_queue_t
a wait queue with a deadline.
src
kernel
sync
completion.h
Generated by
1.18.0