foobar2000 SDK  2015-01-14
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() {InitializeCriticalSection(&sec);}
9  inline void destroy() throw() {DeleteCriticalSection(&sec);}
10 private:
12  void operator=(const _critical_section_base&);
13 };
14 
15 // Static-lifetime critical section, no cleanup - valid until process termination
17 public:
19 #if !PFC_LEAK_STATIC_OBJECTS
21 #endif
22 };
23 
24 // Regular critical section, intended for any lifetime scopes
26 private:
27  CRITICAL_SECTION sec;
28 public:
31 };
32 
33 class c_insync
34 {
35 private:
37 public:
38  c_insync(_critical_section_base * p_section) throw() : m_section(*p_section) {m_section.enter();}
39  c_insync(_critical_section_base & p_section) throw() : m_section(p_section) {m_section.enter();}
40  ~c_insync() throw() {m_section.leave();}
41 };
42 
43 #define insync(X) c_insync blah____sync(X)
44 
45 
46 namespace pfc {
47 
48 
49 // Read write lock - Vista-and-newer friendly lock that allows concurrent reads from a resource that permits such
50 // Warning, non-recursion proof
51 #if _WIN32_WINNT < 0x600
52 
53 // Inefficient fallback implementation for pre Vista OSes
54 class readWriteLock {
55 public:
57  void enterRead() {
58  m_obj.enter();
59  }
60  void enterWrite() {
61  m_obj.enter();
62  }
63  void leaveRead() {
64  m_obj.leave();
65  }
66  void leaveWrite() {
67  m_obj.leave();
68  }
69 private:
71 
72  readWriteLock( const readWriteLock & );
73  void operator=( const readWriteLock & );
74 };
75 
76 #else
77 class readWriteLock {
78 public:
80  }
81 
82  void enterRead() {
83  AcquireSRWLockShared( & theLock );
84  }
85  void enterWrite() {
86  AcquireSRWLockExclusive( & theLock );
87  }
88  void leaveRead() {
89  ReleaseSRWLockShared( & theLock );
90  }
91  void leaveWrite() {
92  ReleaseSRWLockExclusive( &theLock );
93  }
94 
95 private:
97  void operator=(const readWriteLock&);
98 
99  SRWLOCK theLock;
100 };
101 #endif
102 
104 public:
107 private:
109  void operator=( const _readWriteLock_scope_read &);
111 };
113 public:
116 private:
118  void operator=( const _readWriteLock_scope_write &);
120 };
121 
122 #define inReadSync( X ) ::pfc::_readWriteLock_scope_read _asdf_l_readWriteLock_scope_read( X )
123 #define inWriteSync( X ) ::pfc::_readWriteLock_scope_write _asdf_l_readWriteLock_scope_write( X )
124 
125 }
_critical_section_base & m_section
Definition: synchro_win.h:36
_readWriteLock_scope_read(readWriteLock &lock)
Definition: synchro_win.h:105
critical_section m_obj
Definition: synchro_win.h:70
c_insync(_critical_section_base &p_section)
Definition: synchro_win.h:39
void operator=(const readWriteLock &)
CRITICAL_SECTION sec
Definition: synchro_win.h:3
CRITICAL_SECTION sec
Definition: synchro_win.h:27
readWriteLockBase & m_lock
Definition: synchro_nix.h:123
_readWriteLock_scope_write(readWriteLock &lock)
Definition: synchro_win.h:114
void operator=(const _readWriteLock_scope_write &)
void operator=(const _critical_section_base &)
readWriteLockBase & m_lock
Definition: synchro_nix.h:132
c_insync(_critical_section_base *p_section)
Definition: synchro_win.h:38
_readWriteLock_scope_read(readWriteLockBase &lock)
Definition: synchro_nix.h:118
void operator=(const _readWriteLock_scope_read &)
_readWriteLock_scope_write(readWriteLockBase &lock)
Definition: synchro_nix.h:127