2 #include "../acl_cpp_define.hpp" 60 array_ = (T**) malloc(
sizeof(T*) * capacity_);
73 void clear(
bool free_obj =
false)
76 for (
size_t i = off_curr_; i < off_next_; i++) {
89 bool push(T* t,
bool notify_first =
false)
91 if (lock_.
lock() ==
false) {
95 if (off_next_ == capacity_) {
96 if (off_curr_ >= 10000) {
99 for (
size_t i = off_curr_; i < off_next_; i++) {
100 array_[n++] = array_[i];
103 memmove(array_, array_ + off_curr_,
104 (off_next_ - off_curr_) *
sizeof(T*));
107 off_next_ -= off_curr_;
111 array_ = (T**) realloc(array_,
sizeof(T*) * capacity_);
114 array_[off_next_++] = t;
117 if (cond_.
notify() ==
false) {
120 if (lock_.
unlock() ==
false) {
124 if (lock_.
unlock() ==
false) {
127 if (cond_.
notify() ==
false) {
148 T*
pop(
int wait_ms = -1,
bool* found = NULL)
150 long long n = ((
long long) wait_ms) * 1000;
153 if (lock_.
lock() ==
false) {
157 T* t = peek(found_flag);
159 if (lock_.
unlock() ==
false) {
170 if (!cond_.
wait(n,
true) && wait_ms >= 0) {
172 if (lock_.
unlock() ==
false) {
190 return off_next_ - off_curr_;
196 if (lock_.
lock() ==
false) {
203 if (lock_.
unlock() ==
false) {
218 T* peek(
bool& found_flag)
220 if (off_curr_ == off_next_) {
223 off_curr_ = off_next_ = 0;
229 T* t = array_[off_curr_++];
void clear(bool free_obj=false)
tbox_array(bool free_obj=true)
bool wait(long long microseconds=-1, bool locked=false)
bool push(T *t, bool notify_first=false)
T * pop(int wait_ms=-1, bool *found=NULL)