static_mem_pool.cpp

Go to the documentation of this file.
00001 // -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
00002 // vim:tabstop=4:shiftwidth=4:expandtab:
00003 
00004 /*
00005  * Copyright (C) 2004-2006 Wu Yongwei <adah at users dot sourceforge dot net>
00006  *
00007  * This software is provided 'as-is', without any express or implied
00008  * warranty.  In no event will the authors be held liable for any
00009  * damages arising from the use of this software.
00010  *
00011  * Permission is granted to anyone to use this software for any purpose,
00012  * including commercial applications, and to alter it and redistribute
00013  * it freely, subject to the following restrictions:
00014  *
00015  * 1. The origin of this software must not be misrepresented; you must
00016  *    not claim that you wrote the original software. If you use this
00017  *    software in a product, an acknowledgment in the product
00018  *    documentation would be appreciated but is not required.
00019  * 2. Altered source versions must be plainly marked as such, and must
00020  *    not be misrepresented as being the original software.
00021  * 3. This notice may not be removed or altered from any source
00022  *    distribution.
00023  *
00024  * This file is part of Stones of Nvwa:
00025  *      http://sourceforge.net/projects/nvwa
00026  *
00027  */
00028 
00039 #include <algorithm>
00040 #include "cont_ptr_utils.h"
00041 #include "static_mem_pool.h"
00042 
00043 static_mem_pool_set::static_mem_pool_set()
00044 {
00045     _STATIC_MEM_POOL_TRACE(false, "The static_mem_pool_set is created");
00046 }
00047 
00048 static_mem_pool_set::~static_mem_pool_set()
00049 {
00050     std::for_each(_M_memory_pool_set.rbegin(),
00051                   _M_memory_pool_set.rend(),
00052                   delete_object());
00053     _STATIC_MEM_POOL_TRACE(false, "The static_mem_pool_set is destroyed");
00054 }
00055 
00061 static_mem_pool_set& static_mem_pool_set::instance()
00062 {
00063     lock __guard;
00064     static static_mem_pool_set _S_instance;
00065     return _S_instance;
00066 }
00067 
00073 void static_mem_pool_set::recycle()
00074 {
00075     _STATIC_MEM_POOL_TRACE(false, "Memory pools are being recycled");
00076     container_type::iterator __end = _M_memory_pool_set.end();
00077     for (container_type::iterator
00078             __i  = _M_memory_pool_set.begin();
00079             __i != __end; ++__i)
00080     {
00081         (*__i)->recycle();
00082     }
00083 }
00084 
00090 void static_mem_pool_set::add(mem_pool_base* __memory_pool_p)
00091 {
00092     lock __guard;
00093     _M_memory_pool_set.push_back(__memory_pool_p);
00094 }

Generated on Wed May 5 00:06:36 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6