mirror of
https://github.com/gnif/LookingGlass.git
synced 2025-05-17 12:01:18 +00:00
[common] added a sleep to the framebuffer spinlock and a sane timeout
This commit is contained in:
parent
82e0b7b6ab
commit
90d0cd873d
@ -24,8 +24,10 @@ Place, Suite 330, Boston, MA 02111-1307 USA
|
|||||||
#include <stdatomic.h>
|
#include <stdatomic.h>
|
||||||
#include <emmintrin.h>
|
#include <emmintrin.h>
|
||||||
#include <smmintrin.h>
|
#include <smmintrin.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#define FB_CHUNK_SIZE 1048576
|
#define FB_CHUNK_SIZE 1048576 // 1MB
|
||||||
|
#define FB_SPIN_LIMIT 10000 // 10ms
|
||||||
|
|
||||||
struct stFrameBuffer
|
struct stFrameBuffer
|
||||||
{
|
{
|
||||||
@ -40,7 +42,6 @@ void framebuffer_wait(const FrameBuffer * frame, size_t size)
|
|||||||
while(atomic_load_explicit(&frame->wp, memory_order_acquire) != size) {}
|
while(atomic_load_explicit(&frame->wp, memory_order_acquire) != size) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool framebuffer_read(const FrameBuffer * frame, void * restrict dst,
|
bool framebuffer_read(const FrameBuffer * frame, void * restrict dst,
|
||||||
size_t dstpitch, size_t height, size_t width, size_t bpp, size_t pitch)
|
size_t dstpitch, size_t height, size_t width, size_t bpp, size_t pitch)
|
||||||
{
|
{
|
||||||
@ -54,11 +55,18 @@ bool framebuffer_read(const FrameBuffer * frame, void * restrict dst,
|
|||||||
while(y < height)
|
while(y < height)
|
||||||
{
|
{
|
||||||
uint_least32_t wp;
|
uint_least32_t wp;
|
||||||
|
int spinCount = 0;
|
||||||
|
|
||||||
/* spinlock */
|
/* spinlock */
|
||||||
do
|
|
||||||
wp = atomic_load_explicit(&frame->wp, memory_order_acquire);
|
wp = atomic_load_explicit(&frame->wp, memory_order_acquire);
|
||||||
while(wp - rp < pitch);
|
while(wp - rp < linewidth)
|
||||||
|
{
|
||||||
|
if (++spinCount == FB_SPIN_LIMIT)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
usleep(1);
|
||||||
|
wp = atomic_load_explicit(&frame->wp, memory_order_acquire);
|
||||||
|
}
|
||||||
|
|
||||||
_mm_mfence();
|
_mm_mfence();
|
||||||
__m128i * restrict s = (__m128i *)(frame->data + rp);
|
__m128i * restrict s = (__m128i *)(frame->data + rp);
|
||||||
@ -104,11 +112,18 @@ bool framebuffer_read_fn(const FrameBuffer * frame, size_t height, size_t width,
|
|||||||
while(y < height)
|
while(y < height)
|
||||||
{
|
{
|
||||||
uint_least32_t wp;
|
uint_least32_t wp;
|
||||||
|
int spinCount = 0;
|
||||||
|
|
||||||
/* spinlock */
|
/* spinlock */
|
||||||
do
|
|
||||||
wp = atomic_load_explicit(&frame->wp, memory_order_acquire);
|
wp = atomic_load_explicit(&frame->wp, memory_order_acquire);
|
||||||
while(wp - rp < pitch);
|
while(wp - rp < linewidth)
|
||||||
|
{
|
||||||
|
if (++spinCount == FB_SPIN_LIMIT)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
usleep(1);
|
||||||
|
wp = atomic_load_explicit(&frame->wp, memory_order_acquire);
|
||||||
|
}
|
||||||
|
|
||||||
if (!fn(opaque, frame->data + rp, linewidth))
|
if (!fn(opaque, frame->data + rp, linewidth))
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user