diff options
author | Bjoern Michaelsen <bjoern.michaelsen@canonical.com> | 2016-04-07 01:32:05 +0200 |
---|---|---|
committer | Michael Meeks <michael.meeks@collabora.com> | 2016-04-07 08:39:51 +0000 |
commit | 71aa80300c89c726254049f775d1c48518b6dfe4 (patch) | |
tree | 84482e7915d19ee38dbd30487aaf8060b775fee9 /desktop/unx | |
parent | b8454666ec08cab835af56ba473843397052156a (diff) |
refactor pagein, as it still seems to cause rare crashes
Change-Id: I51e6cdf79c19c3709e00dc10175527ec6583a758
Reviewed-on: https://gerrit.libreoffice.org/23872
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
Tested-by: Michael Meeks <michael.meeks@collabora.com>
Diffstat (limited to 'desktop/unx')
-rw-r--r-- | desktop/unx/source/file_image_unx.c | 30 |
1 files changed, 11 insertions, 19 deletions
diff --git a/desktop/unx/source/file_image_unx.c b/desktop/unx/source/file_image_unx.c index 522c49171f49..ec229f95ff98 100644 --- a/desktop/unx/source/file_image_unx.c +++ b/desktop/unx/source/file_image_unx.c @@ -74,37 +74,29 @@ cleanup_and_leave: */ int file_image_pagein (file_image * image) { - file_image w; - long s; - size_t k; - // force touching of each page despite the optimizer + long s = -1; volatile char c =0; + size_t idx; if (image == NULL) return EINVAL; - - if ((w.m_base = image->m_base) == NULL) + if (image->m_base == NULL) return EINVAL; - if ((w.m_size = image->m_size) == 0) + if (image->m_size == 0) return 0; - if (madvise (w.m_base, w.m_size, MADV_WILLNEED) == -1) + if (madvise (image->m_base, image->m_size, MADV_WILLNEED) == -1) return errno; - if ((s = sysconf (_SC_PAGESIZE)) == -1) + s = sysconf (_SC_PAGESIZE); + if (s == -1) s = 0x1000; - - k = (size_t)(s); - while (w.m_size > k) - { - c ^= ((char*)(w.m_base))[0]; - w.m_base = (char*)(w.m_base) + k; - w.m_size -= k; - } - if (w.m_size > 0) + // force touching of each page despite the optimizer + for(idx = 0; idx < image->m_size; idx += (size_t)s) { - c ^= ((char*)(w.m_base))[0]; + c ^= ((volatile const char*)(image->m_base))[idx]; } + c ^= ((volatile const char*)(image->m_base))[image->m_size-1]; return 0; } |