ringbuffer: alloc no less than 2 bytes.
This protects against race conditions. We can now preset the first two bytes which are used for size and flags by the COM module (currently the only user of the ringbuffer module).
This commit is contained in:
@@ -49,6 +49,9 @@ RingBuffer_Alloc:
|
||||
ldd r18, y+RINGBUFFER_OFFS_USED
|
||||
ldd r19, y+RINGBUFFER_OFFS_WRITEPOS
|
||||
|
||||
cpi r16, 2 ; alloc at least two bytes
|
||||
brcs RingBuffer_Alloc_error ; too few bytes
|
||||
|
||||
mov r20, r16 ; to_alloc
|
||||
add r20, r18 ; to_alloc + used
|
||||
cp r20, r17 ; new_used < max?
|
||||
@@ -70,7 +73,8 @@ RingBuffer_Alloc_l1:
|
||||
clr r17
|
||||
add yl, r16
|
||||
adc yh, r17
|
||||
st y+RINGBUFFER_OFFS_DATA, r17
|
||||
std y+RINGBUFFER_OFFS_DATA, r17 ; (length byte in COM module)
|
||||
std y+RINGBUFFER_OFFS_DATA+1, r17 ; (flags byte in COM module)
|
||||
pop yh
|
||||
pop yl
|
||||
|
||||
|
||||
Reference in New Issue
Block a user