[Groonga-commit] groonga/groonga at e1e00de [master] array: remove queue support

Back to archive index

Kouhei Sutou null+****@clear*****
Tue Jan 30 12:30:58 JST 2018


Kouhei Sutou	2018-01-30 12:30:58 +0900 (Tue, 30 Jan 2018)

  New Revision: e1e00de51aef3705830d835194dbda4825898817
  https://github.com/groonga/groonga/commit/e1e00de51aef3705830d835194dbda4825898817

  Message:
    array: remove queue support

  Modified files:
    lib/db.c
    lib/grn_hash.h
    lib/hash.c

  Modified: lib/db.c (+0 -2)
===================================================================
--- lib/db.c    2018-01-30 11:37:34 +0900 (19cd4c74a)
+++ lib/db.c    2018-01-30 12:30:58 +0900 (11c47b25b)
@@ -11443,8 +11443,6 @@ grn_obj_clear_lock(grn_ctx *ctx, grn_obj *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 :

  Modified: lib/grn_hash.h (+0 -22)
===================================================================
--- lib/grn_hash.h    2018-01-30 11:37:34 +0900 (cad46cbc2)
+++ lib/grn_hash.h    2018-01-30 12:30:58 +0900 (6547394b5)
@@ -170,28 +170,6 @@ 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);
 
-/* 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;
-  grn_bool unblock_requested;
-};
-
-GRN_API void grn_array_queue_lock_clear(grn_ctx *ctx, grn_array *array);
-GRN_API void grn_array_clear_curr_rec(grn_ctx *ctx, grn_array *array);
-GRN_API grn_table_queue *grn_array_queue(grn_ctx *ctx, grn_array *array);
-GRN_API uint32_t grn_table_queue_size(grn_table_queue *queue);
-GRN_API void grn_table_queue_head_increment(grn_table_queue *queue);
-GRN_API void grn_table_queue_tail_increment(grn_table_queue *queue);
-GRN_API grn_id grn_table_queue_head(grn_table_queue *queue);
-GRN_API grn_id grn_table_queue_tail(grn_table_queue *queue);
-
 /**** grn_hash ****/
 
 #define GRN_HASH_MAX_KEY_SIZE_NORMAL GRN_TABLE_MAX_KEY_SIZE

  Modified: lib/hash.c (+0 -169)
===================================================================
--- lib/hash.c    2018-01-30 11:37:34 +0900 (d4de4201b)
+++ lib/hash.c    2018-01-30 12:30:58 +0900 (74fab5b42)
@@ -321,82 +321,6 @@ grn_io_array_bit_flip(grn_ctx *ctx, grn_io *io,
   return ptr;
 }
 
-/* grn_table_queue */
-
-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_lock_fin(grn_ctx *ctx, grn_table_queue *queue)
-{
-  COND_FIN(queue->cond);
-  MUTEX_FIN(queue->mutex);
-}
-
-static void
-grn_table_queue_init(grn_ctx *ctx, grn_table_queue *queue)
-{
-  queue->head = 0;
-  queue->tail = 0;
-  queue->cap = GRN_ARRAY_MAX;
-  queue->unblock_requested = GRN_FALSE;
-  grn_table_queue_lock_init(ctx, queue);
-}
-
-static void
-grn_table_queue_fin(grn_ctx *ctx, grn_table_queue *queue)
-{
-  grn_table_queue_lock_fin(ctx, queue);
-}
-
-uint32_t
-grn_table_queue_size(grn_table_queue *queue)
-{
-  return (queue->head < queue->tail)
-    ? 2 * queue->cap + queue->head - queue->tail
-    : queue->head - queue->tail;
-}
-
-void
-grn_table_queue_head_increment(grn_table_queue *queue)
-{
-  if (queue->head == 2 * queue->cap) {
-    queue->head = 1;
-  } else {
-    queue->head++;
-  }
-}
-
-void
-grn_table_queue_tail_increment(grn_table_queue *queue)
-{
-  if (queue->tail == 2 * queue->cap) {
-    queue->tail = 1;
-  } else {
-    queue->tail++;
-  }
-}
-
-grn_id
-grn_table_queue_head(grn_table_queue *queue)
-{
-  return queue->head > queue->cap
-    ? queue->head - queue->cap
-    : queue->head;
-}
-
-grn_id
-grn_table_queue_tail(grn_table_queue *queue)
-{
-  return queue->tail > queue->cap
-    ? queue->tail - queue->cap
-    : queue->tail;
-}
-
 /* grn_array */
 
 #define GRN_ARRAY_SEGMENT_SIZE 0x400000
