@@ -15,66 +15,68 @@ bool Event::Wait(u32 millisecondsTimeout) noexcept
15
15
#include < pthread.h>
16
16
Event::Event () noexcept
17
17
{
18
- m_id.signaled = false ;
19
- pthread_mutex_init (&m_id.mutex , nullptr );
20
- pthread_cond_init (&m_id.cond , nullptr );
18
+ m_id.signaled = false ;
19
+ pthread_mutex_init (&m_id.mutex , nullptr );
20
+ pthread_cond_init (&m_id.cond , nullptr );
21
21
}
22
22
Event::~Event () noexcept
23
23
{
24
- pthread_mutex_destroy (&m_id.mutex );
25
- pthread_cond_destroy (&m_id.cond );
24
+ pthread_mutex_destroy (&m_id.mutex );
25
+ pthread_cond_destroy (&m_id.cond );
26
26
}
27
27
void Event::Reset () noexcept
28
28
{
29
- pthread_mutex_lock (&m_id.mutex );
30
- pthread_cond_signal (&m_id.cond );
31
- m_id.signaled = false ;
32
- pthread_mutex_unlock (&m_id.mutex );
29
+ pthread_mutex_lock (&m_id.mutex );
30
+ pthread_cond_signal (&m_id.cond );
31
+ m_id.signaled = false ;
32
+ pthread_mutex_unlock (&m_id.mutex );
33
33
}
34
34
void Event::Set () noexcept
35
35
{
36
- pthread_mutex_lock (&m_id.mutex );
37
- pthread_cond_signal (&m_id.cond );
38
- m_id.signaled = true ;
39
- pthread_mutex_unlock (&m_id.mutex );
36
+ pthread_mutex_lock (&m_id.mutex );
37
+ pthread_cond_signal (&m_id.cond );
38
+ m_id.signaled = true ;
39
+ pthread_mutex_unlock (&m_id.mutex );
40
40
}
41
41
void Event::Wait () noexcept
42
42
{
43
- pthread_mutex_lock (&m_id.mutex );
43
+ pthread_mutex_lock (&m_id.mutex );
44
44
45
- while (!m_id.signaled )
46
- {
47
- pthread_cond_wait (&m_id.cond , &m_id.mutex );
48
- }
45
+ while (!m_id.signaled )
46
+ {
47
+ pthread_cond_wait (&m_id.cond , &m_id.mutex );
48
+ }
49
+ m_id.signaled = false ; // due in WaitForSingleObject() "Before returning, a wait function modifies the state of some types of synchronization"
49
50
50
- pthread_mutex_unlock (&m_id.mutex );
51
+ pthread_mutex_unlock (&m_id.mutex );
51
52
}
52
53
bool Event::Wait (u32 millisecondsTimeout) noexcept
53
54
{
54
- bool result = false ;
55
- pthread_mutex_lock (&m_id.mutex );
55
+ bool result = false ;
56
+ pthread_mutex_lock (&m_id.mutex );
56
57
57
- timespec ts;
58
- clock_gettime (CLOCK_REALTIME, &ts);
59
- ts.tv_nsec += (long ) millisecondsTimeout * 1000 * 1000 ;
60
- if (ts.tv_nsec > 1000000000 )
61
- {
62
- ts.tv_nsec -= 1000000000 ;
63
- ts.tv_sec += 1 ;
64
- }
58
+ timespec ts;
59
+ clock_gettime (CLOCK_REALTIME, &ts);
60
+ ts.tv_nsec += (long ) millisecondsTimeout * 1000 * 1000 ;
61
+ if (ts.tv_nsec > 1000000000 )
62
+ {
63
+ ts.tv_nsec -= 1000000000 ;
64
+ ts.tv_sec += 1 ;
65
+ }
65
66
66
- while (!m_id.signaled )
67
- {
68
- int res = pthread_cond_timedwait (&m_id.cond , &m_id.mutex , &ts);
69
- if (res == ETIMEDOUT)
70
- {
71
- result = true ;
72
- break ;
73
- }
74
- }
67
+ while (!m_id.signaled )
68
+ {
69
+ int res = pthread_cond_timedwait (&m_id.cond , &m_id.mutex , &ts);
70
+ if (res == ETIMEDOUT)
71
+ {
72
+ result = true ;
73
+ break ;
74
+ }
75
+ }
76
+ m_id.signaled = false ;
75
77
76
- pthread_mutex_unlock (&m_id.mutex );
78
+ pthread_mutex_unlock (&m_id.mutex );
77
79
78
- return result;
80
+ return result;
79
81
}
80
82
#endif
0 commit comments