Lines Matching refs:mgr

115 static void set_state(struct onoff_manager *mgr,  in set_state()  argument
118 mgr->flags = (state & ONOFF_STATE_MASK) in set_state()
119 | (mgr->flags & ~ONOFF_STATE_MASK); in set_state()
122 static int validate_args(const struct onoff_manager *mgr, in validate_args() argument
125 if ((mgr == NULL) || (cli == NULL)) { in validate_args()
140 int onoff_manager_init(struct onoff_manager *mgr, in onoff_manager_init() argument
143 if ((mgr == NULL) in onoff_manager_init()
150 *mgr = (struct onoff_manager)ONOFF_MANAGER_INITIALIZER(transitions); in onoff_manager_init()
155 static void notify_monitors(struct onoff_manager *mgr, in notify_monitors() argument
159 sys_slist_t *mlist = &mgr->monitors; in notify_monitors()
164 mon->callback(mgr, mon, state, res); in notify_monitors()
168 static void notify_one(struct onoff_manager *mgr, in notify_one() argument
177 cb(mgr, cli, state, res); in notify_one()
181 static void notify_all(struct onoff_manager *mgr, in notify_all() argument
193 notify_one(mgr, cli, state, res); in notify_all()
197 static void process_event(struct onoff_manager *mgr,
201 static void transition_complete(struct onoff_manager *mgr, in transition_complete() argument
204 k_spinlock_key_t key = k_spin_lock(&mgr->lock); in transition_complete()
206 mgr->last_res = res; in transition_complete()
207 process_event(mgr, EVT_COMPLETE, key); in transition_complete()
211 static int process_recheck(struct onoff_manager *mgr) in process_recheck() argument
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()
237 static void process_complete(struct onoff_manager *mgr, in process_complete() argument
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()
247 set_state(mgr, ONOFF_STATE_ERROR); 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()
263 set_state(mgr, ONOFF_STATE_ON); in process_complete()
267 set_state(mgr, ONOFF_STATE_OFF); in process_complete()
269 if (process_recheck(mgr) != EVT_NOP) { in process_complete()
270 mgr->flags |= ONOFF_FLAG_RECHECK; in process_complete()
278 set_state(mgr, ONOFF_STATE_OFF); in process_complete()
279 if (process_recheck(mgr) != EVT_NOP) { in process_complete()
280 mgr->flags |= ONOFF_FLAG_RECHECK; in process_complete()
298 static void process_event(struct onoff_manager *mgr, in process_event() argument
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()
329 evt = process_recheck(mgr); in process_event()
338 res = mgr->last_res; in process_event()
339 process_complete(mgr, &clients, 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()
347 set_state(mgr, ONOFF_STATE_TO_ON); in process_event()
350 __ASSERT_NO_MSG(mgr->refs == 0); in process_event()
352 transit = mgr->transitions->stop; in process_event()
354 set_state(mgr, ONOFF_STATE_TO_OFF); in process_event()
357 __ASSERT_NO_MSG(!sys_slist_is_empty(&mgr->clients)); in process_event()
359 transit = mgr->transitions->reset; in process_event()
361 set_state(mgr, ONOFF_STATE_RESETTING); 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()
386 notify_monitors(mgr, state, res); in process_event()
390 notify_all(mgr, &clients, state, res); in process_event()
394 transit(mgr, transition_complete); 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()
421 int onoff_request(struct onoff_manager *mgr, in onoff_request() argument
427 int rv = validate_args(mgr, cli); in onoff_request()
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()
446 mgr->refs += 1U; in onoff_request()
462 sys_slist_append(&mgr->clients, &cli->node); in onoff_request()
466 process_event(mgr, EVT_RECHECK, key); in onoff_request()
468 k_spin_unlock(&mgr->lock, key); in onoff_request()
471 notify_one(mgr, cli, state, 0); in onoff_request()
478 int onoff_release(struct onoff_manager *mgr) in onoff_release() argument
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()
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()
501 process_event(mgr, EVT_RECHECK, key); in onoff_release()
503 k_spin_unlock(&mgr->lock, key); in onoff_release()
509 int onoff_reset(struct onoff_manager *mgr, in onoff_reset() argument
513 int rv = validate_args(mgr, cli); in onoff_reset()
516 && (mgr->transitions->reset == NULL)) { 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()
533 sys_slist_append(&mgr->clients, &cli->node); in onoff_reset()
537 process_event(mgr, EVT_RECHECK, key); in onoff_reset()
539 k_spin_unlock(&mgr->lock, key); in onoff_reset()
545 int onoff_cancel(struct onoff_manager *mgr, in onoff_cancel() argument
548 if ((mgr == NULL) || (cli == NULL)) { 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()
568 int onoff_monitor_register(struct onoff_manager *mgr, in onoff_monitor_register() argument
571 if ((mgr == NULL) 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()
586 int onoff_monitor_unregister(struct onoff_manager *mgr, in onoff_monitor_unregister() argument
591 if ((mgr == NULL) 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()