-
Notifications
You must be signed in to change notification settings - Fork 87
Fix wrong allocation size of ringbuffer #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,8 +54,9 @@ typedef struct { | |
/* true if x is a power of 2 */ | ||
#define IS_POWEROF2(x) ((((x) -1) & (x)) == 0) | ||
#define RING_SIZE_MASK (unsigned) (0x0fffffff) /**< Ring size mask */ | ||
#define ALIGN_FLOOR(val, align) \ | ||
(typeof(val))((val) & (~((typeof(val))((align) -1)))) | ||
#define ALIGN_CEIL(val, align) \ | ||
(typeof(val))((val) + (-(typeof(val))(val) & ((align) -1))) | ||
|
||
|
||
/** | ||
* Calculate the memory size needed for a ring buffer. | ||
|
@@ -80,7 +81,7 @@ ssize_t ringbuf_get_memsize(const unsigned count) | |
return -EINVAL; | ||
|
||
ssize_t sz = sizeof(ringbuf_t) + count * sizeof(void *); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The right way is to mention the size, which is multiple of cache line size. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It will be alright to limit the size to the multiple of cache line size. But in this situation, I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @RinHizakura, you are right. |
||
sz = ALIGN_FLOOR(sz, CACHE_LINE_SIZE); | ||
sz = ALIGN_CEIL(sz, CACHE_LINE_SIZE); | ||
return sz; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check if this is what you want, thanks!