foobar2000 SDK  2015-08-03
synchro_win.h
Go to the documentation of this file.
2 protected:
3  CRITICAL_SECTION sec;
4 public:
6  inline void enter() throw() {EnterCriticalSection(&sec);}
7  inline void leave() throw() {LeaveCriticalSection(&sec);}
8  inline void create() throw() {
9 #ifdef PFC_WINDOWS_DESKTOP_APP
11 #else
12  InitializeCriticalSectionEx(&sec,0,0);
13 #endif
14  }
15  inline void destroy() throw() {DeleteCriticalSection(&sec);}
16 private:
18  void operator=(const _critical_section_base&);
19 };
20 
21 // Static-lifetime critical section, no cleanup - valid until process termination
23 public:
25 #if !PFC_LEAK_STATIC_OBJECTS
27 #endif
28 };
29 
30 // Regular critical section, intended for any lifetime scopes
32 private:
33  CRITICAL_SECTION sec;
34 public:
37 };
38 
39 class c_insync
40 {
41 private:
43 public:
44  c_insync(_critical_section_base * p_section) throw() : m_section(*p_section) {m_section.enter();}
45  c_insync(_critical_section_base & p_section) throw() : m_section(p_section) {m_section.enter();}
46  ~c_insync() throw() {m_section.leave();}
47 };
48 
49 #define insync(X) c_insync blah____sync(X)
50 
51 
52 namespace pfc {
53 
54 
55 // Read write lock - Vista-and-newer friendly lock that allows concurrent reads from a resource that permits such
56 // Warning, non-recursion proof
57 #if _WIN32_WINNT < 0x600
58 
59 // Inefficient fallback implementation for pre Vista OSes
60 class readWriteLock {
61 public:
63  void enterRead() {
64  m_obj.enter();
65  }
66  void enterWrite() {
67  m_obj.enter();
68  }
69  void leaveRead() {
70  m_obj.leave();
71  }
72  void leaveWrite() {
73  m_obj.leave();
74  }
75 private:
77 
78  readWriteLock( const readWriteLock & );
79  void operator=( const readWriteLock & );
80 };
81 
82 #else
83 class readWriteLock {
84 public:
85  readWriteLock() : theLock() {
86  }
87 
88  void enterRead() {
89  AcquireSRWLockShared( & theLock );
90  }
91  void enterWrite() {
92  AcquireSRWLockExclusive( & theLock );
93  }
94  void leaveRead() {
95  ReleaseSRWLockShared( & theLock );
96  }
97  void leaveWrite() {
98  ReleaseSRWLockExclusive( &theLock );
99  }
100 
101 private:
103  void operator=(const readWriteLock&);
104 
105  SRWLOCK theLock;
106 };
107 #endif
108 
110 public:
111  _readWriteLock_scope_read( readWriteLock & lock ) : m_lock( lock ) { m_lock.enterRead(); }
112  ~_readWriteLock_scope_read() {m_lock.leaveRead();}
113 private:
115  void operator=( const _readWriteLock_scope_read &);
117 };
119 public:
120  _readWriteLock_scope_write( readWriteLock & lock ) : m_lock( lock ) { m_lock.enterWrite(); }
121  ~_readWriteLock_scope_write() {m_lock.leaveWrite();}
122 private:
124  void operator=( const _readWriteLock_scope_write &);
126 };
127 
128 #define inReadSync( X ) ::pfc::_readWriteLock_scope_read _asdf_l_readWriteLock_scope_read( X )
129 #define inWriteSync( X ) ::pfc::_readWriteLock_scope_write _asdf_l_readWriteLock_scope_write( X )
130 
133 
134 }
_critical_section_base & m_section
Definition: synchro_win.h:42
_readWriteLock_scope_read(readWriteLock &lock)
Definition: synchro_win.h:111
critical_section m_obj
Definition: synchro_win.h:76
c_insync(_critical_section_base &p_section)
Definition: synchro_win.h:45
CRITICAL_SECTION sec
Definition: synchro_win.h:3
CRITICAL_SECTION sec
Definition: synchro_win.h:33
_readWriteLock_scope_write(readWriteLock &lock)
Definition: synchro_win.h:120
::c_insync mutexScope
Definition: synchro_win.h:132
::critical_section mutex
Definition: synchro_win.h:131
pfc::mutexRecur critical_section
Definition: synchro_nix.h:138
void InitializeCriticalSection(LPCRITICAL_SECTION lpCriticalSection)
Definition: pp-winapi.h:24
pfc::mutexScope c_insync
Definition: synchro_nix.h:140
void operator=(const _critical_section_base &)
c_insync(_critical_section_base *p_section)
Definition: synchro_win.h:44