Skip to content

Commit ff11096

Browse files
committed
kernel: Fix OS::block issue with new deferred timer creation
1 parent 2e46a7d commit ff11096

3 files changed

Lines changed: 21 additions & 19 deletions

File tree

src/kernel/events.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ void Events::process_events()
108108
#ifdef DEBUG_SMP
109109
SMP::global_lock();
110110
if (intr != 0)
111-
printf("[%p] Calling handler for intr=%u irq=%u cpu %d\n",
112-
get_cpu_esp(), IRQ_BASE + intr, intr, SMP::cpu_id());
111+
printf("[cpu%d] Calling handler for intr=%u irq=%u\n",
112+
SMP::cpu_id(), IRQ_BASE + intr, intr);
113113
SMP::global_unlock();
114114
#endif
115115
callbacks[intr]();

src/platform/x86_pc/block.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ extern "C" uint32_t os_get_highest_blocking_level() {
3838
* A quick and dirty implementation of blocking calls, which simply halts,
3939
* then calls the event loop, then returns.
4040
**/
41-
void OS::block(){
42-
41+
void OS::block()
42+
{
4343
// Initialize stats
4444
if (not blocking_level) {
4545
blocking_level = &Statman::get()
@@ -60,10 +60,13 @@ void OS::block(){
6060
if (*blocking_level > *highest_blocking_level)
6161
*highest_blocking_level = *blocking_level;
6262

63+
// Process immediate events
64+
Events::get().process_events();
65+
6366
// Await next interrupt
6467
OS::halt();
6568

66-
// Process callbacks
69+
// Process events (again?)
6770
Events::get().process_events();
6871

6972
// Decrement level

test/kernel/integration/block/service.cpp

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,25 @@
1717

1818
#include <os>
1919
#include <timers>
20+
using namespace std::chrono;
2021

2122
extern "C" uint32_t os_get_blocking_level();
2223
extern "C" uint32_t os_get_highest_blocking_level();
2324

24-
void sleep(int i){
25-
static Timers::id_t timer{};
26-
27-
if (not timer)
28-
timer = Timers::oneshot(std::chrono::seconds(i), [](auto){
29-
INFO("Timer", "Ticked");
30-
timer = 0;
31-
Expects(os_get_blocking_level() == 1);
32-
});
33-
34-
while (timer) {
25+
static void msleep(int micros)
26+
{
27+
bool ticked = false;
28+
Timers::oneshot(microseconds(micros),
29+
[&ticked] (int) {
30+
INFO("Timer", "Ticked");
31+
ticked = true;
32+
Expects(os_get_blocking_level() == 1);
33+
});
34+
35+
while (ticked == false) {
3536
OS::block();
3637
Expects(os_get_blocking_level() == 0);
3738
}
38-
39-
INFO("Test", " Done");
4039
}
4140

4241
void Service::start()
@@ -50,7 +49,7 @@ void Service::ready()
5049

5150
int n = 10;
5251
for (int i = 0; i < n; i++) {
53-
sleep(1);
52+
msleep(1000000);
5453
sleeps++;
5554
printf("Sleep %i/%i \n", sleeps, n);
5655
if (sleeps == 10)

0 commit comments

Comments
 (0)