Merge new TortoiseGitBlame Parser
[TortoiseGit.git] / src / AsyncFramework / CriticalSection.h
blob30bd5e77ffd94407c063fb65744398de4a541d2a
1 /***************************************************************************
2 * Copyright (C) 2009 by Stefan Fuhrmann *
3 * stefanfuhrmann@alice-dsl.de *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #pragma once
23 namespace async
26 /**
27 * Just a simple critical section (i.e. recursive mutex)
28 * implementation with minimal overhead.
31 class CCriticalSection
33 private:
35 /// OS-specific critical section object
37 CRITICAL_SECTION section;
39 public:
41 /// construction
43 CCriticalSection(void);
45 /// destruction
47 ~CCriticalSection(void);
49 /// Acquire the mutex, i.e. enter the critical section
51 void Acquire();
53 /// Release the mutex, i.e. leave the critical section
55 void Release();
58 // Mutex functionality
60 __forceinline void CCriticalSection::Acquire()
62 EnterCriticalSection (&section);
65 __forceinline void CCriticalSection::Release()
67 LeaveCriticalSection (&section);
70 /**
71 * RAII lock class for \ref CCriticalSection mutexes.
74 class CCriticalSectionLock
76 private:
78 CCriticalSection& section;
80 // dummy assignement operator to silence the C4512 compiler warning
81 // not implemented assigment operator (even is dummy and private) to
82 // get rid of cppcheck error as well as accidental use
83 CCriticalSectionLock & operator=( const CCriticalSectionLock & ) /*{ section = ; return * this; }*/;
84 public:
86 __forceinline CCriticalSectionLock (CCriticalSection& section)
87 : section (section)
89 section.Acquire();
92 __forceinline ~CCriticalSectionLock()
94 section.Release();