A one try more to fix the bug with events ignoring reported by Anikeev
Showing
2 changed files
with
18 additions
and
13 deletions
@@ -30,7 +30,7 @@ | @@ -30,7 +30,7 @@ | ||
30 | 30 | ||
31 | extern void _critical( const char *const function_name, const char *fmt, ...); | 31 | extern void _critical( const char *const function_name, const char *fmt, ...); |
32 | #define critical(...) _critical(__FUNCTION__, __VA_ARGS__) | 32 | #define critical(...) _critical(__FUNCTION__, __VA_ARGS__) |
33 | -#define critical_on(cond) {if (unlikely(cond)) {critical("Assert: "TOSTR(cond));}} | 33 | +#define critical_on(cond) {debug(30, "%s", TOSTR(cond)); if (unlikely(cond)) {critical("Assert: "TOSTR(cond));}} |
34 | 34 | ||
35 | extern void _error(const char *const function_name, const char *fmt, ...); | 35 | extern void _error(const char *const function_name, const char *fmt, ...); |
36 | #define error(...) _error(__FUNCTION__, __VA_ARGS__) | 36 | #define error(...) _error(__FUNCTION__, __VA_ARGS__) |
@@ -49,8 +49,11 @@ extern void _info(const char *const function_name, const char *fmt, ...); | @@ -49,8 +49,11 @@ extern void _info(const char *const function_name, const char *fmt, ...); | ||
49 | #else | 49 | #else |
50 | # define debug(debug_level, ...) {} | 50 | # define debug(debug_level, ...) {} |
51 | # define error_or_debug(debug_level, ...) ((debug_level)<0 ? _error(__FUNCTION__, __VA_ARGS__) : (void)0) | 51 | # define error_or_debug(debug_level, ...) ((debug_level)<0 ? _error(__FUNCTION__, __VA_ARGS__) : (void)0) |
52 | + | ||
52 | #endif | 53 | #endif |
53 | 54 | ||
55 | +#define debug_call(debug_level, code) debug(debug_level, "%s -> %i", TOSTR(code), code) | ||
56 | + | ||
54 | #define critical_or_warning(cond, ...) ((cond) ? _critical : _warning)(__FUNCTION__, __VA_ARGS__) | 57 | #define critical_or_warning(cond, ...) ((cond) ? _critical : _warning)(__FUNCTION__, __VA_ARGS__) |
55 | 58 | ||
56 | extern void error_init(void *_outputmethod, int *_quiet, int *_verbose, int *_debug); | 59 | extern void error_init(void *_outputmethod, int *_quiet, int *_verbose, int *_debug); |
@@ -196,6 +196,7 @@ int gio_add_watch_dir(ctx_t *ctx_p, indexes_t *indexes_p, const char *const accp | @@ -196,6 +196,7 @@ int gio_add_watch_dir(ctx_t *ctx_p, indexes_t *indexes_p, const char *const accp | ||
196 | return fmdat->handle_id; | 196 | return fmdat->handle_id; |
197 | } | 197 | } |
198 | 198 | ||
199 | +int cancel_g_iteration_stop; | ||
199 | pthread_t thread_g_iteration_stop; | 200 | pthread_t thread_g_iteration_stop; |
200 | void *g_iteration_stop(void *_timeout_p) { | 201 | void *g_iteration_stop(void *_timeout_p) { |
201 | struct timeval *timeout_p = _timeout_p; | 202 | struct timeval *timeout_p = _timeout_p; |
@@ -203,6 +204,10 @@ void *g_iteration_stop(void *_timeout_p) { | @@ -203,6 +204,10 @@ void *g_iteration_stop(void *_timeout_p) { | ||
203 | struct timespec ts_abs; | 204 | struct timespec ts_abs; |
204 | debug(10, "{%u, %u}", timeout_p->tv_sec, timeout_p->tv_usec); | 205 | debug(10, "{%u, %u}", timeout_p->tv_sec, timeout_p->tv_usec); |
205 | critical_on (pthread_mutex_lock(&gio_mutex_prefetcher)); | 206 | critical_on (pthread_mutex_lock(&gio_mutex_prefetcher)); |
207 | + if (cancel_g_iteration_stop) { | ||
208 | + critical_on (pthread_mutex_unlock(&gio_mutex_prefetcher)); | ||
209 | + return NULL; | ||
210 | + } | ||
206 | 211 | ||
207 | #define INFINITETIME (3600 * 24 * 365 * 10) /* ~10 years */ | 212 | #define INFINITETIME (3600 * 24 * 365 * 10) /* ~10 years */ |
208 | if (timeout_p->tv_sec > INFINITETIME) | 213 | if (timeout_p->tv_sec > INFINITETIME) |
@@ -249,6 +254,7 @@ static inline int gio_wait_now(ctx_t *ctx_p, struct indexes *indexes_p, struct t | @@ -249,6 +254,7 @@ static inline int gio_wait_now(ctx_t *ctx_p, struct indexes *indexes_p, struct t | ||
249 | return queue_length; | 254 | return queue_length; |
250 | } | 255 | } |
251 | 256 | ||
257 | + cancel_g_iteration_stop = 0; | ||
252 | pthread_create(&thread_g_iteration_stop, NULL, g_iteration_stop, tv_p); | 258 | pthread_create(&thread_g_iteration_stop, NULL, g_iteration_stop, tv_p); |
253 | /* | 259 | /* |
254 | debug(30, "pthread_spin_unlock(&queue_lock);"); | 260 | debug(30, "pthread_spin_unlock(&queue_lock);"); |
@@ -263,20 +269,16 @@ static inline int gio_wait_now(ctx_t *ctx_p, struct indexes *indexes_p, struct t | @@ -263,20 +269,16 @@ static inline int gio_wait_now(ctx_t *ctx_p, struct indexes *indexes_p, struct t | ||
263 | return queue_length; | 269 | return queue_length; |
264 | } | 270 | } |
265 | */ | 271 | */ |
266 | - debug(30, "pthread_spin_unlock(&queue_lock);"); | 272 | + debug_call (40, pthread_spin_unlock(&queue_lock)); |
267 | - pthread_spin_unlock(&queue_lock); | ||
268 | - sleep(1); | ||
269 | debug(20 , "g_main_context_iteration(NULL, TRUE); queue_length == %i", queue_length); | 273 | debug(20 , "g_main_context_iteration(NULL, TRUE); queue_length == %i", queue_length); |
270 | result = g_main_context_iteration(NULL, TRUE); | 274 | result = g_main_context_iteration(NULL, TRUE); |
271 | debug(10, "g_main_context_iteration() -> %i", result); | 275 | debug(10, "g_main_context_iteration() -> %i", result); |
272 | - debug(30, "pthread_spin_lock(&queue_lock);"); | 276 | + debug_call (40, pthread_spin_lock(&queue_lock)); |
273 | - pthread_spin_lock(&queue_lock); | ||
274 | - debug(20 , "pthread_mutex_lock(&gio_mutex_prefetcher);") | ||
275 | critical_on (pthread_mutex_lock(&gio_mutex_prefetcher)); | 277 | critical_on (pthread_mutex_lock(&gio_mutex_prefetcher)); |
276 | - debug(20 , "pthread_mutex_unlock(&gio_mutex_prefetcher);") | 278 | + cancel_g_iteration_stop = 1; |
277 | - pthread_mutex_unlock(&gio_mutex_prefetcher); | 279 | + critical_on (pthread_mutex_unlock(&gio_mutex_prefetcher)); |
278 | - pthread_cond_broadcast(&gio_cond_gotevent); | 280 | + critical_on (pthread_cond_broadcast(&gio_cond_gotevent)); |
279 | - pthread_join(thread_g_iteration_stop, &ret); | 281 | + critical_on (pthread_join(thread_g_iteration_stop, &ret)); |
280 | 282 | ||
281 | debug(9, "queue_length == %i", queue_length); | 283 | debug(9, "queue_length == %i", queue_length); |
282 | return queue_length; | 284 | return queue_length; |
@@ -285,10 +287,10 @@ int gio_wait(ctx_t *ctx_p, struct indexes *indexes_p, struct timeval *tv_p) { | @@ -285,10 +287,10 @@ int gio_wait(ctx_t *ctx_p, struct indexes *indexes_p, struct timeval *tv_p) { | ||
285 | int ret; | 287 | int ret; |
286 | 288 | ||
287 | debug(30, "pthread_spin_lock(&queue_lock);"); | 289 | debug(30, "pthread_spin_lock(&queue_lock);"); |
288 | - pthread_spin_lock(&queue_lock); | 290 | + debug_call (40, pthread_spin_lock(&queue_lock)); |
289 | ret = gio_wait_now(ctx_p, indexes_p, tv_p); | 291 | ret = gio_wait_now(ctx_p, indexes_p, tv_p); |
290 | debug(30, "pthread_spin_unlock(&queue_lock);"); | 292 | debug(30, "pthread_spin_unlock(&queue_lock);"); |
291 | - pthread_spin_unlock(&queue_lock); | 293 | + debug_call (40, pthread_spin_unlock(&queue_lock)); |
292 | 294 | ||
293 | return ret; | 295 | return ret; |
294 | } | 296 | } |
-
Please register or login to post a comment