soui 5.0.0.1
Soui5 Doc
 
Loading...
Searching...
No Matches
SSemaphore.h
1#ifndef __SSEMAPHORE__H__
2#define __SSEMAPHORE__H__
3
4#include <utilities-def.h>
5#include <helper/SNoCopyable.hpp>
6
7SNSBEGIN
8
9/**
10 * @brief Return codes for semaphore operations.
11 */
12enum
13{
14 RETURN_OK = 0, /**< Operation was successful. */
15 RETURN_TIMEOUT = 1, /**< Operation timed out. */
16 RETURN_ERROR = -1 /**< An error occurred. */
17};
18
19class SemaphorePrivate;
20
21/**
22 * @class SSemaphore
23 * @brief A class for thread synchronization using semaphores.
24 * @details This class provides methods to wait for and notify semaphores.
25 * @note This class is non-copyable.
26 */
27class UTILITIES_API SSemaphore : public SNoCopyable
28{
29public:
30 /**
31 * @brief Waits indefinitely for the semaphore to be notified.
32 * @return RETURN_OK if the semaphore is notified successfully.
33 * @return RETURN_ERROR if an error occurs.
34 */
35 int wait();
36
37 /**
38 * @brief Waits for the semaphore to be notified within a specified time.
39 * @param msec The maximum time to wait in milliseconds.
40 * @return RETURN_OK if the semaphore is notified successfully.
41 * @return RETURN_TIMEOUT if the wait times out.
42 * @return RETURN_ERROR if an error occurs.
43 */
44 int wait(unsigned int msec);
45
46 /**
47 * @brief Notifies the semaphore.
48 * @details This function increases the semaphore count, allowing one or more waiting threads to proceed.
49 */
50 void notify();
51
52 /**
53 * @brief Default constructor.
54 * Initializes the semaphore.
55 */
56 SSemaphore();
57
58 /**
59 * @brief Destructor.
60 * Cleans up the semaphore resources.
61 */
62 virtual ~SSemaphore();
63
64private:
65 SemaphorePrivate &_private; /**< Pointer to the private implementation of the semaphore. */
66};
67
68SNSEND
69
70#endif // __SSEMAPHORE__H__
int wait()
Waits indefinitely for the semaphore to be notified.
void notify()
Notifies the semaphore.
SSemaphore()
Default constructor. Initializes the semaphore.