libnuma/memories/
Memory.rs

1// This file is part of libnuma. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/libnuma/master/COPYRIGHT. No part of libnuma, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2// Copyright © 2016-2017 The developers of libnuma. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/libnuma/master/COPYRIGHT.
3
4
5pub trait Memory
6{
7	#[inline(always)]
8	fn wrap(address: *mut c_void, size: size_t) -> Self;
9	
10	#[inline(always)]
11	fn address(&self) -> *mut c_void;
12	
13	#[inline(always)]
14	fn size(&self) -> size_t;
15	
16	#[inline(always)]
17	fn is_null(&self) -> bool
18	{
19		self.address().is_null()
20	}
21	
22	#[inline(always)]
23	fn to_node(&self, node: NodeIndex)
24	{
25		unsafe { numa_tonode_memory(self.address(), self.size(), node.0 as c_int) }
26	}
27	
28	#[inline(always)]
29	fn set_local(&self)
30	{
31		unsafe { numa_setlocal_memory(self.address(), self.size()) }
32	}
33	
34	#[inline(always)]
35	fn police(&self)
36	{
37		unsafe { numa_police_memory(self.address(), self.size()) }
38	}
39	
40	//noinspection SpellCheckingInspection
41	fn bind(&self, nodes: &NodeMask, memory_policy: MemoryPolicy, flags: MovePagesFlags::Flags) -> Result<(), ErrorKind>
42	{
43		use ::std::io::ErrorKind::*;
44		
45		let bitmask = nodes.bitmask();
46		match unsafe { mbind(self.address(), self.size() as c_ulong, memory_policy as c_int, (*bitmask).maskp, (*bitmask).size, flags.bits()) }
47		{
48			0 => Ok(()),
49			-1 => match errno().0
50			{
51				::libc::EFAULT => panic!("Used an invalid address, an address not in this process or their was an unmapped hole in the length supplied"),
52				::libc::EINVAL => Err(InvalidInput),
53				::libc::EIO => Err(PermissionDenied),
54				::libc::ENOMEM => Err(Other),
55				::libc::EPERM => Err(PermissionDenied),
56				unexpected @ _ => panic!("Did not expect numa_move_pages to set errno {}", unexpected),
57			},
58			unexpected @ _ => panic!("Did not expect numa_move_pages to return {}", unexpected),
59		}
60	}
61}