static void
ngx_http_file_cache_lock_wait_handler(ngx_event_t *ev)
{
    ngx_uint_t                 wait;
    ngx_msec_t                 now, timer;
    ngx_http_cache_t          *c;
    ngx_http_request_t        *r;
    ngx_http_file_cache_t     *cache;

    r = ev->data;
    c = r->cache;

    now = ngx_current_msec;

    ngx_log_debug2(NGX_LOG_DEBUG_HTTP, ev->log, 0,
                   "http file cache wait handler wt:%M cur:%M",
                   c->wait_time, now);

    timer = c->wait_time - now;

    if ((ngx_msec_int_t) timer <= 0) {
        ngx_log_error(NGX_LOG_INFO, ev->log, 0, "cache lock timeout");
        c->lock_timeout = 0;
        goto wakeup;
    }

    cache = c->file_cache;
    wait = 0;

    ngx_shmtx_lock(&cache->shpool->mutex);

    timer = c->node->lock_time - now;

    if (c->node->updating && (ngx_msec_int_t) timer > 0) {
        wait = 1;
    }

    ngx_shmtx_unlock(&cache->shpool->mutex);

    if (wait) {
        ngx_add_timer(ev, (timer > 500) ? 500 : timer);
        return;
    }

wakeup:

    c->waiting = 0;
    r->main->blocked--;
    r->connection->write->handler(r->connection->write);
}