null+****@clear*****
null+****@clear*****
2012年 6月 14日 (木) 18:17:34 JST
Daijiro MORI 2012-06-14 18:17:34 +0900 (Thu, 14 Jun 2012) New Revision: 9c14f18118c9f5ae3f1974d3b6258e2402766979 Log: table: add grn_table_queue stuff. Modified files: lib/db.c lib/groonga_in.h lib/hash.c lib/hash.h Modified: lib/db.c (+3 -1) =================================================================== --- lib/db.c 2012-06-14 00:30:07 +0900 (e590de1) +++ lib/db.c 2012-06-14 18:17:34 +0900 (7a2a1ed) @@ -7366,10 +7366,12 @@ grn_obj_clear_lock(grn_ctx *ctx, grn_obj *obj) } grn_io_clear_lock(grn_obj_io(obj)); break; + case GRN_TABLE_NO_KEY : + grn_array_queue_lock_clear(ctx, (grn_array *)obj); + /* fallthru */ case GRN_TABLE_HASH_KEY : case GRN_TABLE_PAT_KEY : case GRN_TABLE_DAT_KEY : - case GRN_TABLE_NO_KEY : { grn_hash *cols; if ((cols = grn_hash_create(ctx, NULL, sizeof(grn_id), 0, Modified: lib/groonga_in.h (+13 -0) =================================================================== --- lib/groonga_in.h 2012-06-14 00:30:07 +0900 (5c09d56) +++ lib/groonga_in.h 2012-06-14 18:17:34 +0900 (aacab6e) @@ -263,6 +263,13 @@ typedef pthread_mutex_t grn_mutex; #define MUTEX_LOCK(m) pthread_mutex_lock(&m) #define MUTEX_UNLOCK(m) pthread_mutex_unlock(&m) #define MUTEX_FIN(m) +#define MUTEX_INIT_SHARED(m) do {\ + pthread_mutexattr_t mutexattr;\ + pthread_mutexattr_init(&mutexattr);\ + pthread_mutexattr_setpshared(&mutexattr, PTHREAD_PROCESS_SHARED);\ + pthread_mutex_init(&m, &mutexattr);\ +} while (0) + typedef pthread_mutex_t grn_critical_section; #define CRITICAL_SECTION_INIT(cs) pthread_mutex_init(&(cs), NULL) #define CRITICAL_SECTION_ENTER(cs) pthread_mutex_lock(&(cs)) @@ -273,6 +280,12 @@ typedef pthread_cond_t grn_cond; #define COND_INIT(c) pthread_cond_init(&c, NULL) #define COND_SIGNAL(c) pthread_cond_signal(&c) #define COND_WAIT(c,m) pthread_cond_wait(&c, &m) +#define COND_INIT_SHARED(c) do {\ + pthread_condattr_t condattr;\ + pthread_condattr_init(&condattr);\ + pthread_condattr_setpshared(&condattr, PTHREAD_PROCESS_SHARED);\ + pthread_cond_init(&c, &condattr);\ +} while (0) typedef pthread_key_t grn_thread_key; #define THREAD_KEY_CREATE(key, destr) pthread_key_create(key, destr) Modified: lib/hash.c (+39 -3) =================================================================== --- lib/hash.c 2012-06-14 00:30:07 +0900 (d968ebe) +++ lib/hash.c 2012-06-14 18:17:34 +0900 (e0d0cfc) @@ -318,9 +318,36 @@ grn_io_array_bit_flip(grn_ctx *ctx, grn_io *io, return ptr; } +/* grn_table_queue */ + +typedef struct _grn_table_queue grn_table_queue; + +struct _grn_table_queue { + grn_mutex mutex; + grn_cond cond; + grn_id head; + grn_id tail; + grn_id cap; +}; + +static void +grn_table_queue_lock_init(grn_ctx *ctx, grn_table_queue *queue) +{ + MUTEX_INIT_SHARED(queue->mutex); + COND_INIT_SHARED(queue->cond); +} + +static void +grn_table_queue_init(grn_ctx *ctx, grn_table_queue *queue) +{ + queue->head = 0; + queue->tail = 0; + queue->cap = GRN_ID_MAX; + grn_table_queue_lock_init(ctx, queue); +} + /* grn_array */ -#define GRN_ARRAY_HEADER_SIZE 0x9000 #define GRN_ARRAY_SEGMENT_SIZE 0x400000 /* Header of grn_io-based grn_array. */ @@ -332,7 +359,8 @@ struct grn_array_header { uint32_t n_garbages; grn_id garbages; uint32_t lock; - uint32_t reserved[5]; + uint32_t reserved[9]; + grn_table_queue queue; }; /* @@ -443,7 +471,7 @@ grn_array_init_io_array(grn_ctx *ctx, grn_array *array, const char *path, header->n_entries = 0; header->n_garbages = 0; header->garbages = GRN_ID_NIL; - + grn_table_queue_init(ctx, &header->queue); array->obj.header.flags = flags; array->ctx = ctx; array->value_size = value_size; @@ -457,6 +485,14 @@ grn_array_init_io_array(grn_ctx *ctx, grn_array *array, const char *path, return GRN_SUCCESS; } +void +grn_array_queue_lock_clear(grn_ctx *ctx, grn_array *array) +{ + struct grn_array_header *header; + header = grn_io_header(array->io); + grn_table_queue_lock_init(ctx, &header->queue); +} + static grn_rc grn_array_init(grn_ctx *ctx, grn_array *array, const char *path, uint32_t value_size, uint32_t flags) Modified: lib/hash.h (+1 -0) =================================================================== --- lib/hash.h 2012-06-14 00:30:07 +0900 (1994e6e) +++ lib/hash.h 2012-06-14 18:17:34 +0900 (03f00f2) @@ -166,6 +166,7 @@ struct _grn_array_cursor { grn_rc grn_array_truncate(grn_ctx *ctx, grn_array *array); grn_rc grn_array_copy_sort_key(grn_ctx *ctx, grn_array *array, grn_table_sort_key *keys, int n_keys); +void grn_array_queue_lock_clear(grn_ctx *ctx, grn_array *array); /**** grn_hash ****/