1 //===-- tsan_vector.h -------------------------------------------*- C++ -*-===//
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
6 //===----------------------------------------------------------------------===//
8 // This file is a part of ThreadSanitizer (TSan), a race detector.
10 //===----------------------------------------------------------------------===//
12 // Low-fat STL-like vector container.
17 #include "tsan_defs.h"
18 #include "tsan_mman.h"
25 explicit Vector(MBlockType typ
)
34 internal_free(begin_
);
39 internal_free(begin_
);
49 T
&operator[](uptr i
) {
50 DCHECK_LT(i
, end_
- begin_
);
54 const T
&operator[](uptr i
) const {
55 DCHECK_LT(i
, end_
- begin_
);
59 T
*PushBack(T v
= T()) {
60 EnsureSize(Size() + 1);
66 DCHECK_GT(end_
, begin_
);
70 void Resize(uptr size
) {
71 uptr old_size
= Size();
73 if (old_size
< size
) {
74 for (uptr i
= old_size
; i
< size
; i
++)
80 const MBlockType typ_
;
85 void EnsureSize(uptr size
) {
88 if (size
<= (uptr
)(last_
- begin_
)) {
92 uptr cap0
= last_
- begin_
;
98 T
*p
= (T
*)internal_alloc(typ_
, cap
* sizeof(T
));
100 internal_memcpy(p
, begin_
, cap0
* sizeof(T
));
101 internal_free(begin_
);
104 end_
= begin_
+ size
;
105 last_
= begin_
+ cap
;
108 Vector(const Vector
&);
109 void operator=(const Vector
&);
111 } // namespace __tsan
113 #endif // #ifndef TSAN_VECTOR_H