11 #include "../clib/logfacility.h" 12 #include "../clib/passert.h" 13 #include "../clib/threadhelp.h" 14 #include "../clib/tracebuf.h" 32 EnterCriticalSection( &cs );
39 size_t tid = GetCurrentThreadId();
42 LeaveCriticalSection( &cs );
48 int res = pthread_mutex_lock( &
polsem );
49 if ( res != 0 || locker != 0 )
51 POLLOG.Format(
"pthread_mutex_lock: res={}, tid={}, locker={}\n" ) << res << tid <<
locker;
62 int res = pthread_mutex_unlock( &
polsem );
65 POLLOG.Format(
"pthread_mutex_unlock: res={},tid={}" ) << res << tid;
77 HANDLE hEvTasksThread;
78 HANDLE hEvClientTransmit;
80 CRITICAL_SECTION csThread;
85 InitializeCriticalSection( &cs );
86 hEvPulse = CreateEvent(
nullptr, TRUE, FALSE,
nullptr );
88 hEvTasksThread = CreateEvent(
nullptr, FALSE, FALSE,
nullptr );
90 hEvClientTransmit = CreateEvent(
nullptr, TRUE, FALSE,
nullptr );
92 InitializeCriticalSection( &csThread );
93 hSemThread = CreateSemaphore(
nullptr, 0, 1,
nullptr );
98 CloseHandle( hSemThread );
99 DeleteCriticalSection( &csThread );
101 CloseHandle( hEvTasksThread );
102 hEvTasksThread =
nullptr;
104 CloseHandle( hEvPulse );
105 CloseHandle( hEvClientTransmit );
106 DeleteCriticalSection( &cs );
111 PulseEvent( hEvPulse );
116 WaitForSingleObject( hEvPulse, millis );
121 SetEvent( hEvTasksThread );
126 WaitForSingleObject( hEvTasksThread, millis );
132 PulseEvent( hEvClientTransmit );
137 WaitForSingleObject( hEvClientTransmit, millis );
168 res = pthread_mutexattr_init( &polsem_attr );
179 res = pthread_mutex_init( &polsem, &polsem_attr );
182 pthread_attr_init( &thread_attr );
183 pthread_attr_setdetachstate( &thread_attr, PTHREAD_CREATE_DETACHED );
190 pthread_mutex_lock( &pulse_mut );
191 pthread_cond_broadcast( &pulse_cond );
192 pthread_mutex_unlock( &pulse_mut );
200 gettimeofday( &now, &tz );
204 add_sec = millis / 1000;
205 millis -= ( add_sec * 1000 );
207 ptimeout->tv_sec = now.tv_sec + add_sec;
209 ptimeout->tv_nsec = now.tv_usec * 1000 + millis * 1000000L;
210 if ( ptimeout->tv_nsec >= 1000000000 )
213 ptimeout->tv_nsec -= 1000000000;
219 struct timespec timeout;
221 pthread_mutex_lock( &pulse_mut );
225 pthread_cond_timedwait( &pulse_cond, &pulse_mut, &timeout );
227 pthread_mutex_unlock( &pulse_mut );
232 pthread_mutex_lock( &task_pulse_mut );
233 pthread_cond_broadcast( &task_pulse_cond );
234 pthread_mutex_unlock( &task_pulse_mut );
239 struct timespec timeout;
241 pthread_mutex_lock( &task_pulse_mut );
245 pthread_cond_timedwait( &task_pulse_cond, &task_pulse_mut, &timeout );
247 pthread_mutex_unlock( &task_pulse_mut );
252 pthread_mutex_lock( &clienttransmit_pulse_mut );
253 pthread_cond_broadcast( &clienttransmit_pulse_cond );
254 pthread_mutex_unlock( &clienttransmit_pulse_mut );
259 struct timespec timeout;
261 pthread_mutex_lock( &clienttransmit_pulse_mut );
265 pthread_cond_timedwait( &clienttransmit_pulse_cond, &clienttransmit_pulse_mut, &timeout );
267 pthread_mutex_unlock( &clienttransmit_pulse_mut );
pthread_mutex_t clienttransmit_pulse_mut
pthread_cond_t clienttransmit_pulse_cond
pthread_mutex_t task_pulse_mut
void send_ClientTransmit_pulse()
#define TRACEBUF_ADDELEM(tag, value)
void wait_for_ClientTransmit_pulse(unsigned int millis)
pthread_cond_t threadstart_pulse_cond
void calc_abs_timeout(struct timespec *ptimeout, unsigned int millis)
pthread_mutex_t polsemdbg_mut
pthread_cond_t task_pulse_cond
pthread_cond_t pulse_cond
pthread_mutex_t pulse_mut
#define passert_always(exp)
pthread_attr_t thread_attr
void tasks_thread_sleep(unsigned int millis)
pthread_mutex_t threadstart_pulse_mut
pthread_mutex_t threadstart_mut
pthread_mutexattr_t polsem_attr
void wait_for_pulse(unsigned int millis)