339 struct timespec rqtp;
340
341 if (count == 1) {
342 busy->total = 0;
343 busy->sec = 2;
344 }
345 if (busy->total > 1000 * busy->sec) {
346 idmapdlog(LOG_DEBUG,
347 "Thread %d waited %d sec for the %s database",
348 pthread_self(), busy->sec, busy->name);
349 busy->sec++;
350 }
351
352 if (count <= busy->delay_size) {
353 delay = busy->delays[count-1];
354 } else {
355 delay = busy->delays[busy->delay_size - 1];
356 }
357 busy->total += delay;
358 rqtp.tv_sec = 0;
359 rqtp.tv_nsec = delay * (NANOSEC / MILLISEC);
360 (void) nanosleep(&rqtp, NULL);
361 return (1);
362 }
363
364
365 /*
366 * Get the database handle
367 */
368 idmap_retcode
369 get_db_handle(sqlite **db)
370 {
371 char *errmsg;
372 idmap_tsd_t *tsd;
373
374 /*
375 * Retrieve the db handle from thread-specific storage
376 * If none exists, open and store in thread-specific storage.
377 */
378 if ((tsd = idmap_get_tsd()) == NULL) {
379 idmapdlog(LOG_ERR,
|
339 struct timespec rqtp;
340
341 if (count == 1) {
342 busy->total = 0;
343 busy->sec = 2;
344 }
345 if (busy->total > 1000 * busy->sec) {
346 idmapdlog(LOG_DEBUG,
347 "Thread %d waited %d sec for the %s database",
348 pthread_self(), busy->sec, busy->name);
349 busy->sec++;
350 }
351
352 if (count <= busy->delay_size) {
353 delay = busy->delays[count-1];
354 } else {
355 delay = busy->delays[busy->delay_size - 1];
356 }
357 busy->total += delay;
358 rqtp.tv_sec = 0;
359 rqtp.tv_nsec = MSEC2NSEC(delay);
360 (void) nanosleep(&rqtp, NULL);
361 return (1);
362 }
363
364
365 /*
366 * Get the database handle
367 */
368 idmap_retcode
369 get_db_handle(sqlite **db)
370 {
371 char *errmsg;
372 idmap_tsd_t *tsd;
373
374 /*
375 * Retrieve the db handle from thread-specific storage
376 * If none exists, open and store in thread-specific storage.
377 */
378 if ((tsd = idmap_get_tsd()) == NULL) {
379 idmapdlog(LOG_ERR,
|