LCOV - code coverage report
Current view: top level - memory_manager - manager.cpp (source / functions) Hit Total Coverage
Test: CoherentDB code coverage Lines: 17 22 77.3 %
Date: 2011-02-13 Functions: 6 8 75.0 %

          Line data    Source code
       1             : /*
       2             :  * (C) Copyright 2010 Xilexio
       3             :  * 
       4             :  * This file is part of CoherentDB.
       5             :  * 
       6             :  * CoherentDB is free software: you can redistribute it and/or modify it
       7             :  * under the terms of the GNU General Public License as published by
       8             :  * the Free Software Foundation, either version 3 of the License, or
       9             :  * (at your option) any later version.
      10             :  * 
      11             :  * CoherentDB is distributed in the hope that it will be useful, but
      12             :  * WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
      14             :  * General Public License for more details.
      15             :  * 
      16             :  * You should have received a copy of the GNU General Public
      17             :  * License along with CoherentDB. If not, see
      18             :  * http://www.gnu.org/licenses/.
      19             :  */
      20             : 
      21             : #include <unistd.h>
      22             : #include <memory_manager/manager.h>
      23             : #include <debug/asserts.h>
      24             : #include <config/config.h>
      25             : 
      26             : namespace coherent
      27             : {
      28             : namespace memory_manager
      29             : {
      30             : 
      31           0 : const char* out_of_total_memory::what() const throw ()
      32             : {
      33           0 :     return "Insufficent total memory left for memory reservation.";
      34             : }
      35             : 
      36             : memory_manager* memory_manager::instance = 0;
      37             : 
      38           0 : memory_manager::~memory_manager()
      39             : {
      40           0 : }
      41             : 
      42           8 : void memory_manager::reserve_bytes(size_t bytes)
      43             : {
      44          16 :     boost::mutex::scoped_lock rm(reserved_bytes_mutex);
      45             : 
      46           8 :     if (reserved_bytes + bytes > limit_bytes)
      47           0 :         throw out_of_total_memory();
      48             : 
      49           8 :     reserved_bytes += bytes;
      50           8 : }
      51             : 
      52           8 : void memory_manager::free_bytes(size_t bytes)
      53             : {
      54          16 :     boost::mutex::scoped_lock rm(reserved_bytes_mutex);
      55             : 
      56             :     d_assert(bytes <= reserved_bytes);
      57             : 
      58           8 :     reserved_bytes -= bytes;
      59           8 : }
      60             : 
      61           1 : void memory_manager::init(const config::global_config& conf)
      62             : {
      63             :     d_assert(!instance);
      64             : 
      65           1 :     instance = new memory_manager(conf);
      66           1 : }
      67             : 
      68           1 : memory_manager::memory_manager(const config::global_config& conf) :
      69           1 : reserved_bytes(0), limit_bytes(conf.memory_manager.initialLimitBytes), default_session_limit_bytes(conf.memory_manager.defaultSessionLimitBytes)
      70             : {
      71           1 :     page_size = sysconf(_SC_PAGESIZE);
      72           1 : }
      73             : 
      74             : }
      75           3 : }

Generated by: LCOV version 1.9