posix memalign is not supported
use standard memalign.
Signed-off-by: Amit Pundir <amit.pundir@linaro.org>
diff --git a/src/sat.cpp b/src/sat.cpp
index bed62b7..dab70dc 100644
--- a/src/sat.cpp
+++ b/src/sat.cpp
@@ -1271,10 +1271,15 @@
// Allocate all the nums once so that we get a single chunk
// of contiguous memory.
int *num;
+#if HAVE_POSIX_MEMALIGN
int err_result = posix_memalign(
reinterpret_cast<void**>(&num),
kCacheLineSize, sizeof(*num) * num_cpus * cc_cacheline_count_);
sat_assert(err_result == 0);
+#else
+ num = static_cast<int*>(memalign(kCacheLineSize, sizeof(*num) * num_cpus * cc_cacheline_count_));
+ sat_assert(num != NULL);
+#endif
int cline;
for (cline = 0; cline < cc_cacheline_count_; cline++) {
diff --git a/src/worker.cpp b/src/worker.cpp
index 2d61286..b219122 100644
--- a/src/worker.cpp
+++ b/src/worker.cpp
@@ -1791,6 +1791,7 @@
// Init a local buffer if we need it.
if (!page_io_) {
+#ifdef HAVE_POSIX_MEMALIGN
int result = posix_memalign(&local_page_, 512, sat_->page_length());
if (result) {
logprintf(0, "Process Error: disk thread posix_memalign "
@@ -1799,6 +1800,14 @@
status_ = false;
return false;
}
+#else
+ local_page_ = memalign(512, sat_->page_length());
+ if (!local_page_) {
+ logprintf(0, "Process Error: disk thread memalign failed.\n");
+ status_ = false;
+ return false;
+ }
+#endif
}
return true;
}
@@ -2358,6 +2367,7 @@
int64 loops = 0;
// Init a local buffer for storing data.
void *local_page = NULL;
+#ifdef HAVE_POSIX_MEMALIGN
int result = posix_memalign(&local_page, 512, sat_->page_length());
if (result) {
logprintf(0, "Process Error: net slave posix_memalign "
@@ -2366,6 +2376,14 @@
status_ = false;
return false;
}
+#else
+ local_page = memalign(512, sat_->page_length());
+ if (!local_page) {
+ logprintf(0, "Process Error: net slave memalign failed.\n");
+ status_ = false;
+ return false;
+ }
+#endif
struct page_entry page;
page.addr = local_page;
@@ -3105,6 +3123,7 @@
// Allocate a block buffer aligned to 512 bytes since the kernel requires it
// when using direst IO.
+#ifdef HAVE_POSIX_MEMALIGN
int memalign_result = posix_memalign(&block_buffer_, kBufferAlignment,
sat_->page_length());
if (memalign_result) {
@@ -3115,6 +3134,18 @@
status_ = false;
return false;
}
+#else
+ block_buffer_ = memalign(kBufferAlignment
+ sat_->page_length());
+ if (!block_buffer_) {
+ CloseDevice(fd);
+ logprintf(0, "Process Error: Unable to allocate memory for buffers "
+ "for disk %s (thread %d) memalign failed.\n",
+ device_name_.c_str(), thread_num_);
+ status_ = false;
+ return false;
+ }
+#endif
if (io_setup(5, &aio_ctx_)) {
CloseDevice(fd);