dn_thread.h
Go to the documentation of this file.
1 #ifndef DN_THREAD_H_
2 #define DN_THREAD_H_
3 
38 #ifndef _DN_EXP_THREAD
39 #define _DN_EXP_THREAD
40 #endif /* _DN_EXP_THREAD */
41 
62 #if defined(_USE_WIN_API)
63 #define begin_thread(p_thread, function, arg) { *p_thread = (HANDLE)_beginthreadex(NULL, 0, function, arg, 0, NULL); }
64 #define exit_thread(thread) { if(thread != NULL) { WaitForSingleObject(thread, INFINITE); CloseHandle(thread); thread = NULL; } }
65 #define dn_sleep(n) Sleep(n)
66 typedef HANDLE MUTEX;
67 typedef HANDLE THREAD;
68 typedef unsigned int THRET;
69 #define THTYPE __stdcall
70 typedef HANDLE EVENT;
71 #elif defined(_USE_LINUX_API)
72 #define begin_thread(p_thread, function, arg) pthread_create(p_thread, NULL, function, arg)
73 #define exit_thread(thread) pthread_join(thread, NULL)
74 #define dn_sleep(n) usleep((n) * 1000)
75 typedef pthread_mutex_t MUTEX;
76 typedef pthread_t THREAD;
77 typedef void *THRET;
78 #define THTYPE
79 #define STATUS_WAIT_0 ((uint32_t)0x00000000L)
80 #define WAIT_OBJECT_0 ((STATUS_WAIT_0) + 0)
81 typedef struct EVENT
82  {
83  pthread_mutex_t mutex;
84  pthread_cond_t cond;
85  int mode;
86  int signal;
87  }EVENT;
88 #endif
89 
94 #ifndef INFINITE
95 #define INFINITE ((uint32_t)-1)
96 #endif
97 
98 #ifdef __cplusplus
99 extern "C"
100 {
101 #endif
102 
109  initialize_mutex(MUTEX *pmutex);
110 
118  release_mutex(MUTEX *pmutex);
119 
127  lock_mutex(MUTEX *pmutex, uint32_t timeout);
128 
135  unlock_mutex(MUTEX *pmutex);
136 
145  create_event(EVENT *pevt, int reset_mode, int init_signal);
146 
154  destroy_event(EVENT *pevt);
155 
162  set_event(EVENT *pevt);
163 
170  reset_event(EVENT *pevt);
171 
179  wait_event(EVENT *pevt, uint32_t timeout);
180 
190  wait_event_multi(EVENT **pevt, uint32_t count, uint32_t timeout,
191  int wait_all);
192 
199 #define calc_time_diff(start, end) (((end) >= (start)) ? ((end) - (start)) : ((((uint32_t)-1) - (end)) + (start)))
200 
207 
208 #ifdef __cplusplus
209 }
210 #endif
211 
212 #endif /* DN_THREAD_H_ */
_DN_EXP_THREAD HRESULT wait_event(EVENT *pevt, uint32_t timeout)
Waits a event.
Definition: dn_thread.c:361
_DN_EXP_THREAD HRESULT unlock_mutex(MUTEX *pmutex)
Unlocks mutex handle.
Definition: dn_thread.c:188
unsigned uint32_t
Definition: stdint.h:43
_DN_EXP_THREAD HRESULT lock_mutex(MUTEX *pmutex, uint32_t timeout)
Locks mutex handle.
Definition: dn_thread.c:145
_DN_EXP_THREAD HRESULT create_event(EVENT *pevt, int reset_mode, int init_signal)
Creates a event object.
Definition: dn_thread.c:220
_DN_EXP_THREAD HRESULT wait_event_multi(EVENT **pevt, uint32_t count, uint32_t timeout, int wait_all)
Waits multiple events.
Definition: dn_thread.c:478
int THREAD
int MUTEX
int32_t HRESULT
Definition: dn_common.h:61
_DN_EXP_THREAD HRESULT destroy_event(EVENT *pevt)
Destroys a event object.
Definition: dn_thread.c:251
#define THRET
_DN_EXP_THREAD HRESULT set_event(EVENT *pevt)
Sets a event.
Definition: dn_thread.c:295
int EVENT
_DN_EXP_THREAD uint32_t gettimeofday_msec()
Gets the current time value [ms].
Definition: dn_thread.c:589
#define _DN_EXP_THREAD
Definition: dn_thread.h:39
_DN_EXP_THREAD HRESULT release_mutex(MUTEX *pmutex)
Releases mutex handle.
Definition: dn_thread.c:108
_DN_EXP_THREAD HRESULT initialize_mutex(MUTEX *pmutex)
Initializes mutex handle.
Definition: dn_thread.c:80
_DN_EXP_THREAD HRESULT reset_event(EVENT *pevt)
Resets a event.
Definition: dn_thread.c:328


bcap_core
Author(s): DENSO WAVE INCORPORATED
autogenerated on Mon Jun 10 2019 13:12:20