@@ -412,7 +336,6 @@ struct grn_array_header {
   uint32_t lock;
   uint32_t truncated;
   uint32_t reserved[8];
-  grn_table_queue queue;
 };
 
 /*
@@ -525,7 +448,6 @@ grn_array_init_io_array(grn_ctx *ctx, grn_array *array, const char *path,
   header->n_garbages = 0;
   header->garbages = GRN_ID_NIL;
   header->truncated = GRN_FALSE;
-  grn_table_queue_init(ctx, &header->queue);
   array->obj.header.flags = flags;
   array->ctx = ctx;
   array->value_size = value_size;
@@ -539,26 +461,6 @@ 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);
-}
-
-grn_table_queue *
-grn_array_queue(grn_ctx *ctx, grn_array *array)
-{
-  if (grn_array_is_io_array(array)) {
-    struct grn_array_header *header;
-    header = grn_io_header(array->io);
-    return &header->queue;
-  } else {
-    return NULL;
-  }
-}
-
 static grn_rc
 grn_array_init(grn_ctx *ctx, grn_array *array,
                const char *path, uint32_t value_size, uint32_t flags)
@@ -652,7 +554,6 @@ grn_array_close(grn_ctx *ctx, grn_array *array)
   if (!ctx || !array) { return GRN_INVALID_ARGUMENT; }
   if (array->keys) { GRN_FREE(array->keys); }
   if (grn_array_is_io_array(array)) {
-    /* grn_table_queue_fin(ctx, &array->header->queue); */
     rc = grn_io_close(ctx, array->io);
   } else {
     GRN_ASSERT(ctx == array->ctx);
@@ -1187,76 +1088,6 @@ grn_array_add(grn_ctx *ctx, grn_array *array, void **value)
   return GRN_ID_NIL;
 }
 
-grn_id
-grn_array_push(grn_ctx *ctx, grn_array *array,
-               void (*func)(grn_ctx *, grn_array *, grn_id, void *),
-               void *func_arg)
-{
-  grn_id id = GRN_ID_NIL;
-  grn_table_queue *queue = grn_array_queue(ctx, array);
-  if (queue) {
-    MUTEX_LOCK(queue->mutex);
-    if (grn_table_queue_head(queue) == queue->cap) {
-      grn_array_clear_curr_rec(ctx, array);
-    }
-    id = grn_array_add(ctx, array, NULL);
-    if (func) {
-      func(ctx, array, id, func_arg);
-    }
-    if (grn_table_queue_size(queue) == queue->cap) {
-      grn_table_queue_tail_increment(queue);
-    }
-    grn_table_queue_head_increment(queue);
-    COND_SIGNAL(queue->cond);
-    MUTEX_UNLOCK(queue->mutex);
-  } else {
-    ERR(GRN_OPERATION_NOT_SUPPORTED, "only persistent arrays support push");
-  }
-  return id;
-}
-
-grn_id
-grn_array_pull(grn_ctx *ctx, grn_array *array, grn_bool blockp,
-               void (*func)(grn_ctx *, grn_array *, grn_id, void *),
-               void *func_arg)
-{
-  grn_id id = GRN_ID_NIL;
-  grn_table_queue *queue = grn_array_queue(ctx, array);
-  if (queue) {
-    MUTEX_LOCK(queue->mutex);
-    queue->unblock_requested = GRN_FALSE;
-    while (grn_table_queue_size(queue) == 0) {
-      if (!blockp || queue->unblock_requested) {
-        MUTEX_UNLOCK(queue->mutex);
-        GRN_OUTPUT_BOOL(0);
-        return id;
-      }
-      COND_WAIT(queue->cond, queue->mutex);
-    }
-    grn_table_queue_tail_increment(queue);
-    id = grn_table_queue_tail(queue);
-    if (func) {
-      func(ctx, array, id, func_arg);
-    }
-    MUTEX_UNLOCK(queue->mutex);
-  } else {
-    ERR(GRN_OPERATION_NOT_SUPPORTED, "only persistent arrays support pull");
-  }
-  return id;
-}
-
-void
-grn_array_unblock(grn_ctx *ctx, grn_array *array)
-{
-  grn_table_queue *queue = grn_array_queue(ctx, array);
-  if (!queue) {
-    return;
-  }
-
-  queue->unblock_requested = GRN_TRUE;
-  COND_BROADCAST(queue->cond);
-}
-
 /* grn_hash : hash table */
 
 #define GRN_HASH_MAX_SEGMENT  0x400
-------------- next part --------------
HTML����������������������������...
URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20180130/0a087aaa/attachment-0001.htm 



More information about the Groonga-commit mailing list
Back to archive index