64static void make_large_number_of_copies(
RCP<int> ptr) {
65 std::vector<RCP<int> > ptrs(10000, ptr);
102 std::vector<std::thread> threads;
103 for (
int i = 0; i < numThreads; ++i) {
104 threads.push_back(std::thread(make_large_number_of_copies, ptr));
106 for (
unsigned int i = 0; i < threads.size(); ++i) {
117static void create_independent_rcp_objects() {
119 while (!ThreadTestManager::s_bAllowThreadsToRun) {}
152 std::vector<std::thread> threads;
154 ThreadTestManager::s_bAllowThreadsToRun =
false;
155 for (
int i = 0; i < numThreads; ++i) {
156 threads.push_back(std::thread(create_independent_rcp_objects));
159 ThreadTestManager::s_bAllowThreadsToRun =
true;
160 for (
unsigned int i = 0; i < threads.size(); ++i) {
173static void create_independent_rcp_without_ownership() {
174 for(
int n = 0;
n < 10000; ++
n ) {
175 int * intPtr =
new int;
202 std::vector<std::thread> threads;
203 for (
int i = 0; i < numThreads; ++i) {
204 threads.push_back(std::thread(create_independent_rcp_without_ownership));
206 for (
unsigned int i = 0; i < threads.size(); ++i) {
218template<
typename SOURCE_RCP_TYPE>
219static void thread_gets_a_copy_of_rcp(SOURCE_RCP_TYPE ptr) {
223 while(!ThreadTestManager::s_bAllowThreadsToRun) {}
251 for(
int cycleIndex = 0; cycleIndex < numCycles; ++cycleIndex) {
253 CatchMemoryLeak::s_countAllocated = 0;
257 ThreadTestManager::s_bAllowThreadsToRun =
false;
258 std::vector<std::thread> threads;
259 for (
int threadIndex = 0; threadIndex < numThreads; ++threadIndex) {
260 threads.push_back(std::thread(
267 ThreadTestManager::s_bAllowThreadsToRun =
true;
268 for (
unsigned int i = 0; i < threads.size(); ++i) {
272 convenience_log_progress(cycleIndex, numCycles);
273 if (CatchMemoryLeak::s_countAllocated != 0) {
287void deallocCatchMemoryLeak(CatchMemoryLeak* ptr)
290 ++CatchMemoryLeak::s_countDeallocs;
316 for(
int cycleIndex = 0; cycleIndex < numCycles; ++cycleIndex) {
317 CatchMemoryLeak::s_countDeallocs = 0;
321 ThreadTestManager::s_bAllowThreadsToRun =
false;
322 std::vector<std::thread> threads;
323 for (
int threadIndex = 0; threadIndex < numThreads; ++threadIndex) {
324 threads.push_back(std::thread(
331 ThreadTestManager::s_bAllowThreadsToRun =
true;
332 for (
unsigned int i = 0; i < threads.size(); ++i) {
336 convenience_log_progress(cycleIndex, numCycles);
337 if (CatchMemoryLeak::s_countDeallocs != 1) {
348void deallocHandleCatchMemoryLeak(CatchMemoryLeak** handle)
350 ++CatchMemoryLeak::s_countDeallocs;
351 CatchMemoryLeak *
ptr = *handle;
378 for(
int cycleIndex = 0; cycleIndex < numCycles; ++cycleIndex) {
379 CatchMemoryLeak::s_countDeallocs = 0;
382 deallocHandleCatchMemoryLeak));
384 ThreadTestManager::s_bAllowThreadsToRun =
false;
385 std::vector<std::thread> threads;
386 for (
unsigned int threadIndex = 0; threadIndex <
387 numThreads; ++threadIndex) {
388 threads.push_back(std::thread(
395 ThreadTestManager::s_bAllowThreadsToRun =
true;
396 for (
unsigned int i = 0; i < threads.size(); ++i) {
400 convenience_log_progress(cycleIndex, numCycles);
401 if (CatchMemoryLeak::s_countDeallocs != 1) {
414 int numCopies,
bool bCallsRelease) {
416 while(!ThreadTestManager::s_bAllowThreadsToRun) {}
441 bool bFailure =
false;
443 for(
int cycleIndex = 0; cycleIndex < numCycles; ++cycleIndex) {
444 CatchMemoryLeak::s_countAllocated = 0;
445 CatchMemoryLeak * pMemoryToLeak =
new CatchMemoryLeak;
448 ThreadTestManager::s_bAllowThreadsToRun =
false;
449 std::vector<std::thread> threads;
450 for (
int threadIndex = 0; threadIndex < numThreads; ++threadIndex) {
451 bool bCallRelease = (threadIndex==0);
452 threads.push_back(std::thread(call_release_on_rcp_if_flag_is_set,
453 ptr, 1, bCallRelease));
456 ThreadTestManager::s_bAllowThreadsToRun =
true;
457 for (
unsigned int i = 0; i < threads.size(); ++i) {
460 convenience_log_progress(cycleIndex, numCycles);
461 if (CatchMemoryLeak::s_countAllocated != 1) {
467 delete pMemoryToLeak;
482 static RCP<ExtraDataTest<T> > create(T *ptr)
483 {
return rcp(
new ExtraDataTest(ptr)); }
484 ~ExtraDataTest() {
delete [] ptr_; }
487 ExtraDataTest(T *ptr) : ptr_(
ptr) {}
490 ExtraDataTest(
const ExtraDataTest&);
491 ExtraDataTest& operator=(
const ExtraDataTest&);
514 for(
int cycleIndex = 0; cycleIndex < numCycles; ++cycleIndex) {
515 CatchMemoryLeak::s_countAllocated = 0;
522 ThreadTestManager::s_bAllowThreadsToRun =
false;
523 std::vector<std::thread> threads;
524 for (
unsigned int threadIndex = 0; threadIndex < numThreads;
526 threads.push_back(std::thread(
533 ThreadTestManager::s_bAllowThreadsToRun =
true;
534 for (
unsigned int i = 0; i < threads.size(); ++i) {
538 convenience_log_progress(cycleIndex, numCycles);
539 if (CatchMemoryLeak::s_countAllocated != 0) {
581 for(
int cycleIndex = 0; cycleIndex < numCycles; ++cycleIndex) {
582 CatchMemoryLeak::s_countAllocated = 0;
586 ThreadTestManager::s_bAllowThreadsToRun =
false;
587 std::vector<std::thread> threads;
588 bool bToggleStrong =
true;
589 for (
int threadIndex = 0; threadIndex < numThreads; ++threadIndex) {
591 threads.push_back(std::thread(
593 ptr.create_strong()));
596 threads.push_back(std::thread(
600 bToggleStrong = !bToggleStrong;
606 ThreadTestManager::s_bAllowThreadsToRun =
true;
607 for (
unsigned int i = 0; i < threads.size(); ++i) {
611 convenience_log_progress(cycleIndex, numCycles);
612 if (CatchMemoryLeak::s_countAllocated != 0) {
623static std::atomic<int> s_count_successful_conversions(0);
624static std::atomic<int> s_count_failed_conversions(0);
625template<
class SOURCE_RCP_TYPE>
626static void attempt_make_a_strong_ptr(SOURCE_RCP_TYPE ptr) {
628 while(!ThreadTestManager::s_bAllowThreadsToRun) {}
631 if (possibleStrongPtr.
is_null()) {
632 ++s_count_failed_conversions;
635 ++s_count_successful_conversions;
666 s_count_successful_conversions = 0;
667 s_count_failed_conversions = 0;
669 for(
int cycleIndex = 0; cycleIndex < numCycles; ++cycleIndex) {
670 CatchMemoryLeak::s_countAllocated = 0;
674 ThreadTestManager::s_bAllowThreadsToRun =
false;
675 std::vector<std::thread> threads;
676 bool bCycleStrong =
true;
677 for (
int threadIndex = 0; threadIndex < numThreads; ++threadIndex) {
679 threads.push_back(std::thread(
681 ptr.create_strong()));
684 threads.push_back(std::thread(
688 bCycleStrong = !bCycleStrong;
694 ThreadTestManager::s_bAllowThreadsToRun =
true;
695 for (
unsigned int i = 0; i < threads.size(); ++i) {
699 if (CatchMemoryLeak::s_countAllocated != 0) {
705 std::cout <<
"Weak converted with null " << s_count_failed_conversions <<
706 " times and success " << s_count_successful_conversions
707 <<
" times. We want to see a mix of each. ";
#define TEUCHOS_THREAD_SAFE_UNIT_TESTS_THREADS_USED
#define TEST_INEQUALITY_CONST(v1, v2)
Assert the inequality of v1 and constant v2.
#define TEST_EQUALITY_CONST(v1, v2)
Assert the equality of v1 and constant v2.
#define TEST_EQUALITY(v1, v2)
Assert the equality of v1 and v2.
Reference-counted pointer node classes.
Reference-counted pointer class and non-member templated function implementations.
#define TEUCHOS_STANDARD_CATCH_STATEMENTS(VERBOSE, ERR_STREAM, SUCCESS_FLAG)
Simple macro that catches and reports standard exceptions and other exceptions.
#define TEUCHOS_UNIT_TEST(TEST_GROUP, TEST_NAME)
Macro for defining a (non-templated) unit test.
Smart reference counting pointer class for automatic garbage collection.
bool is_null() const
Returns true if the underlying pointer is null.
void set_extra_data(const T1 &extra_data, const std::string &name, const Ptr< ArrayRCP< T2 > > &p, EPrePostDestruction destroy_when=POST_DESTROY, bool force_unique=true)
Set extra data associated with a ArrayRCP object.
DeallocFunctorDelete< T, DeleteFunctor > deallocFunctorDelete(DeleteFunctor deleteFunctor)
A simple function used to create a functor deallocator object.
DeallocFunctorHandleDelete< T, DeleteHandleFunctor > deallocFunctorHandleDelete(DeleteHandleFunctor deleteHandleFunctor)
A simple function used to create a functor deallocator object.
Ptr< T > inOutArg(T &arg)
create a non-persisting (required or optional) input/output argument for a function call.
Ptr< T > ptr(T *p)
Create a pointer to an object from a raw pointer.
static int numActiveRCPNodes()
Print the number of active RCPNode objects currently being tracked.
Smart reference counting pointer class for automatic garbage collection.
RCP< T > rcpWithDealloc(T *p, Dealloc_T dealloc, bool owns_mem=true)
Initialize from a raw pointer with a deallocation policy.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.