]>
Commit | Line | Data |
---|---|---|
f427ee49 A |
1 | #ifndef TESTS_INTRUSIVE_SHARED_PTR_TEST_POLICY_H |
2 | #define TESTS_INTRUSIVE_SHARED_PTR_TEST_POLICY_H | |
3 | ||
4 | #include <libkern/c++/intrusive_shared_ptr.h> | |
5 | #include <darwintest_utils.h> | |
6 | ||
7 | struct test_policy { | |
8 | static inline int retain_count = 0; | |
9 | ||
10 | template <typename T> | |
11 | static void | |
12 | retain(T&) | |
13 | { | |
14 | ++retain_count; | |
15 | } | |
16 | template <typename T> | |
17 | static void | |
18 | release(T&) | |
19 | { | |
20 | --retain_count; | |
21 | } | |
22 | }; | |
23 | ||
24 | struct tracking_policy { | |
25 | static inline int retains = 0; | |
26 | static inline int releases = 0; | |
27 | static inline int refcount = 0; | |
28 | static inline bool hit_zero = false; | |
29 | ||
30 | static void | |
31 | reset() | |
32 | { | |
33 | retains = 0; | |
34 | releases = 0; | |
35 | refcount = 0; | |
36 | hit_zero = false; | |
37 | } | |
38 | ||
39 | template <typename T> | |
40 | static void | |
41 | retain(T&) | |
42 | { | |
43 | ++retains; | |
44 | ++refcount; | |
45 | } | |
46 | template <typename T> | |
47 | static void | |
48 | release(T&) | |
49 | { | |
50 | ++releases; | |
51 | --refcount; | |
52 | if (refcount == 0) { | |
53 | hit_zero = true; | |
54 | } | |
55 | } | |
56 | }; | |
57 | ||
58 | template <int> | |
59 | struct dummy_policy { | |
60 | template <typename T> | |
61 | static void | |
62 | retain(T&) | |
63 | { | |
64 | } | |
65 | template <typename T> | |
66 | static void | |
67 | release(T&) | |
68 | { | |
69 | } | |
70 | }; | |
71 | ||
72 | template <typename T> | |
73 | using tracked_shared_ptr = libkern::intrusive_shared_ptr<T, tracking_policy>; | |
74 | ||
75 | template <typename T> | |
76 | using test_shared_ptr = libkern::intrusive_shared_ptr<T, test_policy>; | |
77 | ||
78 | #define CHECK(...) T_ASSERT_TRUE((__VA_ARGS__), # __VA_ARGS__) | |
79 | ||
80 | #endif // !TESTS_INTRUSIVE_SHARED_PTR_TEST_POLICY_H |