annotate DEPENDENCIES/generic/include/boost/regex/v4/mem_block_cache.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents 2665513ce2d3
children
rev   line source
Chris@16 1 /*
Chris@16 2 * Copyright (c) 2002
Chris@16 3 * John Maddock
Chris@16 4 *
Chris@16 5 * Use, modification and distribution are subject to the
Chris@16 6 * Boost Software License, Version 1.0. (See accompanying file
Chris@16 7 * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Chris@16 8 *
Chris@16 9 */
Chris@16 10
Chris@16 11 /*
Chris@16 12 * LOCATION: see http://www.boost.org for most recent version.
Chris@16 13 * FILE mem_block_cache.hpp
Chris@16 14 * VERSION see <boost/version.hpp>
Chris@16 15 * DESCRIPTION: memory block cache used by the non-recursive matcher.
Chris@16 16 */
Chris@16 17
Chris@16 18 #ifndef BOOST_REGEX_V4_MEM_BLOCK_CACHE_HPP
Chris@16 19 #define BOOST_REGEX_V4_MEM_BLOCK_CACHE_HPP
Chris@16 20
Chris@16 21 #include <new>
Chris@16 22 #ifdef BOOST_HAS_THREADS
Chris@16 23 #include <boost/regex/pending/static_mutex.hpp>
Chris@16 24 #endif
Chris@16 25
Chris@16 26 #ifdef BOOST_HAS_ABI_HEADERS
Chris@16 27 # include BOOST_ABI_PREFIX
Chris@16 28 #endif
Chris@16 29
Chris@16 30 namespace boost{
Chris@16 31 namespace re_detail{
Chris@16 32
Chris@16 33 struct mem_block_node
Chris@16 34 {
Chris@16 35 mem_block_node* next;
Chris@16 36 };
Chris@16 37
Chris@16 38 struct mem_block_cache
Chris@16 39 {
Chris@16 40 // this member has to be statically initialsed:
Chris@16 41 mem_block_node* next;
Chris@16 42 unsigned cached_blocks;
Chris@16 43 #ifdef BOOST_HAS_THREADS
Chris@16 44 boost::static_mutex mut;
Chris@16 45 #endif
Chris@16 46
Chris@16 47 ~mem_block_cache()
Chris@16 48 {
Chris@16 49 while(next)
Chris@16 50 {
Chris@16 51 mem_block_node* old = next;
Chris@16 52 next = next->next;
Chris@16 53 ::operator delete(old);
Chris@16 54 }
Chris@16 55 }
Chris@16 56 void* get()
Chris@16 57 {
Chris@16 58 #ifdef BOOST_HAS_THREADS
Chris@16 59 boost::static_mutex::scoped_lock g(mut);
Chris@16 60 #endif
Chris@16 61 if(next)
Chris@16 62 {
Chris@16 63 mem_block_node* result = next;
Chris@16 64 next = next->next;
Chris@16 65 --cached_blocks;
Chris@16 66 return result;
Chris@16 67 }
Chris@16 68 return ::operator new(BOOST_REGEX_BLOCKSIZE);
Chris@16 69 }
Chris@16 70 void put(void* p)
Chris@16 71 {
Chris@16 72 #ifdef BOOST_HAS_THREADS
Chris@16 73 boost::static_mutex::scoped_lock g(mut);
Chris@16 74 #endif
Chris@16 75 if(cached_blocks >= BOOST_REGEX_MAX_CACHE_BLOCKS)
Chris@16 76 {
Chris@16 77 ::operator delete(p);
Chris@16 78 }
Chris@16 79 else
Chris@16 80 {
Chris@16 81 mem_block_node* old = static_cast<mem_block_node*>(p);
Chris@16 82 old->next = next;
Chris@16 83 next = old;
Chris@16 84 ++cached_blocks;
Chris@16 85 }
Chris@16 86 }
Chris@16 87 };
Chris@16 88
Chris@16 89 extern mem_block_cache block_cache;
Chris@16 90
Chris@16 91 }
Chris@16 92 } // namespace boost
Chris@16 93
Chris@16 94 #ifdef BOOST_HAS_ABI_HEADERS
Chris@16 95 # include BOOST_ABI_SUFFIX
Chris@16 96 #endif
Chris@16 97
Chris@16 98 #endif
Chris@16 99