]> Git Repo - VerusCoin.git/blame - src/allocators.cpp
remove fields of ser_streamplaceholder
[VerusCoin.git] / src / allocators.cpp
CommitLineData
d8315d16
GA
1// Copyright (c) 2009-2013 The Bitcoin developers
2// Distributed under the MIT/X11 software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#include "allocators.h"
6
7#ifdef WIN32
8#ifdef _WIN32_WINNT
9#undef _WIN32_WINNT
10#endif
11#define _WIN32_WINNT 0x0501
12#define WIN32_LEAN_AND_MEAN 1
13#ifndef NOMINMAX
14#define NOMINMAX
15#endif
16#include <windows.h>
17// This is used to attempt to keep keying material out of swap
18// Note that VirtualLock does not provide this as a guarantee on Windows,
19// but, in practice, memory that has been VirtualLock'd almost never gets written to
20// the pagefile except in rare circumstances where memory is extremely low.
21#else
22#include <sys/mman.h>
23#include <limits.h> // for PAGESIZE
24#include <unistd.h> // for sysconf
25#endif
26
0b8f47dc
C
27LockedPageManager* LockedPageManager::_instance = NULL;
28boost::once_flag LockedPageManager::init_flag = BOOST_ONCE_INIT;
29
d8315d16
GA
30/** Determine system page size in bytes */
31static inline size_t GetSystemPageSize()
32{
33 size_t page_size;
34#if defined(WIN32)
35 SYSTEM_INFO sSysInfo;
36 GetSystemInfo(&sSysInfo);
37 page_size = sSysInfo.dwPageSize;
38#elif defined(PAGESIZE) // defined in limits.h
39 page_size = PAGESIZE;
40#else // assume some POSIX OS
41 page_size = sysconf(_SC_PAGESIZE);
42#endif
43 return page_size;
44}
45
46bool MemoryPageLocker::Lock(const void *addr, size_t len)
47{
48#ifdef WIN32
49 return VirtualLock(const_cast<void*>(addr), len);
50#else
51 return mlock(addr, len) == 0;
52#endif
53}
54
55bool MemoryPageLocker::Unlock(const void *addr, size_t len)
56{
57#ifdef WIN32
58 return VirtualUnlock(const_cast<void*>(addr), len);
59#else
60 return munlock(addr, len) == 0;
61#endif
62}
63
64LockedPageManager::LockedPageManager() : LockedPageManagerBase<MemoryPageLocker>(GetSystemPageSize())
65{
66}
67
This page took 0.073569 seconds and 4 git commands to generate.