Beispiel #1
0
 void onDraw(const int loops, SkCanvas*) override {
     for (int i = 0; i < loops; ++i) {
         SkWeakRefCnt* ref = new SkWeakRefCnt();
         for (int j = 0; j < M; ++j) {
             ref->ref();
             ref->unref();
         }
         ref->unref();
     }
 }
Beispiel #2
0
static void bounce_weak_ref(void* data) {
    SkWeakRefCnt* ref = static_cast<SkWeakRefCnt*>(data);
    for (int i = 0; i < 100000; ++i) {
        if (ref->try_ref()) {
            ref->unref();
        }
    }
}
Beispiel #3
0
 virtual void onDraw(const int loops, SkCanvas*) {
     for (int i = 0; i < loops; ++i) {
         SkWeakRefCnt ref;
         for (int j = 0; j < M; ++j) {
             ref.ref();
             ref.unref();
         }
     }
 }
Beispiel #4
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();
}