This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Why can't I call pstorage functions from the callback?

I ran into an issue recently of attempting to make a pstorage_update call from the callback set in pstorage_register. It resulted in a difficult to track down error, so I'm posting the results here in case it helps someone else.

The symptoms of making the update request from the callback were that I sometimes saw data from a previous page written to the current page, although it did not do this consistently.

It's understandable that pstorage is not reentrant, although could be fixed.

  • It turns out that the update completion callback is made in a "halfway" state: the state machine state has been set back to STATE_INIT, but the current task (the update) hasn't been removed from the queue; so calling back runs the first step of the previous update (which is a copy of the old data to the swap page). When the callback returns, the previous task is removed from the queue and the next task to run is the second state of the new update.

    It is documented that "Module APIs are not thread-safe or re-entrant.", so this is definitely on me. It might be worth making them re-entrant (probably not).

  • do you solve this problem?? i'm same issue, pstorage_update don't work in callback function.? please help me.

Related