File tree Expand file tree Collapse file tree 4 files changed +37
-11
lines changed Expand file tree Collapse file tree 4 files changed +37
-11
lines changed Original file line number Diff line number Diff line change 1
1
#pragma once
2
2
#include " fiber_cpp_define.hpp"
3
- #include < list >
3
+ #include < cstdlib >
4
4
#include < cassert>
5
+ #include < list>
5
6
6
7
struct ACL_FIBER_SEM ;
7
8
@@ -151,7 +152,7 @@ class fiber_sbox2 : public box2<T> {
151
152
, off_curr_(0 )
152
153
, off_next_(0 )
153
154
{
154
- box_ = (T*) malloc ( sizeof (T) * capacity_) ;
155
+ box_ = new T[ capacity_] ;
155
156
}
156
157
157
158
explicit fiber_sbox2 (int buf)
@@ -160,10 +161,10 @@ class fiber_sbox2 : public box2<T> {
160
161
, off_curr_(0 )
161
162
, off_next_(0 )
162
163
{
163
- box_ = (T*) malloc ( sizeof (T) * capacity_) ;
164
+ box_ = new T[ capacity_] ;
164
165
}
165
166
166
- ~fiber_sbox2 () {}
167
+ ~fiber_sbox2 () { delete [] box_; }
167
168
168
169
// @override
169
170
bool push (T t, bool dummy = false ) {
@@ -184,8 +185,18 @@ class fiber_sbox2 : public box2<T> {
184
185
off_next_ -= off_curr_;
185
186
off_curr_ = 0 ;
186
187
} else {
187
- capacity_ += 10000 ;
188
- box_ = (T*) realloc (box_, sizeof (T) * capacity_);
188
+ size_t capacity = capacity_ + 10000 ;
189
+ T* box = new T[capacity];
190
+ for (size_t i = 0 ; i < capacity_; i++) {
191
+ #if __cplusplus >= 201103L || defined(USE_CPP11)
192
+ box[i] = std::move (box_[i]);
193
+ #else
194
+ box[i] = box_[i];
195
+ #endif
196
+ }
197
+ delete [] box_;
198
+ box_ = box;
199
+ capacity_ = capacity;
189
200
}
190
201
}
191
202
box_[off_next_++] = t;
Original file line number Diff line number Diff line change @@ -49,10 +49,10 @@ template<typename T>
49
49
class fiber_tbox2 : public box2 <T> {
50
50
public:
51
51
fiber_tbox2 () : capacity_(10000 ) , off_curr_(0 ) , off_next_(0 ) {
52
- box_ = (T*) malloc ( sizeof (T) * capacity_) ;
52
+ box_ = new T[ capacity_] ;
53
53
}
54
54
55
- ~fiber_tbox2 () { free ( box_) ; }
55
+ ~fiber_tbox2 () { delete [] box_; }
56
56
57
57
/* *
58
58
* Clean up unconsumed messages in the message queue.
@@ -95,8 +95,19 @@ class fiber_tbox2 : public box2<T> {
95
95
off_next_ -= off_curr_;
96
96
off_curr_ = 0 ;
97
97
} else {
98
- capacity_ += 10000 ;
99
- box_ = (T*) realloc (box_, sizeof (T) * capacity_);
98
+ size_t capacity = capacity_ + 10000 ;
99
+ T* box = new T[capacity];
100
+ for (size_t i = 0 ; i < capacity_; i++) {
101
+ #if __cplusplus >= 201103L || defined(USE_CPP11)
102
+ box[i] = std::move (box_[i]);
103
+ #else
104
+ box[i] = box_[i];
105
+ #endif
106
+ }
107
+ delete [] box_;
108
+ box_ = box;
109
+ capacity_ = capacity;
110
+
100
111
}
101
112
}
102
113
#if __cplusplus >= 201103L || defined(USE_CPP11)
Original file line number Diff line number Diff line change 15
15
@ (cd client2; make)
16
16
@ (cd fiber_connect; make)
17
17
@ (cd fiber_tbox; make)
18
+ @ (cd fiber_box; make)
19
+ @ (cd fibers; make)
18
20
cl clean :
19
21
@ (cd fiber; make clean)
20
22
@ (cd httpd; make clean)
@@ -32,5 +34,7 @@ cl clean:
32
34
@ (cd client2; make clean)
33
35
@ (cd fiber_connect; make clean)
34
36
@ (cd fiber_tbox; make clean)
37
+ @ (cd fiber_box; make clean)
38
+ @ (cd fibers; make clean)
35
39
36
40
rb rebuild : clean all
Original file line number Diff line number Diff line change 1
1
CC = g++
2
2
3
3
CFLAGS = -c -g -W -Wall -Wcast-qual -Wcast-align \
4
- -Waggregate-return - Wno-long-long \
4
+ -Wno-long-long \
5
5
-Wpointer-arith -Werror -Wshadow -O3 \
6
6
-D_REENTRANT -D_POSIX_PTHREAD_SEMANTICS -D_USE_FAST_MACRO
7
7
You can’t perform that action at this time.
0 commit comments