diff options
author | Jean-Francois Mauguit <jfmauguit@mac.com> | 2024-09-24 09:03:25 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-24 09:03:25 -0400 |
commit | bab614c421ed7ae329d26bf028c4a3b1d2450f5a (patch) | |
tree | 12f17f78986871dd2cfb0a56e5e93b545c1ae0d0 /Src/replicant/nu/win/MessageLoop.h | |
parent | 4bde6044fddf053f31795b9eaccdd2a5a527d21f (diff) | |
parent | 20d28e80a5c861a9d5f449ea911ab75b4f37ad0d (diff) | |
download | winamp-bab614c421ed7ae329d26bf028c4a3b1d2450f5a.tar.gz |
Merge pull request #5 from WinampDesktop/community
Merge to main
Diffstat (limited to 'Src/replicant/nu/win/MessageLoop.h')
-rw-r--r-- | Src/replicant/nu/win/MessageLoop.h | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/Src/replicant/nu/win/MessageLoop.h b/Src/replicant/nu/win/MessageLoop.h new file mode 100644 index 00000000..88e4520f --- /dev/null +++ b/Src/replicant/nu/win/MessageLoop.h @@ -0,0 +1,45 @@ +#pragma once +#include "foundation/types.h" +#include "nu/lfmpscq.h" +#include "nu/LockFreeLIFO.h" +#include <windows.h> + +namespace nu +{ + + /* you can inherit from message_node_t (or combine inside a struct) + but make sure that your message isn't > 64 bytes */ + struct message_node_t : public queue_node_t + { + uint32_t message; + }; + + class MessageLoop + { + public: + MessageLoop(); + ~MessageLoop(); + /* API for Message senders */ + message_node_t *AllocateMessage(); // returns a message for you to fill out + void PostMessage(message_node_t *message); + + /* API for Message receivers */ + void FreeMessage(message_node_t *message); + message_node_t *GetMessage(); // waits forever + message_node_t *PeekMessage(); + message_node_t *PeekMessage(unsigned int milliseconds); + private: + void RefillCache(); + + HANDLE message_notification; + mpscq_t message_queue; + + /* Memory cache to be able to run APCs without having the memory manager lock + we'll allocate 100 at a time (#defined by MESSAGE_CACHE_SEED) + and allocate new ones only if the cache is empty (which unfortunately will lock) + cache_bases holds the pointers we've allocated (to free on destruction of this object) + and message_cache holds the individual pointers */ + static lifo_t message_cache; + static lifo_t cache_bases; + }; +}
\ No newline at end of file |