From d15f18113bf4a7fbe9758d50623d65dc42b452a9 Mon Sep 17 00:00:00 2001 From: cnlohr Date: Mon, 21 May 2018 12:51:18 -0400 Subject: [PATCH] Use semaphores for better performance. --- colorchord2/DisplayFileWrite.c | 11 +++++------ colorchord2/keyboard_rgb_test.conf | 4 ++-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/colorchord2/DisplayFileWrite.c b/colorchord2/DisplayFileWrite.c index 915a259..ed1e2ce 100644 --- a/colorchord2/DisplayFileWrite.c +++ b/colorchord2/DisplayFileWrite.c @@ -28,8 +28,8 @@ struct FileWriteDriver int file_thread_usleep; int asynchronous; uint32_t pass_buffer[MAX_LEDS]; - volatile int flagchanges; og_thread_t rt_thread; + og_sema_t rt_sema; }; static void * LightsWrite( void * v ) @@ -37,9 +37,7 @@ static void * LightsWrite( void * v ) struct FileWriteDriver * d = (struct FileWriteDriver *)v; while(1) { - usleep( d->file_thread_usleep ); - if( !d->flagchanges ) continue; - d->flagchanges = 0; + OGLockSema( d->rt_sema ); if( d->lights_file > 0 ) { int btos = ((d->inflate_to_u32)?4:3)*d->total_leds; @@ -75,7 +73,7 @@ static void FileWriteUpdate(void * id, struct NoteFinder*nf) { struct FileWriteDriver * d = (struct FileWriteDriver*)id; - + if( OGGetSema( d->rt_sema ) > 0 ) return; if( !d->inflate_to_u32 ) { memcpy( d->pass_buffer, OutLEDs, d->total_leds*3 ); @@ -89,7 +87,7 @@ static void FileWriteUpdate(void * id, struct NoteFinder*nf) d->pass_buffer[i] = ol[0] | (ol[1]<<8) | (ol[2]<<16) | 0xff000000; } } - d->flagchanges = 1; + OGUnlockSema( d->rt_sema ); } @@ -112,6 +110,7 @@ static struct DriverInstances * DisplayFileWrite(const char * parameters) ret->Params = FileWriteParams; FileWriteParams( d ); printf( "Loaded DisplayFileWrite\n" ); + d->rt_sema = OGCreateSema(); d->rt_thread = OGCreateThread( LightsWrite, d ); return ret; } diff --git a/colorchord2/keyboard_rgb_test.conf b/colorchord2/keyboard_rgb_test.conf index 0fcdfdc..4d48d5d 100644 --- a/colorchord2/keyboard_rgb_test.conf +++ b/colorchord2/keyboard_rgb_test.conf @@ -1,9 +1,9 @@ # This is the keyboard test for Clevo and PowerSpec 1510 and 1710 laptops, using the kernel module found here: # https://github.com/cnlohr/clevo_xsm_wmi +cpu_autolimit_interval=.002 cpu_autolimit = 1 -headless=0 - +headless=1 octaves = 5 base_hz = 82.406889228