summaryrefslogtreecommitdiff
path: root/firmware/kernel.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/kernel.c')
-rw-r--r--firmware/kernel.c78
1 files changed, 78 insertions, 0 deletions
diff --git a/firmware/kernel.c b/firmware/kernel.c
index 184d29fe93..439aea584a 100644
--- a/firmware/kernel.c
+++ b/firmware/kernel.c
@@ -1368,3 +1368,81 @@ void event_set_state(struct event *e, unsigned int state)
1368#endif 1368#endif
1369} 1369}
1370#endif /* HAVE_EVENT_OBJECTS */ 1370#endif /* HAVE_EVENT_OBJECTS */
1371
1372
1373#ifdef HAVE_WAKEUP_OBJECTS
1374/****************************************************************************
1375 * Lightweight IRQ-compatible wakeup object
1376 */
1377
1378/* Initialize the wakeup object */
1379void wakeup_init(struct wakeup *w)
1380{
1381 w->queue = NULL;
1382 w->signalled = 0;
1383 IF_COP( corelock_init(&w->cl); )
1384}
1385
1386/* Wait for a signal blocking indefinitely or for a specified period */
1387int wakeup_wait(struct wakeup *w, int timeout)
1388{
1389 int ret = WAIT_SUCCEEDED; /* Presume success */
1390 int oldlevel = disable_irq_save();
1391
1392 corelock_lock(&w->cl);
1393
1394 if(w->signalled == 0 && timeout != TIMEOUT_NOBLOCK)
1395 {
1396 struct thread_entry * current = cores[CURRENT_CORE].running;
1397
1398 IF_COP( current->obj_cl = &w->cl; )
1399 current->bqp = &w->queue;
1400
1401 if (timeout != TIMEOUT_BLOCK)
1402 block_thread_w_tmo(current, timeout);
1403 else
1404 block_thread(current);
1405
1406 corelock_unlock(&w->cl);
1407 switch_thread();
1408
1409 oldlevel = disable_irq_save();
1410 corelock_lock(&w->cl);
1411 }
1412
1413 if(w->signalled == 0)
1414 {
1415 /* Timed-out or failed */
1416 ret = (timeout != TIMEOUT_BLOCK) ? WAIT_TIMEDOUT : WAIT_FAILED;
1417 }
1418
1419 w->signalled = 0; /* Reset */
1420
1421 corelock_unlock(&w->cl);
1422 restore_irq(oldlevel);
1423
1424 return ret;
1425}
1426
1427/* Signal the thread waiting or leave the signal if the thread hasn't
1428 * waited yet.
1429 *
1430 * returns THREAD_NONE or THREAD_OK
1431 */
1432int wakeup_signal(struct wakeup *w)
1433{
1434 int oldlevel = disable_irq_save();
1435 int ret;
1436
1437 corelock_lock(&w->cl);
1438
1439 w->signalled = 1;
1440 ret = wakeup_thread(&w->queue);
1441
1442 corelock_unlock(&w->cl);
1443 restore_irq(oldlevel);
1444
1445 return ret;
1446}
1447#endif /* HAVE_WAKEUP_OBJECTS */
1448