Last active
November 4, 2025 05:41
-
-
Save akihikodaki/8e6cbe3a94f731602cba9ab6ed3a719f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| static inline void qemu_futex_wait(Futex *f, unsigned val) | |
| { | |
| push(f->targets); | |
| if (f->val == val) { | |
| _lwp_park(f); | |
| } | |
| } | |
| static inline void qemu_futex_wake_all(Futex *f) | |
| { | |
| _lwp_unpark_all(move(f->targets), f->val); | |
| } | |
| static inline void qemu_futex_post_wake(Futex *f) | |
| { | |
| if (!f->refs--) { | |
| free(f); | |
| } | |
| } | |
| static inline void qemu_futex_ref(Futex *f) | |
| { | |
| f->refs++; | |
| } | |
| static inline void qemu_futex_unref(Futex *f) | |
| { | |
| if (!f->refs--) { | |
| free(f); | |
| } | |
| } | |
| init(f) { | |
| qemu_futex_ref(f); | |
| } | |
| wake(f) { | |
| qemu_futex_ref(f); | |
| if (xchg(&f->val, SET) == BUSY) { | |
| qemu_futex_wake_all(f); | |
| } | |
| qemu_futex_unref(f); | |
| } | |
| wait(f) { | |
| f->val = BUSY; | |
| qemu_futex_wait(f, BUSY); | |
| } | |
| destroy(f) { | |
| qemu_futex_unref(f); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment