null+****@clear*****
null+****@clear*****
2012年 5月 8日 (火) 13:00:41 JST
Susumu Yata 2012-05-08 13:00:41 +0900 (Tue, 08 May 2012) New Revision: d8b01a4e20b9045d6e66f719ee4fb4fa70bac868 Log: Replace sleep/usleep() with grn_sleep/nanosleep(). Modified files: lib/groonga_in.h lib/hash.c lib/io.c src/grnslap.c src/groonga.c src/groonga_benchmark.c Modified: lib/groonga_in.h (+3 -3) =================================================================== --- lib/groonga_in.h 2012-05-08 12:55:56 +0900 (cb907a4) +++ lib/groonga_in.h 2012-05-08 13:00:41 +0900 (8279a07) @@ -308,7 +308,7 @@ typedef pthread_key_t grn_thread_key; while ((((++grn_uyield_count) & (0x100 - 1)) != 0 || (sched_yield() * 0) == 0) && (while_cond)) #if !defined(_POSIX_PRIORITY_SCHEDULING) - #define sched_yield() usleep(1000 * 20) + #define sched_yield() grn_nanosleep(1000000 * 20) #endif #else /* USE_UYIELD */ #define GRN_TEST_YIELD() do {} while (0) @@ -383,7 +383,7 @@ typedef int grn_cond; #define COND_SIGNAL(c) #define COND_WAIT(c,m) do { \ MUTEX_UNLOCK(m); \ - usleep(1000); \ + grn_nanosleep(1000000); \ MUTEX_LOCK(m); \ } while (0) /* todo : must be enhanced! */ @@ -645,7 +645,7 @@ grn_str_greater(const uint8_t *ap, uint32_t as, const uint8_t *bp, uint32_t bs) #define GRN_FUTEX_WAKE(p) syscall(SYS_futex, p, FUTEX_WAKE, 1) #else /* USE_FUTEX */ -#define GRN_FUTEX_WAIT(p) usleep(1000) +#define GRN_FUTEX_WAIT(p) grn_nanosleep(1000000) #define GRN_FUTEX_WAKE(p) #endif /* USE_FUTEX */ Modified: lib/hash.c (+1 -1) =================================================================== --- lib/hash.c 2012-05-08 12:55:56 +0900 (f4a52b3) +++ lib/hash.c 2012-05-08 13:00:41 +0900 (d968ebe) @@ -1821,7 +1821,7 @@ grn_hash_lock(grn_ctx *ctx, grn_hash *hash, int timeout) GRN_LOG(ctx, GRN_LOG_NOTICE, "hash(%p) collisions(%d/%d)", hash, _ncolls, _ncalls); } } - usleep(1000); + grn_nanosleep(1000000); continue; } return GRN_SUCCESS; Modified: lib/io.c (+2 -2) =================================================================== --- lib/io.c 2012-05-08 12:55:56 +0900 (e19a79b) +++ lib/io.c 2012-05-08 13:00:41 +0900 (c416235) @@ -1067,7 +1067,7 @@ retry: nent = cl; /* number of iw */ cl = 0; count = 0; - usleep(1); + grn_nanosleep(1000); goto retry; } else dp("-- No Reading state CacheData. --\n"); @@ -1476,7 +1476,7 @@ grn_io_lock(grn_ctx *ctx, grn_io *io, int timeout) "io(%s) collisions(%d/%d)", io->path, _ncolls, _ncalls); } } - usleep(1000); + grn_nanosleep(1000000); continue; } return GRN_SUCCESS; Modified: src/grnslap.c (+1 -1) =================================================================== --- src/grnslap.c 2012-05-08 12:55:56 +0900 (7eb20d3) +++ src/grnslap.c 2012-05-08 13:00:41 +0900 (afe26bc) @@ -280,7 +280,7 @@ do_client() if ((nrecv < max_tp * (tve.tv_sec - tvb.tv_sec)) && (nsent - nrecv) < max_con) { break; } /* lprint(ctx, "s:%d r:%d", nsent, nrecv); */ - usleep(1000); + grn_nanosleep(1000000); } if (!(nsent % 1000)) { lprint(ctx, " : %d", nsent); } } Modified: src/groonga.c (+1 -1) =================================================================== --- src/groonga.c 2012-05-08 12:55:56 +0900 (8a0792c) +++ src/groonga.c 2012-05-08 13:00:41 +0900 (67a4706) @@ -918,7 +918,7 @@ run_server_loop(grn_ctx *ctx, grn_com_event *ev) MUTEX_LOCK(q_mutex); if (nthreads == nfthreads) { break; } MUTEX_UNLOCK(q_mutex); - usleep(1000); + grn_nanosleep(1000000); } { grn_edge *edge; Modified: src/groonga_benchmark.c (+1 -1) =================================================================== --- src/groonga_benchmark.c 2012-05-08 12:55:56 +0900 (b4bff19) +++ src/groonga_benchmark.c 2012-05-08 13:00:41 +0900 (f0c10e2) @@ -2141,7 +2141,7 @@ check_server(grn_ctx *ctx) while (1) { ret = grn_ctx_connect(ctx, grntest_serverhost, grntest_serverport, 0); if (ret == GRN_CONNECTION_REFUSED) { - sleep(1); + grn_sleep(1); retry++; if (retry > 5) { fprintf(stderr, "Cannot connect groonga server:host=%s:port=%d:ret=%d\n",