FreeRDP
libwinpr/synch/synch.h
1 
20 #ifndef WINPR_SYNCH_PRIVATE_H
21 #define WINPR_SYNCH_PRIVATE_H
22 
23 #include <winpr/config.h>
24 
25 #include <winpr/platform.h>
26 
27 #include <winpr/synch.h>
28 
29 #include "../handle/handle.h"
30 #include "../thread/apc.h"
31 #include "event.h"
32 
33 #ifndef _WIN32
34 
35 #define WINPR_PIPE_SEMAPHORE 1
36 
37 #if defined __APPLE__
38 #include <pthread.h>
39 #include <sys/time.h>
40 #include <semaphore.h>
41 #include <mach/mach.h>
42 #include <mach/semaphore.h>
43 #include <mach/task.h>
44 #define winpr_sem_t semaphore_t
45 #else
46 #include <pthread.h>
47 #include <semaphore.h>
48 #define winpr_sem_t sem_t
49 #endif
50 
52 {
53  WINPR_HANDLE common;
54  char* name;
55  pthread_mutex_t mutex;
56 };
57 typedef struct winpr_mutex WINPR_MUTEX;
58 
60 {
61  WINPR_HANDLE common;
62 
63  int pipe_fd[2];
64  winpr_sem_t* sem;
65 };
66 typedef struct winpr_semaphore WINPR_SEMAPHORE;
67 
68 #ifdef WINPR_HAVE_SYS_TIMERFD_H
69 #include <stdio.h>
70 #include <unistd.h>
71 #include <fcntl.h>
72 #include <sys/timerfd.h>
73 #define TIMER_IMPL_TIMERFD
74 
75 #elif defined(WITH_POSIX_TIMER)
76 #include <fcntl.h>
77 #define TIMER_IMPL_POSIX
78 
79 #elif defined(__APPLE__)
80 #define TIMER_IMPL_DISPATCH
81 #include <dispatch/dispatch.h>
82 #else
83 #warning missing timer implementation
84 #endif
85 
87 {
88  WINPR_HANDLE common;
89 
90  int fd;
91  BOOL bInit;
92  LONG lPeriod;
93  BOOL bManualReset;
94  PTIMERAPCROUTINE pfnCompletionRoutine;
95  LPVOID lpArgToCompletionRoutine;
96 
97 #ifdef TIMER_IMPL_TIMERFD
98  struct itimerspec timeout;
99 #endif
100 
101 #ifdef TIMER_IMPL_POSIX
102  WINPR_EVENT_IMPL event;
103  timer_t tid;
104  struct itimerspec timeout;
105 #endif
106 
107 #ifdef TIMER_IMPL_DISPATCH
108  WINPR_EVENT_IMPL event;
109  dispatch_queue_t queue;
110  dispatch_source_t source;
111  BOOL running;
112 #endif
113  char* name;
114 
115  WINPR_APC_ITEM apcItem;
116 };
117 typedef struct winpr_timer WINPR_TIMER;
118 
119 typedef struct winpr_timer_queue_timer WINPR_TIMER_QUEUE_TIMER;
120 
122 {
123  WINPR_HANDLE common;
124 
125  pthread_t thread;
126  pthread_attr_t attr;
127  pthread_mutex_t mutex;
128  pthread_cond_t cond;
129  pthread_mutex_t cond_mutex;
130  struct sched_param param;
131 
132  BOOL bCancelled;
133  WINPR_TIMER_QUEUE_TIMER* activeHead;
134  WINPR_TIMER_QUEUE_TIMER* inactiveHead;
135 };
136 typedef struct winpr_timer_queue WINPR_TIMER_QUEUE;
137 
139 {
140  WINPR_HANDLE common;
141 
142  ULONG Flags;
143  DWORD DueTime;
144  DWORD Period;
145  PVOID Parameter;
146  WAITORTIMERCALLBACK Callback;
147 
148  int FireCount;
149 
150  struct timespec StartTime;
151  struct timespec ExpirationTime;
152 
153  WINPR_TIMER_QUEUE* timerQueue;
154  WINPR_TIMER_QUEUE_TIMER* next;
155 };
156 
157 #endif
158 
159 #endif /* WINPR_SYNCH_PRIVATE_H */