soui 5.0.0.1
Soui5 Doc
 
Loading...
Searching...
No Matches
SCriticalSection.h
Go to the documentation of this file.
1/**
2 * @file SCriticalSection.h
3 * @brief Header file for SCriticalSection and SAutoLock classes.
4 * @version v1.0
5 * @author SOUI group
6 * @date 2014/09/27
7 *
8 * @details This file provides a wrapper for critical sections and an auto-lock mechanism.
9 */
10
11 #ifndef __SCRITICALSECTION__H__
12 #define __SCRITICALSECTION__H__
13
14 #include <utilities-def.h>
15
16 SNSBEGIN
17
18 /**
19 * @class SCriticalSectionImpl
20 * @brief Implementation class for critical section.
21 * @note This class is intended for internal use.
22 */
24
25 /**
26 * @class SCriticalSection
27 * @brief Wrapper class for a critical section.
28 * @details This class provides methods to enter and leave a critical section, ensuring thread safety.
29 */
30 class UTILITIES_API SCriticalSection
31 {
32 public:
33 /**
34 * @brief Constructor.
35 * Initializes a new critical section.
36 */
38
39 /**
40 * @brief Destructor.
41 * Destroys the critical section.
42 */
43 virtual ~SCriticalSection();
44
45 /**
46 * @brief Enters the critical section.
47 * @details This method blocks the calling thread until the critical section is available.
48 */
49 void Enter();
50
51 /**
52 * @brief Leaves the critical section.
53 * @details This method releases the critical section, allowing other threads to enter.
54 */
55 void Leave();
56
57 protected:
58 SCriticalSectionImpl* m_cs; /**< Pointer to the critical section implementation. */
59 };
60
61 /**
62 * @class SAutoLock
63 * @brief Auto-lock class for managing critical sections.
64 * @details This class automatically enters the critical section upon construction and leaves it upon destruction.
65 */
66 class UTILITIES_API SAutoLock
67 {
68 public:
69 /**
70 * @brief Constructor.
71 * @param cs Reference to the SCriticalSection object to manage.
72 * @details Enters the critical section.
73 */
75 {
76 m_cs.Enter();
77 }
78
79 /**
80 * @brief Destructor.
81 * @details Leaves the critical section.
82 */
84 {
85 m_cs.Leave();
86 }
87
88 protected:
89 SCriticalSection & m_cs; /**< Reference to the managed SCriticalSection object. */
90 };
91
92 SNSEND
93
94 #endif // __SCRITICALSECTION__H__
SCriticalSection & m_cs
SAutoLock(SCriticalSection &cs)
Constructor.
~SAutoLock()
Destructor.
Wrapper class for a critical section.
SCriticalSectionImpl * m_cs
void Leave()
Leaves the critical section.
SCriticalSection()
Constructor. Initializes a new critical section.
void Enter()
Enters the critical section.
Implementation class for critical section.