Electroneum
epee::mlocker Class Reference

#include <mlocker.h>

Public Member Functions

 mlocker (void *ptr, size_t len)
 
 ~mlocker ()
 

Static Public Member Functions

static size_t get_page_size ()
 
static size_t get_num_locked_pages ()
 
static size_t get_num_locked_objects ()
 
static void lock (void *ptr, size_t len)
 
static void unlock (void *ptr, size_t len)
 

Detailed Description

Definition at line 36 of file mlocker.h.

Constructor & Destructor Documentation

◆ mlocker()

epee::mlocker::mlocker ( void *  ptr,
size_t  len 
)

Definition at line 115 of file mlocker.cpp.

115  : ptr(ptr), len(len)
116  {
117  lock(ptr, len);
118  }
static void lock(void *ptr, size_t len)
Definition: mlocker.cpp:126
Here is the call graph for this function:

◆ ~mlocker()

epee::mlocker::~mlocker ( )

Definition at line 120 of file mlocker.cpp.

121  {
122  try { unlock(ptr, len); }
123  catch (...) { /* ignore and do not propagate through the dtor */ }
124  }
static void unlock(void *ptr, size_t len)
Definition: mlocker.cpp:144
Here is the call graph for this function:

Member Function Documentation

◆ get_num_locked_objects()

size_t epee::mlocker::get_num_locked_objects ( )
static

Definition at line 167 of file mlocker.cpp.

168  {
169  CRITICAL_REGION_LOCAL(mutex());
170  return num_locked_objects;
171  }
#define CRITICAL_REGION_LOCAL(x)
Definition: syncobj.h:228

◆ get_num_locked_pages()

size_t epee::mlocker::get_num_locked_pages ( )
static

Definition at line 161 of file mlocker.cpp.

162  {
163  CRITICAL_REGION_LOCAL(mutex());
164  return map().size();
165  }
#define CRITICAL_REGION_LOCAL(x)
Definition: syncobj.h:228

◆ get_page_size()

size_t epee::mlocker::get_page_size ( )
static

Definition at line 107 of file mlocker.cpp.

108  {
109  CRITICAL_REGION_LOCAL(mutex());
110  if (page_size == 0)
111  page_size = query_page_size();
112  return page_size;
113  }
#define CRITICAL_REGION_LOCAL(x)
Definition: syncobj.h:228
Here is the caller graph for this function:

◆ lock()

void epee::mlocker::lock ( void *  ptr,
size_t  len 
)
static

Definition at line 126 of file mlocker.cpp.

127  {
128  TRY_ENTRY();
129 
130  size_t page_size = get_page_size();
131  if (page_size == 0)
132  return;
133 
134  CRITICAL_REGION_LOCAL(mutex());
135  const size_t first = ((uintptr_t)ptr) / page_size;
136  const size_t last = (((uintptr_t)ptr) + len - 1) / page_size;
137  for (size_t page = first; page <= last; ++page)
138  lock_page(page);
139  ++num_locked_objects;
140 
141  CATCH_ENTRY_L1("mlocker::lock", void());
142  }
static size_t get_page_size()
Definition: mlocker.cpp:107
#define TRY_ENTRY()
Definition: misc_log_ex.h:151
_W64 unsigned int uintptr_t
Definition: stdint.h:165
#define CRITICAL_REGION_LOCAL(x)
Definition: syncobj.h:228
#define CATCH_ENTRY_L1(lacation, return_val)
Definition: misc_log_ex.h:166
Here is the call graph for this function:
Here is the caller graph for this function:

◆ unlock()

void epee::mlocker::unlock ( void *  ptr,
size_t  len 
)
static

Definition at line 144 of file mlocker.cpp.

145  {
146  TRY_ENTRY();
147 
148  size_t page_size = get_page_size();
149  if (page_size == 0)
150  return;
151  CRITICAL_REGION_LOCAL(mutex());
152  const size_t first = ((uintptr_t)ptr) / page_size;
153  const size_t last = (((uintptr_t)ptr) + len - 1) / page_size;
154  for (size_t page = first; page <= last; ++page)
155  unlock_page(page);
156  --num_locked_objects;
157 
158  CATCH_ENTRY_L1("mlocker::lock", void());
159  }
static size_t get_page_size()
Definition: mlocker.cpp:107
#define TRY_ENTRY()
Definition: misc_log_ex.h:151
_W64 unsigned int uintptr_t
Definition: stdint.h:165
#define CRITICAL_REGION_LOCAL(x)
Definition: syncobj.h:228
#define CATCH_ENTRY_L1(lacation, return_val)
Definition: misc_log_ex.h:166
Here is the call graph for this function:
Here is the caller graph for this function:

The documentation for this class was generated from the following files: