v01d commented on pull request #3155: URL: https://github.com/apache/incubator-nuttx/pull/3155#issuecomment-805829214
@cisvanmierlo If you could provide a companion PR including checkstate support it would be appreciated. > > @v01d @davids5 The enter_critical_section() function is located in the pm_changestate() function. > > Ok, so I guess that it is safe to be called anywhere then. > I can't really see why it should need to be called from IDLE loop either. > The only issue I can imagine is an interruption between checkstate and change state . Looking at, for example, nrf52_idle.c, we can see a critical section protecting the two calls to changestate as well as any PM calls. Would it be safe to use this from userspace without such a protection? I imagine it could result in some drivers changing state and not others (after first call, if some refused the change) and then an interruption is done before all drivers are reverted to previous state (using the second call). For clarification, I mean this code: ``` flags = enter_critical_section(); /* Perform board-specific, state-dependent logic here */ _info("newstate= %d oldstate=%d\n", newstate, oldstate); /* Then force the global state change */ ret = pm_changestate(PM_IDLE_DOMAIN, newstate); if (ret < 0) { /* The new state change failed, revert to the preceding state */ pm_changestate(PM_IDLE_DOMAIN, oldstate); } else { /* Save the new state */ oldstate = newstate; } ... ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org