Exemplo n.º 1
0
static void test_refCnt(skiatest::Reporter* reporter) {
    SkRefCnt* ref = new SkRefCnt();

    std::thread thing1(bounce_ref, ref);
    std::thread thing2(bounce_ref, ref);

    thing1.join();
    thing2.join();

    REPORTER_ASSERT(reporter, ref->unique());
    ref->unref();
}
main()
{	int a, b; 
	int length=10000000;
	
	getchar();
	b=0;
	for(int m=0; m<length; m++)
	{	a=clock();
		thing1(a);	
		b+=clock()-a;
	}
	cout << "\nfirst: " << b;
	
	b=0;
	for(int m=0; m<length; m++)
	{	a=clock();
		thing2(&a);	
		b+=clock()-a;
	}
	cout << "\nsecond: " << b;

	b=0;
	for(int m=0; m<length; m++)
	{	a=clock();
		thing3(&a);	
		b+=clock()-a;
	}
	cout << "\nthird: " << b;

	b=0;
	for(int m=0; m<length; m++)
	{	a=clock();
		thing4(a);	
		b+=clock()-a;
	}
	cout << "\nfirst: " << b;

	b=0;
	for(int m=0; m<length; m++)
	{	a=clock();
		thing5(a);	
		b+=clock()-a;
	}
	cout << "\nfirst: " << b;

	getchar();
	
}
Exemplo n.º 3
0
static void test_weakRefCnt(skiatest::Reporter* reporter) {
    SkWeakRefCnt* ref = new SkWeakRefCnt();

    std::thread thing1(bounce_ref, ref);
    std::thread thing2(bounce_ref, ref);
    std::thread thing3(bounce_weak_ref, ref);
    std::thread thing4(bounce_weak_weak_ref, ref);

    thing1.join();
    thing2.join();
    thing3.join();
    thing4.join();

    REPORTER_ASSERT(reporter, ref->unique());
    SkDEBUGCODE(REPORTER_ASSERT(reporter, ref->getWeakCnt() == 1));
    ref->unref();
}
TEST(fxcrt, MaybeOwnedNotOwned) {
  int delete_count = 0;
  PseudoDeletable thing1(100, &delete_count);
  {
    CFX_MaybeOwned<PseudoDeletable> ptr(&thing1);
    EXPECT_FALSE(ptr.IsOwned());
    EXPECT_EQ(ptr.Get(), &thing1);
    EXPECT_EQ(100, ptr->GetID());
    EXPECT_TRUE(ptr == &thing1);
    EXPECT_FALSE(ptr != &thing1);

    CFX_MaybeOwned<PseudoDeletable> empty;
    EXPECT_FALSE(ptr == empty);
    EXPECT_TRUE(ptr != empty);
  }
  EXPECT_EQ(0, delete_count);

  delete_count = 0;
  PseudoDeletable thing2(200, &delete_count);
  {
    CFX_MaybeOwned<PseudoDeletable> ptr(&thing1);
    ptr = &thing2;
    EXPECT_FALSE(ptr.IsOwned());
    EXPECT_EQ(ptr.Get(), &thing2);
    EXPECT_EQ(200, ptr->GetID());
  }
  EXPECT_EQ(0, delete_count);

  delete_count = 0;
  int owned_delete_count = 0;
  {
    CFX_MaybeOwned<PseudoDeletable> ptr(&thing1);
    EXPECT_EQ(100, ptr->GetID());
    ptr = pdfium::MakeUnique<PseudoDeletable>(300, &owned_delete_count);
    EXPECT_TRUE(ptr.IsOwned());
    EXPECT_EQ(300, ptr->GetID());
  }
  EXPECT_EQ(0, delete_count);
  EXPECT_EQ(1, owned_delete_count);
}
TEST(fxcrt, MaybeOwnedMove) {
  int delete_count = 0;
  PseudoDeletable thing1(100, &delete_count);
  {
    CFX_MaybeOwned<PseudoDeletable> ptr1(&thing1);
    CFX_MaybeOwned<PseudoDeletable> ptr2(
        pdfium::MakeUnique<PseudoDeletable>(200, &delete_count));
    EXPECT_FALSE(ptr1.IsOwned());
    EXPECT_TRUE(ptr2.IsOwned());

    CFX_MaybeOwned<PseudoDeletable> ptr3(std::move(ptr1));
    CFX_MaybeOwned<PseudoDeletable> ptr4(std::move(ptr2));
    EXPECT_FALSE(ptr1.IsOwned());
    EXPECT_FALSE(ptr2.IsOwned());
    EXPECT_FALSE(ptr3.IsOwned());
    EXPECT_TRUE(ptr4.IsOwned());
    EXPECT_EQ(0, delete_count);
    EXPECT_EQ(nullptr, ptr1.Get());
    EXPECT_EQ(nullptr, ptr2.Get());
    EXPECT_EQ(100, ptr3->GetID());
    EXPECT_EQ(200, ptr4->GetID());

    CFX_MaybeOwned<PseudoDeletable> ptr5;
    CFX_MaybeOwned<PseudoDeletable> ptr6;
    ptr5 = std::move(ptr3);
    ptr6 = std::move(ptr4);
    EXPECT_FALSE(ptr3.IsOwned());
    EXPECT_FALSE(ptr4.IsOwned());
    EXPECT_FALSE(ptr5.IsOwned());
    EXPECT_TRUE(ptr6.IsOwned());
    EXPECT_EQ(0, delete_count);
    EXPECT_EQ(nullptr, ptr3.Get());
    EXPECT_EQ(nullptr, ptr4.Get());
    EXPECT_EQ(100, ptr5->GetID());
    EXPECT_EQ(200, ptr6->GetID());
  }
  EXPECT_EQ(1, delete_count);
}