33
44#include < algorithm>
55#include < span>
6+ #include < atomic>
67
78#include < klib/string.hpp>
89#include < klib/usb/usb/device.hpp>
@@ -606,8 +607,8 @@ namespace klib::usb::device {
606607 static inline volatile uint8_t alt_mode = 0x00 ;
607608
608609 // a non owning buffer to the data from the user
609- static inline const uint8_t * volatile buffer = nullptr ;
610- static inline volatile uint32_t bytes_to_transfer = 0 ;
610+ static inline std::atomic< const uint8_t *> buffer = nullptr ;
611+ static inline std::atomic< uint32_t > bytes_to_transfer = 0 ;
611612
612613 template <typename Usb>
613614 static usb::handshake set_current_impl (const klib::usb::setup_packet &packet) {
@@ -746,7 +747,7 @@ namespace klib::usb::device {
746747 }
747748
748749 // get the size we can transfer
749- const uint32_t size = klib::min (sizeof (video_buffer) - 2 , bytes_to_transfer);
750+ const uint32_t size = klib::min (sizeof (video_buffer) - 2 , bytes_to_transfer. load () );
750751
751752 // check if we have any data left to send
752753 if (!size) {
@@ -765,7 +766,7 @@ namespace klib::usb::device {
765766 }
766767
767768 // copy the new data to the buffer
768- std::copy_n (buffer, size, &video_buffer[2 ]);
769+ std::copy_n (buffer. load () , size, &video_buffer[2 ]);
769770
770771 // move the buffer with the size
771772 buffer += size;
0 commit comments