Lines Matching +full:lock +full:- +full:regions
5 * SPDX-License-Identifier: Apache-2.0
24 * bits are manipulated by process_event() under lock, and actions
25 * cued by bit values are executed outside of lock within
48 * process_events() must re-check the overall state to confirm no
61 /* No-op event: used to process deferred changes.
71 * state (TO-ON, TO-OFF, or RESETTING).
82 * The client list can change while the manager lock is
92 * This is synthesized from EVT_RECHECK in a non-nested
94 * non-empty client (request) list.
100 * This is synthesized from EVT_RECHECK in a non-nested
108 * This is synthesized from EVT_RECHECK in a non-nested
110 * non-empty client (reset) list.
118 mgr->flags = (state & ONOFF_STATE_MASK) in set_state()
119 | (mgr->flags & ~ONOFF_STATE_MASK); in set_state()
126 return -EINVAL; in validate_args()
129 int rv = sys_notify_validate(&cli->notify); in validate_args()
132 && ((cli->notify.flags in validate_args()
134 rv = -EINVAL; in validate_args()
145 || (transitions->start == NULL) in onoff_manager_init()
146 || (transitions->stop == NULL)) { in onoff_manager_init()
147 return -EINVAL; in onoff_manager_init()
159 sys_slist_t *mlist = &mgr->monitors; in notify_monitors()
164 mon->callback(mgr, mon, state, res); in notify_monitors()
174 (onoff_client_callback)sys_notify_finalize(&cli->notify, res); in notify_one()
204 k_spinlock_key_t key = k_spin_lock(&mgr->lock); in transition_complete()
206 mgr->last_res = res; in transition_complete()
214 uint32_t state = mgr->flags & ONOFF_STATE_MASK; in process_recheck()
217 && !sys_slist_is_empty(&mgr->clients)) { in process_recheck()
220 && (mgr->refs == 0U)) { in process_recheck()
223 && !sys_slist_is_empty(&mgr->clients)) { in process_recheck()
241 uint32_t state = mgr->flags & ONOFF_STATE_MASK; in process_complete()
245 *clients = mgr->clients; in process_complete()
246 sys_slist_init(&mgr->clients); in process_complete()
250 *clients = mgr->clients; in process_complete()
251 sys_slist_init(&mgr->clients); in process_complete()
260 mgr->refs += 1U; in process_complete()
270 mgr->flags |= ONOFF_FLAG_RECHECK; in process_complete()
280 mgr->flags |= ONOFF_FLAG_RECHECK; in process_complete()
290 * * Invocation of the user-specified callback when a stable state is
294 * state, but processing is deferred to the top-level invocation which
296 * regions.
303 uint32_t state = mgr->flags & ONOFF_STATE_MASK; in process_event()
305 bool processing = ((mgr->flags & ONOFF_FLAG_PROCESSING) != 0); in process_event()
314 mgr->flags |= ONOFF_FLAG_COMPLETE; in process_event()
318 mgr->flags |= ONOFF_FLAG_RECHECK; in process_event()
338 res = mgr->last_res; in process_event()
343 __ASSERT_NO_MSG(!sys_slist_is_empty(&mgr->clients)); in process_event()
345 transit = mgr->transitions->start; in process_event()
350 __ASSERT_NO_MSG(mgr->refs == 0); in process_event()
352 transit = mgr->transitions->stop; in process_event()
357 __ASSERT_NO_MSG(!sys_slist_is_empty(&mgr->clients)); in process_event()
359 transit = mgr->transitions->reset; in process_event()
371 bool do_monitors = (state != (mgr->flags & ONOFF_STATE_MASK)) in process_event()
372 && !sys_slist_is_empty(&mgr->monitors); in process_event()
378 uint32_t flags = mgr->flags | ONOFF_FLAG_PROCESSING; in process_event()
380 mgr->flags = flags; in process_event()
383 k_spin_unlock(&mgr->lock, key); in process_event()
397 key = k_spin_lock(&mgr->lock); in process_event()
398 mgr->flags &= ~ONOFF_FLAG_PROCESSING; in process_event()
404 if ((mgr->flags & ONOFF_FLAG_COMPLETE) != 0) { in process_event()
405 mgr->flags &= ~ONOFF_FLAG_COMPLETE; in process_event()
407 } else if ((mgr->flags & ONOFF_FLAG_RECHECK) != 0) { in process_event()
408 mgr->flags &= ~ONOFF_FLAG_RECHECK; in process_event()
414 state = mgr->flags & ONOFF_STATE_MASK; in process_event()
418 k_spin_unlock(&mgr->lock, key); in process_event()
433 k_spinlock_key_t key = k_spin_lock(&mgr->lock); in onoff_request()
434 uint32_t state = mgr->flags & ONOFF_STATE_MASK; in onoff_request()
437 if (mgr->refs == SERVICE_REFS_MAX) { in onoff_request()
438 rv = -EAGAIN; in onoff_request()
446 mgr->refs += 1U; in onoff_request()
454 rv = -ENOTSUP; in onoff_request()
457 rv = -EIO; in onoff_request()
462 sys_slist_append(&mgr->clients, &cli->node); in onoff_request()
468 k_spin_unlock(&mgr->lock, key); in onoff_request()
482 k_spinlock_key_t key = k_spin_lock(&mgr->lock); in onoff_release()
483 uint32_t state = mgr->flags & ONOFF_STATE_MASK; in onoff_release()
488 rv = -EIO; in onoff_release()
490 rv = -ENOTSUP; in onoff_release()
495 __ASSERT_NO_MSG(mgr->refs > 0); in onoff_release()
496 mgr->refs -= 1U; in onoff_release()
497 stop = (mgr->refs == 0); in onoff_release()
503 k_spin_unlock(&mgr->lock, key); in onoff_release()
516 && (mgr->transitions->reset == NULL)) { in onoff_reset()
517 rv = -ENOTSUP; in onoff_reset()
524 k_spinlock_key_t key = k_spin_lock(&mgr->lock); in onoff_reset()
525 uint32_t state = mgr->flags & ONOFF_STATE_MASK; in onoff_reset()
530 rv = -EALREADY; in onoff_reset()
533 sys_slist_append(&mgr->clients, &cli->node); in onoff_reset()
539 k_spin_unlock(&mgr->lock, key); in onoff_reset()
549 return -EINVAL; in onoff_cancel()
552 int rv = -EALREADY; in onoff_cancel()
553 k_spinlock_key_t key = k_spin_lock(&mgr->lock); in onoff_cancel()
554 uint32_t state = mgr->flags & ONOFF_STATE_MASK; in onoff_cancel()
556 if (sys_slist_find_and_remove(&mgr->clients, &cli->node)) { in onoff_cancel()
563 k_spin_unlock(&mgr->lock, key); in onoff_cancel()
573 || (mon->callback == NULL)) { in onoff_monitor_register()
574 return -EINVAL; in onoff_monitor_register()
577 k_spinlock_key_t key = k_spin_lock(&mgr->lock); in onoff_monitor_register()
579 sys_slist_append(&mgr->monitors, &mon->node); in onoff_monitor_register()
581 k_spin_unlock(&mgr->lock, key); in onoff_monitor_register()
589 int rv = -EINVAL; in onoff_monitor_unregister()
596 k_spinlock_key_t key = k_spin_lock(&mgr->lock); in onoff_monitor_unregister()
598 if (sys_slist_find_and_remove(&mgr->monitors, &mon->node)) { in onoff_monitor_unregister()
602 k_spin_unlock(&mgr->lock, key); in onoff_monitor_unregister()
610 *keyp = k_spin_lock(&srv->lock); in onoff_sync_lock()
611 return srv->count; in onoff_sync_lock()
626 if (srv->count < 0) { in onoff_sync_finalize()
627 srv->count = 0; in onoff_sync_finalize()
630 srv->count = res; in onoff_sync_finalize()
633 srv->count += 1; in onoff_sync_finalize()
635 srv->count -= 1; in onoff_sync_finalize()
642 int rv = srv->count; in onoff_sync_finalize()
644 k_spin_unlock(&srv->lock, key); in onoff_sync_finalize()
647 /* Detect service mis-use: onoff does not callback on transition in onoff_sync_finalize()