summaryrefslogtreecommitdiff
path: root/firmware/kernel.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/kernel.c')
-rw-r--r--firmware/kernel.c117
1 files changed, 0 insertions, 117 deletions
diff --git a/firmware/kernel.c b/firmware/kernel.c
index 10efb87cf4..fb9c5e2449 100644
--- a/firmware/kernel.c
+++ b/firmware/kernel.c
@@ -1264,122 +1264,6 @@ void semaphore_release(struct semaphore *s)
1264} 1264}
1265#endif /* HAVE_SEMAPHORE_OBJECTS */ 1265#endif /* HAVE_SEMAPHORE_OBJECTS */
1266 1266
1267/****************************************************************************
1268 * Simple event functions ;)
1269 ****************************************************************************/
1270#ifdef HAVE_EVENT_OBJECTS
1271void event_init(struct event *e, unsigned int flags)
1272{
1273 e->queues[STATE_NONSIGNALED] = NULL;
1274 e->queues[STATE_SIGNALED] = NULL;
1275 e->state = flags & STATE_SIGNALED;
1276 e->automatic = (flags & EVENT_AUTOMATIC) ? 1 : 0;
1277 corelock_init(&e->cl);
1278}
1279
1280void event_wait(struct event *e, unsigned int for_state)
1281{
1282 struct thread_entry *current;
1283
1284 corelock_lock(&e->cl);
1285
1286 if(e->automatic != 0)
1287 {
1288 /* wait for false always satisfied by definition
1289 or if it just changed to false */
1290 if(e->state == STATE_SIGNALED || for_state == STATE_NONSIGNALED)
1291 {
1292 /* automatic - unsignal */
1293 e->state = STATE_NONSIGNALED;
1294 corelock_unlock(&e->cl);
1295 return;
1296 }
1297 /* block until state matches */
1298 }
1299 else if(for_state == e->state)
1300 {
1301 /* the state being waited for is the current state */
1302 corelock_unlock(&e->cl);
1303 return;
1304 }
1305
1306 /* block until state matches what callers requests */
1307 current = cores[CURRENT_CORE].running;
1308
1309 IF_COP( current->obj_cl = &e->cl; )
1310 current->bqp = &e->queues[for_state];
1311
1312 disable_irq();
1313 block_thread(current);
1314
1315 corelock_unlock(&e->cl);
1316
1317 /* turn control over to next thread */
1318 switch_thread();
1319}
1320
1321void event_set_state(struct event *e, unsigned int state)
1322{
1323 unsigned int result;
1324 int oldlevel;
1325
1326 corelock_lock(&e->cl);
1327
1328 if(e->state == state)
1329 {
1330 /* no change */
1331 corelock_unlock(&e->cl);
1332 return;
1333 }
1334
1335 IF_PRIO( result = THREAD_OK; )
1336
1337 oldlevel = disable_irq_save();
1338
1339 if(state == STATE_SIGNALED)
1340 {
1341 if(e->automatic != 0)
1342 {
1343 /* no thread should have ever blocked for nonsignaled */
1344 KERNEL_ASSERT(e->queues[STATE_NONSIGNALED] == NULL,
1345 "set_event_state->queue[NS]:S\n");
1346 /* pass to next thread and keep unsignaled - "pulse" */
1347 result = wakeup_thread(&e->queues[STATE_SIGNALED]);
1348 e->state = (result & THREAD_OK) ? STATE_NONSIGNALED : STATE_SIGNALED;
1349 }
1350 else
1351 {
1352 /* release all threads waiting for signaled */
1353 e->state = STATE_SIGNALED;
1354 IF_PRIO( result = )
1355 thread_queue_wake(&e->queues[STATE_SIGNALED]);
1356 }
1357 }
1358 else
1359 {
1360 /* release all threads waiting for nonsignaled */
1361
1362 /* no thread should have ever blocked if automatic */
1363 KERNEL_ASSERT(e->queues[STATE_NONSIGNALED] == NULL ||
1364 e->automatic == 0, "set_event_state->queue[NS]:NS\n");
1365
1366 e->state = STATE_NONSIGNALED;
1367 IF_PRIO( result = )
1368 thread_queue_wake(&e->queues[STATE_NONSIGNALED]);
1369 }
1370
1371 restore_irq(oldlevel);
1372
1373 corelock_unlock(&e->cl);
1374
1375#ifdef HAVE_PRIORITY_SCHEDULING
1376 if(result & THREAD_SWITCH)
1377 switch_thread();
1378#endif
1379}
1380#endif /* HAVE_EVENT_OBJECTS */
1381
1382
1383#ifdef HAVE_WAKEUP_OBJECTS 1267#ifdef HAVE_WAKEUP_OBJECTS
1384/**************************************************************************** 1268/****************************************************************************
1385 * Lightweight IRQ-compatible wakeup object 1269 * Lightweight IRQ-compatible wakeup object
@@ -1456,4 +1340,3 @@ int wakeup_signal(struct wakeup *w)
1456 return ret; 1340 return ret;
1457} 1341}
1458#endif /* HAVE_WAKEUP_OBJECTS */ 1342#endif /* HAVE_WAKEUP_OBJECTS */
1459