LCOV - code coverage report
Current view: top level - frmts/pcidsk/sdk/core - mutexholder.h (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 16 16 100.0 %
Date: 2024-11-21 22:18:42 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Purpose:  MutexHolder class. Helper class for controlling the acquisition
       4             :  *           and release of a Mutex based on current context.
       5             :  *
       6             :  ******************************************************************************
       7             :  * Copyright (c) 2009
       8             :  * PCI Geomatics, 90 Allstate Parkway, Markham, Ontario, Canada.
       9             :  *
      10             :  * SPDX-License-Identifier: MIT
      11             :  ****************************************************************************/
      12             : #ifndef INCLUDE_CORE_MUTEXHOLDER_H
      13             : #define INCLUDE_CORE_MUTEXHOLDER_H
      14             : 
      15             : #include "pcidsk_mutex.h"
      16             : 
      17             : namespace PCIDSK
      18             : {
      19             :     /************************************************************************/
      20             :     /*                             MutexHolder                              */
      21             :     /************************************************************************/
      22             :     class PCIDSK_DLL MutexHolder
      23             :     {
      24             :     public:
      25       17750 :         MutexHolder( Mutex *mutexIn )
      26       17750 :         {
      27       17750 :             this->mutex = mutexIn;
      28       17750 :             if( mutex != nullptr )
      29       17750 :                 mutex->Acquire();
      30       17750 :         }
      31       17750 :         ~MutexHolder()
      32       17750 :         {
      33       17750 :             if( mutex )
      34       17742 :                 mutex->Release();
      35       17750 :         }
      36             : 
      37           8 :         void Release()
      38             :         {
      39           8 :             if (mutex)
      40             :             {
      41           8 :                 mutex->Release();
      42           8 :                 mutex = nullptr;
      43             :             }
      44           8 :         }
      45             : 
      46             :     private:
      47             :         Mutex     *mutex;
      48             : 
      49             :     };
      50             : 
      51             : } //end namespace PCIDSK
      52             : 
      53             : #endif // INCLUDE_CORE_MUTEXHOLDER_H

Generated by: LCOV version 1.14