| 4340 | |
| 4341 | |
| 4342 | static int keycache_pthread_cond_wait(mysql_cond_t *cond, |
| 4343 | mysql_mutex_t *mutex) |
| 4344 | { |
| 4345 | int rc; |
| 4346 | struct timeval now; /* time when we started waiting */ |
| 4347 | struct timespec timeout; /* timeout value for the wait function */ |
| 4348 | struct timezone tz; |
| 4349 | #if defined(KEYCACHE_DEBUG) |
| 4350 | int cnt=0; |
| 4351 | #endif |
| 4352 | |
| 4353 | /* Get current time */ |
| 4354 | gettimeofday(&now, &tz); |
| 4355 | /* Prepare timeout value */ |
| 4356 | timeout.tv_sec= now.tv_sec + KEYCACHE_TIMEOUT; |
| 4357 | /* |
| 4358 | timeval uses microseconds. |
| 4359 | timespec uses nanoseconds. |
| 4360 | 1 nanosecond = 1000 micro seconds |
| 4361 | */ |
| 4362 | timeout.tv_nsec= now.tv_usec * 1000; |
| 4363 | KEYCACHE_THREAD_TRACE_END("started waiting"); |
| 4364 | #if defined(KEYCACHE_DEBUG) |
| 4365 | cnt++; |
| 4366 | if (cnt % 100 == 0) |
| 4367 | fprintf(keycache_debug_log, "waiting...\n"); |
| 4368 | fflush(keycache_debug_log); |
| 4369 | #endif |
| 4370 | rc= mysql_cond_timedwait(cond, mutex, &timeout); |
| 4371 | KEYCACHE_THREAD_TRACE_BEGIN("finished waiting"); |
| 4372 | if (rc == ETIMEDOUT || rc == ETIME) |
| 4373 | { |
| 4374 | #if defined(KEYCACHE_DEBUG) |
| 4375 | fprintf(keycache_debug_log,"aborted by keycache timeout\n"); |
| 4376 | fclose(keycache_debug_log); |
| 4377 | abort(); |
| 4378 | #endif |
| 4379 | keycache_dump(); |
| 4380 | } |
| 4381 | |
| 4382 | #if defined(KEYCACHE_DEBUG) |
| 4383 | KEYCACHE_DBUG_ASSERT(rc != ETIMEDOUT); |
| 4384 | #else |
| 4385 | assert(rc != ETIMEDOUT); |
| 4386 | #endif |
| 4387 | return rc; |
| 4388 | } |
| 4389 | #else |
| 4390 | #if defined(KEYCACHE_DEBUG) |
| 4391 | static int keycache_pthread_cond_wait(mysql_cond_t *cond, |
no test coverage detected