LCOV - code coverage report
Current view: top level - gfx/skia/skia/include/private - GrSingleOwner.h (source / functions) Hit Total Coverage
Test: output.info Lines: 0 18 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 6 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright 2016 Google Inc.
       3             :  *
       4             :  * Use of this source code is governed by a BSD-style license that can be
       5             :  * found in the LICENSE file.
       6             :  */
       7             : 
       8             : #ifndef GrSingleOwner_DEFINED
       9             : #define GrSingleOwner_DEFINED
      10             : 
      11             : #include "SkTypes.h"
      12             : 
      13             : #ifdef SK_DEBUG
      14             : #include "SkMutex.h"
      15             : #include "SkThreadID.h"
      16             : 
      17             : // This is a debug tool to verify an object is only being used from one thread at a time.
      18           0 : class GrSingleOwner {
      19             : public:
      20           0 :      GrSingleOwner() : fOwner(kIllegalThreadID), fReentranceCount(0) {}
      21             : 
      22             :      struct AutoEnforce {
      23           0 :          AutoEnforce(GrSingleOwner* so) : fSO(so) { fSO->enter(); }
      24           0 :          ~AutoEnforce() { fSO->exit(); }
      25             : 
      26             :          GrSingleOwner* fSO;
      27             :      };
      28             : 
      29             : private:
      30           0 :      void enter() {
      31           0 :          SkAutoMutexAcquire lock(fMutex);
      32           0 :          SkThreadID self = SkGetThreadID();
      33           0 :          SkASSERT(fOwner == self || fOwner == kIllegalThreadID);
      34           0 :          fReentranceCount++;
      35           0 :          fOwner = self;
      36           0 :      }
      37             : 
      38           0 :      void exit() {
      39           0 :          SkAutoMutexAcquire lock(fMutex);
      40           0 :          SkASSERT(fOwner == SkGetThreadID());
      41           0 :          fReentranceCount--;
      42           0 :          if (fReentranceCount == 0) {
      43           0 :              fOwner = kIllegalThreadID;
      44             :          }
      45           0 :      }
      46             : 
      47             :      SkMutex fMutex;
      48             :      SkThreadID fOwner;    // guarded by fMutex
      49             :      int fReentranceCount; // guarded by fMutex
      50             : };
      51             : #else
      52             : class GrSingleOwner {}; // Provide a dummy implementation so we can pass pointers to constructors
      53             : #endif
      54             : 
      55             : #endif

Generated by: LCOV version 1.13