From 5f7fed94b3ff74ede85ab9189221808543c4054b Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 11 Dec 2011 19:23:19 +0000 Subject: Align read buffer to page boundary if posix_memalign is available. git-svn-id: http://svn.drobilla.net/serd/trunk@240 490d8e77-9747-427b-9fa3-0b8f29cee8a0 --- src/reader.c | 9 ++++++++- wscript | 7 +++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/reader.c b/src/reader.c index d035448e..7c083dd6 100644 --- a/src/reader.c +++ b/src/reader.c @@ -14,6 +14,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#define _POSIX_C_SOURCE 201112L /* for posix_memalign */ + #include #include #include @@ -24,6 +26,7 @@ #include #include "serd_internal.h" +#include "serd-config.h" #define NS_XSD "http://www.w3.org/2001/XMLSchema#" #define NS_RDF "http://www.w3.org/1999/02/22-rdf-syntax-ns#" @@ -1530,11 +1533,15 @@ serd_reader_read_file_handle(SerdReader* me, FILE* file, const uint8_t* name) { const Cursor cur = { name, 1, 1 }; me->fd = file; - me->read_buf = (uint8_t*)malloc(READ_BUF_LEN * 2); me->read_head = 0; me->cur = cur; me->from_file = true; me->eof = false; +#ifdef HAVE_POSIX_MEMALIGN + posix_memalign((void**)&me->read_buf, 4096, READ_BUF_LEN * 2); +#else + me->read_buf = (uint8_t*)malloc(READ_BUF_LEN * 2); +#endif /* Read into the second page of the buffer. Occasionally peek_string will move the read_head to before this point when readahead causes diff --git a/wscript b/wscript index 928c9d6b..225b52b9 100644 --- a/wscript +++ b/wscript @@ -59,6 +59,13 @@ def configure(conf): if Options.options.largefile: conf.env.append_unique('CFLAGS', '-D_FILE_OFFSET_BITS=64') + # Check for posix_memalign + conf.check(function_name='posix_memalign', + header_name='stdlib.h', + define_name='HAVE_POSIX_MEMALIGN', + cflags='-D_POSIX_C_SOURCE=201112L', + mandatory=False) + autowaf.define(conf, 'SERD_VERSION', SERD_VERSION) conf.write_config_header('serd-config.h', remove=False) -- cgit v1.2.1