3 |
* LinuxSampler - modular, streaming capable sampler * |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
* * |
5 |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
6 |
* Copyright (C) 2005 - 2017 Christian Schoenebeck * |
* Copyright (C) 2005 - 2019 Christian Schoenebeck * |
7 |
* * |
* * |
8 |
* This program is free software; you can redistribute it and/or modify * |
* This program is free software; you can redistribute it and/or modify * |
9 |
* it under the terms of the GNU General Public License as published by * |
* it under the terms of the GNU General Public License as published by * |
38 |
# include <string> |
# include <string> |
39 |
#endif // CONFIG_RT_EXCEPTIONS |
#endif // CONFIG_RT_EXCEPTIONS |
40 |
|
|
41 |
|
#include <iostream> |
42 |
|
|
43 |
#if CONFIG_DEVMODE |
#if CONFIG_DEVMODE |
44 |
# include <string> |
# include <string> |
45 |
# include <iostream> |
# include <stdexcept> |
46 |
const std::string __err_msg_iterator_invalidated = "Pool/RTList iterator invalidated"; |
const std::string __err_msg_iterator_invalidated = "Pool/RTList iterator invalidated"; |
47 |
#endif // CONFIG_DEVMODE |
#endif // CONFIG_DEVMODE |
48 |
|
|
541 |
src->prev = prev; |
src->prev = prev; |
542 |
src->next = dst; |
src->next = dst; |
543 |
#if CONFIG_DEVMODE |
#if CONFIG_DEVMODE |
544 |
src->list = this; |
src->list = dst->list; |
545 |
#endif // CONFIG_DEVMODE |
#endif // CONFIG_DEVMODE |
546 |
} |
} |
547 |
|
|
554 |
src->prev = dst; |
src->prev = dst; |
555 |
src->next = next; |
src->next = next; |
556 |
#if CONFIG_DEVMODE |
#if CONFIG_DEVMODE |
557 |
src->list = this; |
src->list = dst->list; |
558 |
#endif // CONFIG_DEVMODE |
#endif // CONFIG_DEVMODE |
559 |
} |
} |
560 |
|
|
628 |
inline Iterator allocPrepend() { |
inline Iterator allocPrepend() { |
629 |
if (pPool->poolIsEmpty()) return RTListBase<T>::end(); |
if (pPool->poolIsEmpty()) return RTListBase<T>::end(); |
630 |
Iterator element = pPool->alloc(); |
Iterator element = pPool->alloc(); |
631 |
prepend(element); |
this->prepend(element); |
632 |
#if CONFIG_DEVMODE |
#if CONFIG_DEVMODE |
633 |
element.list = this; |
element.list = this; |
634 |
#endif // CONFIG_DEVMODE |
#endif // CONFIG_DEVMODE |
694 |
if (data) delete[] data; |
if (data) delete[] data; |
695 |
} |
} |
696 |
|
|
697 |
|
/** |
698 |
|
* Returns true if there is at least one free element that could be |
699 |
|
* allocated from the pool with i.e. allocAppend() or allocPreprend(). |
700 |
|
* |
701 |
|
* @see poolHasFreeElements() |
702 |
|
*/ |
703 |
inline bool poolIsEmpty() const { |
inline bool poolIsEmpty() const { |
704 |
return freelist.isEmpty(); |
return freelist.isEmpty(); |
705 |
} |
} |
706 |
|
|
707 |
/** |
/** |
708 |
|
* Returns true if at least the requested amount of free @a elements is |
709 |
|
* currently available for being allocated from the pool with i.e. |
710 |
|
* allocAppend() or allocPreprend(). |
711 |
|
* |
712 |
|
* @see poolIsEmpty() |
713 |
|
*/ |
714 |
|
bool poolHasFreeElements(int elements) { |
715 |
|
for (Iterator it = freelist.first(); it != freelist.end() && elements >= 0; ++it) |
716 |
|
--elements; |
717 |
|
return elements <= 0; |
718 |
|
} |
719 |
|
|
720 |
|
int countFreeElements() { |
721 |
|
return freelist.count(); |
722 |
|
} |
723 |
|
|
724 |
|
/** |
725 |
* Returns the current size of the pool, that is the amount of |
* Returns the current size of the pool, that is the amount of |
726 |
* pre-allocated elements from the operating system. It equals the |
* pre-allocated elements from the operating system. It equals the |
727 |
* amount of elements given to the constructor unless resizePool() |
* amount of elements given to the constructor unless resizePool() |