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);
65 void Resize(uptr size
) {
66 uptr old_size
= Size();
68 if (old_size
< size
) {
69 for (uptr i
= old_size
; i
< size
; i
++)
75 const MBlockType typ_
;
80 void EnsureSize(uptr size
) {
83 if (size
<= (uptr
)(last_
- begin_
)) {
87 uptr cap0
= last_
- begin_
;
93 T
*p
= (T
*)internal_alloc(typ_
, cap
* sizeof(T
));
95 internal_memcpy(p
, begin_
, cap0
* sizeof(T
));
96 internal_free(begin_
);
100 last_
= begin_
+ cap
;
103 Vector(const Vector
&);
104 void operator=(const Vector
&);
106 } // namespace __tsan
108 #endif // #ifndef TSAN_VECTOR_H