* added circular index buffer implementation
This commit is contained in:
parent
d40052e24b
commit
cb1d5c7ab3
@ -28,7 +28,7 @@
|
|||||||
SubDir TOP core ;
|
SubDir TOP core ;
|
||||||
|
|
||||||
Module core : kernel_init.c sched.c mutex.c msg.c queue.c
|
Module core : kernel_init.c sched.c mutex.c msg.c queue.c
|
||||||
clist.c thread.c bitarithm.c ;
|
clist.c thread.c bitarithm.c cib.c ;
|
||||||
|
|
||||||
Module hwtimer : hwtimer.c : hwtimer_cpu ;
|
Module hwtimer : hwtimer.c : hwtimer_cpu ;
|
||||||
|
|
||||||
|
|||||||
47
core/cib.c
Normal file
47
core/cib.c
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
typedef struct cib {
|
||||||
|
unsigned int read_count;
|
||||||
|
unsigned int write_count;
|
||||||
|
unsigned int complement;
|
||||||
|
} cib_t;
|
||||||
|
|
||||||
|
void cib_init(cib_t *cib, unsigned int size) {
|
||||||
|
cib->read_count = 0;
|
||||||
|
cib->write_count = 0;
|
||||||
|
cib->complement = 0-size;
|
||||||
|
}
|
||||||
|
|
||||||
|
int cib_avail (cib_t *cib) {
|
||||||
|
return cib->write_count - cib->read_count;
|
||||||
|
}
|
||||||
|
|
||||||
|
int cib_get(cib_t *cib) {
|
||||||
|
int avail = cib_avail (cib);
|
||||||
|
|
||||||
|
if (avail > 0) {
|
||||||
|
return cib->read_count++ & ~cib->complement;
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int cib_put(cib_t *cib) {
|
||||||
|
int avail = cib_avail (cib);
|
||||||
|
|
||||||
|
if ((int)(avail + cib->complement) < 0 ) {
|
||||||
|
return cib->write_count++ & ~(cib->complement);
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
int main() {
|
||||||
|
cib_t cib;
|
||||||
|
|
||||||
|
cib_init(&cib, 0);
|
||||||
|
|
||||||
|
int res = cib_get(&cib);
|
||||||
|
|
||||||
|
printf("%i\n", res);
|
||||||
|
}
|
||||||
|
*/
|
||||||
15
core/include/cib.h
Normal file
15
core/include/cib.h
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#ifndef __CIB_H
|
||||||
|
#define __CIB_H
|
||||||
|
|
||||||
|
typedef struct cib_t {
|
||||||
|
unsigned int read_count;
|
||||||
|
unsigned int write_count;
|
||||||
|
unsigned int complement;
|
||||||
|
} cib_t;
|
||||||
|
|
||||||
|
void cib_init(cib_t *cib, unsigned int size);
|
||||||
|
int cib_get(cib_t *cib);
|
||||||
|
int cib_put(cib_t *cib);
|
||||||
|
int cib_avail(cib_t *cib);
|
||||||
|
|
||||||
|
#endif /* __CIB_H */
|
||||||
Loading…
x
Reference in New Issue
Block a user