diff options
| author | Michal Idziorek <m.i@gmx.at> | 2014-11-26 23:17:55 +0100 |
|---|---|---|
| committer | Michal Idziorek <m.i@gmx.at> | 2014-11-26 23:17:55 +0100 |
| commit | 7393db6692c861bc66164c0dd9b83f23a554775b (patch) | |
| tree | d60c9deb33630d5fb6117c7c1bbc098e62a66f28 /lib | |
| parent | 9c8cfc2e52b0446f7cab14325028075760869b45 (diff) | |
changes, improvements and cleanup
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/bool/bool.h | 2 | ||||
| -rw-r--r-- | lib/buffer/ringbuffer.c | 43 | ||||
| -rw-r--r-- | lib/buffer/ringbuffer.h | 4 | ||||
| -rw-r--r-- | lib/int/stdint.h | 2 | ||||
| -rw-r--r-- | lib/string/string.c | 2 |
5 files changed, 32 insertions, 21 deletions
diff --git a/lib/bool/bool.h b/lib/bool/bool.h index be2cbd4..c2c6171 100644 --- a/lib/bool/bool.h +++ b/lib/bool/bool.h @@ -1,6 +1,8 @@ +/* #include "lib/int/stdint.h" #define false 0 #define true !false #define bool uint8_t +*/ diff --git a/lib/buffer/ringbuffer.c b/lib/buffer/ringbuffer.c index dcf7bc2..a121df1 100644 --- a/lib/buffer/ringbuffer.c +++ b/lib/buffer/ringbuffer.c @@ -4,27 +4,32 @@ #define FOOLOS_MODULE_NAME "ringbuffer" -#include "lib/bool/bool.h" +#include "ringbuffer.h" +#include "kernel/x86.h" #include "lib/logger/log.h" #include "kernel/spinlock.h" #define RINGBUFFER_SIZE 10 -static volatile int size=RINGBUFFER_SIZE; +static int size=RINGBUFFER_SIZE; static volatile int front=RINGBUFFER_SIZE-1; static volatile int back=RINGBUFFER_SIZE-1; static volatile char buf[RINGBUFFER_SIZE]; +static spinlock sl=9; + bool ringbuffer_put(char c) { - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"put wants lock)"); - lock_spin(3); - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"locked by put)"); + x86_int_disable(); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"put wants lock"); + lock_spin(sl); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"locked by put"); if((back-1+size)%size==front) { - lock_release(3); - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"unlocked by put)"); + lock_release(sl); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"unlocked by put"); + x86_int_enable(); return false; } @@ -34,22 +39,25 @@ bool ringbuffer_put(char c) back+=size; back%=size; - lock_release(3); - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"unlocked by put)"); + lock_release(sl); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"unlocked by put"); + x86_int_enable(); return true; } bool ringbuffer_get(char *c) { - - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"get wants lock)"); - lock_spin(3); - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"locked by get)"); + x86_int_disable(); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"get wants lock"); + lock_spin(sl); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"locked by get"); if(front==back) { - lock_release(3); - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"unlocked by get)"); + lock_release(sl); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"unlocked by get"); + x86_int_enable(); + *c='_'; return false; } @@ -60,8 +68,9 @@ bool ringbuffer_get(char *c) front+=size; front%=size; - lock_release(3); - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"unlocked by get)"); + lock_release(sl); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"unlocked by get"); + x86_int_enable(); return true; } diff --git a/lib/buffer/ringbuffer.h b/lib/buffer/ringbuffer.h index 2bb6528..038e33a 100644 --- a/lib/buffer/ringbuffer.h +++ b/lib/buffer/ringbuffer.h @@ -1,5 +1,3 @@ -#include "lib/bool/bool.h" - -void ringbuffer_init(); +#include <stdbool.h> bool ringbuffer_put(char c); bool ringbuffer_get(char *c); diff --git a/lib/int/stdint.h b/lib/int/stdint.h index 38b7040..f2b975f 100644 --- a/lib/int/stdint.h +++ b/lib/int/stdint.h @@ -1,3 +1,5 @@ +/* #include <stdint.h> +*/ diff --git a/lib/string/string.c b/lib/string/string.c index 9f58c43..d5c27f7 100644 --- a/lib/string/string.c +++ b/lib/string/string.c @@ -1,4 +1,4 @@ -#include "lib/bool/bool.h" +#include <stdbool.h> //length 0 for null terminated strings; bool strcmp(char *str1, char *str2, int length) |
