Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To use the export_admin_counter, a process that might get bad results due
- * to an in progress export update should save the export_admin_counter as
- * start_export_admin_counter before executing the code that could be confused.
- * The after the code is complete, the code can call
- * is_export_admin_counter_valid(start_export_admin_counter) to determine if
- * and export update might have upended things.
- *
- * Depending on how the code functions, it may only need to perform this check
- * if an unexpected result occurred. On the other hand the check is cheap, while
- * a false negative is possible, that still requires the code have been
- * executing parallel with an export update which are expected to be extremely
- * rare so even if the code catches a half-updated counter (due to NOT using
- * atomics) it just results in a false negative.
- */
- static inline
- bool is_export_admin_counter_valid(uint64_t start_export_admin_counter)
- {
- return (start_export_admin_counter % 2) == 0 &&
- start_export_admin_counter == export_admin_counter;
- }
- /**
- * @brief Simple check if an export update is in progress
- *
- * If code uses locks in a way that guarantee that an export update can not
- * upset their world while the code is executing then a simple check after
- * failure that an update is in progress (seqlock value is odd) is sufficient.
- * For example, code implementing a lookup in a pseudo fs where lookup holds a
- * lock that prevents the update from changing the pseudo fs while the lookup
- * in in progress means that any update that will upset this lookups apple cart
- * can not start AND end while the lookup is in progress.
- */
- static inline bool is_export_update_in_progress(void)
- {
- return (export_admin_counter % 2) != 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement