diff --git a/include/ircd/allocator.h b/include/ircd/allocator.h index 1be758520..6aa0907aa 100644 --- a/include/ircd/allocator.h +++ b/include/ircd/allocator.h @@ -403,60 +403,3 @@ struct ircd::allocator::node::allocator return &a == &b; } }; - -inline void -ircd::allocator::state::deallocate(const uint &pos, - const size_type &n) -{ - for(size_t i(0); i < n; ++i) - { - assert(test(pos + i)); - btc(pos + i); - } - - last = pos; -} - -inline uint -ircd::allocator::state::allocate(const size_type &n, - const uint &hint) -{ - const auto next(this->next(n)); - if(unlikely(next >= size)) // No block of n was found anywhere (next is past-the-end) - throw std::bad_alloc(); - - for(size_t i(0); i < n; ++i) - { - assert(!test(next + i)); - bts(next + i); - } - - last = next + n; - return next; -} - -inline uint -ircd::allocator::state::next(const size_t &n) -const -{ - uint ret(last), rem(n); - for(; ret < size && rem; ++ret) - if(test(ret)) - rem = n; - else - --rem; - - if(likely(!rem)) - return ret - n; - - for(ret = 0, rem = n; ret < last && rem; ++ret) - if(test(ret)) - rem = n; - else - --rem; - - if(unlikely(rem)) // The allocator should throw std::bad_alloc if !rem - return size; - - return ret - n; -} diff --git a/ircd/Makefile.am b/ircd/Makefile.am index cc9c750cc..6a23dc1dc 100644 --- a/ircd/Makefile.am +++ b/ircd/Makefile.am @@ -73,6 +73,7 @@ libircd_la_LIBADD = \ # systems. libircd_la_SOURCES = \ exception.cc \ + allocator.cc \ lexical.cc \ tokens.cc \ json.cc \ diff --git a/ircd/allocator.cc b/ircd/allocator.cc new file mode 100644 index 000000000..2a781b1a3 --- /dev/null +++ b/ircd/allocator.cc @@ -0,0 +1,66 @@ +// Matrix Construct +// +// Copyright (C) Matrix Construct Developers, Authors & Contributors +// Copyright (C) 2016-2018 Jason Volk +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice is present in all copies. The +// full license for this software is available in the LICENSE file. + +void +ircd::allocator::state::deallocate(const uint &pos, + const size_type &n) +{ + for(size_t i(0); i < n; ++i) + { + assert(test(pos + i)); + btc(pos + i); + } + + last = pos; +} + +uint +ircd::allocator::state::allocate(const size_type &n, + const uint &hint) +{ + const auto next(this->next(n)); + if(unlikely(next >= size)) // No block of n was found anywhere (next is past-the-end) + throw std::bad_alloc(); + + for(size_t i(0); i < n; ++i) + { + assert(!test(next + i)); + bts(next + i); + } + + last = next + n; + return next; +} + +uint +ircd::allocator::state::next(const size_t &n) +const +{ + uint ret(last), rem(n); + for(; ret < size && rem; ++ret) + if(test(ret)) + rem = n; + else + --rem; + + if(likely(!rem)) + return ret - n; + + for(ret = 0, rem = n; ret < last && rem; ++ret) + if(test(ret)) + rem = n; + else + --rem; + + if(unlikely(rem)) // The allocator should throw std::bad_alloc if !rem + return size; + + return ret - n; +}