isomorfeus-ferret 0.13.3 → 0.13.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 958c051fa7f771e25ee1fb29c47aad9ab1cd7a570750f73450ae582474ef6fb5
4
- data.tar.gz: beba6b22ba7493f324be38997fee4f4a56efc896281fcbb2f3521ebef6795029
3
+ metadata.gz: 524b384c2ab35457603726287160b443a50939473bab7852e5e6f5f886ded0a7
4
+ data.tar.gz: b304d0386bc0b14e68167bfcc1b62346f81c02f6eff25c3a6633bb0a1919083e
5
5
  SHA512:
6
- metadata.gz: 98bef5c79e3d4e8854d6a4cb68e2cb796c6f27bbaf1c7b7669ab895e8656d12d033651f8d8b29ac8d7504b46dba7567aa52f2ac297285ff2c6c62e52c48d0019
7
- data.tar.gz: 165497f356ab32cdc6250b3eada43d9ec36d61ee992114bffa9c38372c7894455caeb95aa789cf025c2538c7f9e1eddafe87e66b58536424a4c8e116a123af88
6
+ metadata.gz: b378ce12aa56bb35e57eec2c8df64152a7a7bd5cb1345d4a7dc0264e236fddcea3ffbc41a7213401cf50ff163c3172169fbf93699a4a7f96505f300782bc9a92
7
+ data.tar.gz: 6954e297df285f7726bd925a6f4dda4300f06d059dc4b674a494e775b901f7ea9e529e62be8793049c6df20a17515c41741f63155fbdd661de4595694deb4c27
data/LICENSE CHANGED
@@ -139,32 +139,6 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
139
139
  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
140
140
 
141
141
 
142
- lib/isomorfeus/ferret/monitor.rb originally taken from the gem 'monitor':
143
-
144
- Copyright (C) 1993-2013 Yukihiro Matsumoto. All rights reserved.
145
-
146
- Redistribution and use in source and binary forms, with or without
147
- modification, are permitted provided that the following conditions
148
- are met:
149
-
150
- 1. Redistributions of source code must retain the above copyright notice,
151
- this list of conditions and the following disclaimer.
152
- 2. Redistributions in binary form must reproduce the above copyright notice,
153
- this list of conditions and the following disclaimer in the documentation
154
- and/or other materials provided with the distribution.
155
-
156
- THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND
157
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
158
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
159
- DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
160
- ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
161
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
162
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
163
- ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
164
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
165
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
166
-
167
-
168
142
  The following licenses apply to files, which are distributed within the repo
169
143
  but not distributed with the gem and not used at runtime:
170
144
 
@@ -117,13 +117,13 @@ static void bm_single_run(BenchMarkUnit *unit, BenchMarkTimes *bm_times)
117
117
  struct rusage ru_before, ru_after;
118
118
 
119
119
  if (gettimeofday(&tv_before, NULL) == -1)
120
- FRT_RAISE(FRT_UNSUPPORTED_ERROR, "gettimeofday failed\n");
120
+ rb_raise(rb_eRuntimeError, "gettimeofday failed\n");
121
121
  getrusage(RUSAGE_SELF, &ru_before);
122
122
 
123
123
  unit->run();
124
124
 
125
125
  if (gettimeofday(&tv_after, NULL) == -1)
126
- FRT_RAISE(FRT_UNSUPPORTED_ERROR, "gettimeofday failed\n");
126
+ rb_raise(rb_eRuntimeError, "gettimeofday failed\n");
127
127
  getrusage(RUSAGE_SELF, &ru_after);
128
128
 
129
129
  bm_times->rtime = TVAL_TO_SEC(tv_before, tv_after);
@@ -1271,11 +1271,11 @@ void frb_iw_free(void *p) {
1271
1271
 
1272
1272
  void frb_iw_mark(void *p) {
1273
1273
  FrtIndexWriter *iw = (FrtIndexWriter *)p;
1274
- if (iw->analyzer->ranalyzer)
1274
+ if (iw->analyzer && iw->analyzer->ranalyzer)
1275
1275
  rb_gc_mark(iw->analyzer->ranalyzer);
1276
- if (iw->store->rstore)
1276
+ if (iw->store && iw->store->rstore)
1277
1277
  rb_gc_mark(iw->store->rstore);
1278
- if (iw->fis->rfis)
1278
+ if (iw->fis && iw->fis->rfis)
1279
1279
  rb_gc_mark(iw->fis->rfis);
1280
1280
  }
1281
1281
 
@@ -329,7 +329,7 @@ static void cw_copy_file(FrtCompoundWriter *cw, FrtCWFileEntry *src, FrtOutStrea
329
329
  frt_is_close(is);
330
330
  }
331
331
 
332
- void frt_cw_close(FrtCompoundWriter *cw)
332
+ void frt_cw_close(FrtCompoundWriter *cw, FrtDeleter *dlr)
333
333
  {
334
334
  FrtOutStream *os = NULL;
335
335
  int i;
@@ -356,6 +356,9 @@ void frt_cw_close(FrtCompoundWriter *cw)
356
356
  for (i = 0; i < frt_ary_size(cw->file_entries); i++) {
357
357
  cw->file_entries[i].data_offset = frt_os_pos(os);
358
358
  cw_copy_file(cw, &cw->file_entries[i], os);
359
+ if (dlr) {
360
+ frt_deleter_queue_file(dlr, cw->file_entries[i].name);
361
+ }
359
362
  }
360
363
 
361
364
  /* Write the data offsets into the directory of the compound stream */
@@ -19,7 +19,6 @@ const char *const ERROR_TYPES[] = {
19
19
  "Lock Error"
20
20
  };
21
21
 
22
- bool frt_x_do_logging = false;
23
22
  bool frt_x_abort_on_exception = true;
24
23
  bool frt_x_has_aborted = false;
25
24
  FILE *frt_x_exception_stream = NULL;
@@ -272,15 +272,13 @@ static const struct FrtOutStreamMethods FS_OUT_STREAM_METHODS = {
272
272
  static FrtOutStream *fs_new_output(FrtStore *store, const char *filename)
273
273
  {
274
274
  char path[FRT_MAX_FILE_PATH];
275
- int fd = open(join_path(path, store->dir.path, filename),
276
- O_WRONLY | O_CREAT | O_BINARY, store->file_mode);
277
- FrtOutStream *os;
275
+ int fd = open(join_path(path, store->dir.path, filename), O_WRONLY | O_CREAT | O_BINARY, store->file_mode);
278
276
  if (fd < 0) {
279
277
  FRT_RAISE(FRT_IO_ERROR, "couldn't create OutStream %s: <%s>",
280
278
  path, strerror(errno));
281
279
  }
282
280
 
283
- os = frt_os_new();
281
+ FrtOutStream *os = frt_os_new();
284
282
  os->file.fd = fd;
285
283
  os->m = &FS_OUT_STREAM_METHODS;
286
284
  return os;
@@ -418,9 +416,7 @@ static void fs_close_lock_i(FrtLock *lock)
418
416
 
419
417
  static FrtHash *stores = NULL;
420
418
 
421
- #ifndef UNTHREADED
422
419
  static frt_mutex_t stores_mutex = FRT_MUTEX_INITIALIZER;
423
- #endif
424
420
 
425
421
  static void fs_close_i(FrtStore *store)
426
422
  {
@@ -266,13 +266,6 @@ extern FILE *frt_x_exception_stream;
266
266
  #define EXCEPTION 2
267
267
  #define EXCEPTION_STREAM (frt_x_exception_stream ? frt_x_exception_stream : stderr)
268
268
 
269
- #ifdef DEBUG
270
- extern bool frt_x_do_logging;
271
- #define xlog if (frt_x_do_logging) printf
272
- #else
273
- #define xlog()
274
- #endif
275
-
276
269
  extern void frt_init(int arc, const char *const argv[]);
277
270
  extern void frt_micro_sleep(const int micro_seconds);
278
271
 
@@ -681,15 +681,13 @@ static char *si_norm_file_name(FrtSegmentInfo *si, char *buf, int field_num)
681
681
  if (field_num >= si->norm_gens_size
682
682
  || 0 > (norm_gen = si->norm_gens[field_num])) {
683
683
  return NULL;
684
- }
685
- else {
684
+ } else {
686
685
  const char *ext = (si->use_compound_file && norm_gen > 0) ? "s" : "f";
687
686
  return fn_for_gen_field(buf, si->name, ext, norm_gen, field_num);
688
687
  }
689
688
  }
690
689
 
691
- static void deleter_queue_file(FrtDeleter *dlr, const char *file_name);
692
- #define DEL(file_name) deleter_queue_file(dlr, file_name)
690
+ void frt_deleter_queue_file(FrtDeleter *dlr, const char *file_name);
693
691
 
694
692
  static void si_delete_files(FrtSegmentInfo *si, FrtFieldInfos *fis, FrtDeleter *dlr)
695
693
  {
@@ -700,7 +698,7 @@ static void si_delete_files(FrtSegmentInfo *si, FrtFieldInfos *fis, FrtDeleter *
700
698
 
701
699
  for (i = si->norm_gens_size - 1; i >= 0; i--) {
702
700
  if (0 <= si->norm_gens[i]) {
703
- DEL(si_norm_file_name(si, file_name, fis->fields[i]->number));
701
+ frt_deleter_queue_file(dlr, si_norm_file_name(si, file_name, fis->fields[i]->number));
704
702
  }
705
703
  }
706
704
 
@@ -710,15 +708,14 @@ static void si_delete_files(FrtSegmentInfo *si, FrtFieldInfos *fis, FrtDeleter *
710
708
 
711
709
  if (si->use_compound_file) {
712
710
  memcpy(ext, "cfs", 4);
713
- DEL(file_name);
711
+ frt_deleter_queue_file(dlr, file_name);
714
712
  if (0 <= si->del_gen) {
715
- DEL(frt_fn_for_generation(file_name, si->name, "del", si->del_gen));
713
+ frt_deleter_queue_file(dlr, frt_fn_for_generation(file_name, si->name, "del", si->del_gen));
716
714
  }
717
- }
718
- else {
715
+ } else {
719
716
  for (i = FRT_NELEMS(INDEX_EXTENSIONS) - 1; i >= 0; i--) {
720
717
  memcpy(ext, INDEX_EXTENSIONS[i], 4);
721
- DEL(file_name);
718
+ frt_deleter_queue_file(dlr, file_name);
722
719
  }
723
720
  }
724
721
  }
@@ -3695,8 +3692,7 @@ static bool file_name_filter_is_cfs_file(const char *file_name) {
3695
3692
  ****************************************************************************/
3696
3693
 
3697
3694
  #define DELETABLE_START_CAPA 8
3698
- FrtDeleter *frt_deleter_new(FrtSegmentInfos *sis, FrtStore *store)
3699
- {
3695
+ FrtDeleter *frt_deleter_new(FrtSegmentInfos *sis, FrtStore *store) {
3700
3696
  FrtDeleter *dlr = FRT_ALLOC(FrtDeleter);
3701
3697
  dlr->sis = sis;
3702
3698
  dlr->store = store;
@@ -3704,19 +3700,16 @@ FrtDeleter *frt_deleter_new(FrtSegmentInfos *sis, FrtStore *store)
3704
3700
  return dlr;
3705
3701
  }
3706
3702
 
3707
- void frt_deleter_destroy(FrtDeleter *dlr)
3708
- {
3703
+ void frt_deleter_destroy(FrtDeleter *dlr) {
3709
3704
  frt_hs_destroy(dlr->pending);
3710
3705
  free(dlr);
3711
3706
  }
3712
3707
 
3713
- static void deleter_queue_file(FrtDeleter *dlr, const char *file_name)
3714
- {
3708
+ void frt_deleter_queue_file(FrtDeleter *dlr, const char *file_name) {
3715
3709
  frt_hs_add(dlr->pending, frt_estrdup(file_name));
3716
3710
  }
3717
3711
 
3718
- void frt_deleter_delete_file(FrtDeleter *dlr, char *file_name)
3719
- {
3712
+ void frt_deleter_delete_file(FrtDeleter *dlr, char *file_name) {
3720
3713
  FrtStore *store = dlr->store;
3721
3714
  FRT_TRY
3722
3715
  if (store->exists(store, file_name)) {
@@ -3728,8 +3721,7 @@ void frt_deleter_delete_file(FrtDeleter *dlr, char *file_name)
3728
3721
  FRT_XENDTRY
3729
3722
  }
3730
3723
 
3731
- static void deleter_commit_pending_deletions(FrtDeleter *dlr)
3732
- {
3724
+ static void deleter_commit_pending_deletions(FrtDeleter *dlr) {
3733
3725
  FrtHashSetEntry *hse, *hse_next = dlr->pending->first;
3734
3726
  while ((hse = hse_next) != NULL) {
3735
3727
  hse_next = hse->next;
@@ -3737,23 +3729,13 @@ static void deleter_commit_pending_deletions(FrtDeleter *dlr)
3737
3729
  }
3738
3730
  }
3739
3731
 
3740
- void frt_deleter_delete_files(FrtDeleter *dlr, char **files, int file_cnt)
3741
- {
3742
- int i;
3743
- for (i = file_cnt - 1; i >= 0; i--) {
3744
- deleter_queue_file(dlr, files[i]);
3745
- }
3746
- deleter_commit_pending_deletions(dlr);
3747
- }
3748
-
3749
3732
  struct DelFilesArg {
3750
3733
  char curr_seg_file_name[FRT_SEGMENT_NAME_MAX_LENGTH];
3751
3734
  FrtDeleter *dlr;
3752
3735
  FrtHash *current;
3753
3736
  };
3754
3737
 
3755
- static void frt_deleter_find_deletable_files_i(const char *file_name, void *arg)
3756
- {
3738
+ static void frt_deleter_find_deletable_files_i(const char *file_name, void *arg) {
3757
3739
  struct DelFilesArg *dfa = (struct DelFilesArg *)arg;
3758
3740
  FrtDeleter *dlr = dfa->dlr;
3759
3741
 
@@ -3773,8 +3755,7 @@ static void frt_deleter_find_deletable_files_i(const char *file_name, void *arg)
3773
3755
  if (NULL != p) {
3774
3756
  *p = '\0';
3775
3757
  extension = p + 1;
3776
- }
3777
- else {
3758
+ } else {
3778
3759
  extension = NULL;
3779
3760
  }
3780
3761
 
@@ -3789,16 +3770,14 @@ static void frt_deleter_find_deletable_files_i(const char *file_name, void *arg)
3789
3770
  if (NULL == (si = (FrtSegmentInfo *)frt_h_get(dfa->current, segment_name))) {
3790
3771
  /* Delete if segment is not referenced: */
3791
3772
  do_delete = true;
3792
- }
3793
- else {
3773
+ } else {
3794
3774
  char tmp_fn[FRT_SEGMENT_NAME_MAX_LENGTH];
3795
3775
  /* OK, segment is referenced, but file may still be orphan'd: */
3796
3776
  if (file_name_filter_is_cfs_file(file_name)
3797
3777
  && si->use_compound_file) {
3798
3778
  /* This file is stored in a CFS file for this segment: */
3799
3779
  do_delete = true;
3800
- }
3801
- else if (0 == strcmp("del", extension)) {
3780
+ } else if (0 == strcmp("del", extension)) {
3802
3781
  /* This is a _segmentName_N.del file: */
3803
3782
  if (!frt_fn_for_generation(tmp_fn, segment_name, "del", si->del_gen)
3804
3783
  || 0 != strcmp(file_name, tmp_fn)) {
@@ -3807,8 +3786,7 @@ static void frt_deleter_find_deletable_files_i(const char *file_name, void *arg)
3807
3786
  * this segment, then delete it: */
3808
3787
  do_delete = true;
3809
3788
  }
3810
- }
3811
- else if (NULL != extension
3789
+ } else if (NULL != extension
3812
3790
  && ('s' == *extension || 'f' == *extension)
3813
3791
  && isdigit(extension[1])) {
3814
3792
  si_norm_file_name(si, tmp_fn, atoi(extension + 1));
@@ -3817,15 +3795,14 @@ static void frt_deleter_find_deletable_files_i(const char *file_name, void *arg)
3817
3795
  /* This is an orphan'd norms file: */
3818
3796
  do_delete = true;
3819
3797
  }
3820
- }
3821
- else if (0 == strcmp("cfs", extension) && !si->use_compound_file) {
3798
+ } else if (0 == strcmp("cfs", extension) && !si->use_compound_file) {
3822
3799
  /* This is a partially written _segmentName.cfs: */
3823
3800
  do_delete = true;
3824
3801
  }
3825
3802
  }
3826
3803
 
3827
3804
  if (do_delete) {
3828
- deleter_queue_file(dlr, file_name);
3805
+ frt_deleter_queue_file(dlr, file_name);
3829
3806
  }
3830
3807
  }
3831
3808
  }
@@ -3837,8 +3814,7 @@ static void frt_deleter_find_deletable_files_i(const char *file_name, void *arg)
3837
3814
  * create the unused file (eg when merging segments), and we only remove from
3838
3815
  * deletable when a file is successfully deleted.
3839
3816
  */
3840
- void frt_deleter_find_deletable_files(FrtDeleter *dlr)
3841
- {
3817
+ void frt_deleter_find_deletable_files(FrtDeleter *dlr) {
3842
3818
  /* Gather all "current" segments: */
3843
3819
  int i;
3844
3820
  FrtSegmentInfos *sis = dlr->sis;
@@ -4207,7 +4183,7 @@ static void norm_rewrite(Norm *norm, FrtStore *store, FrtDeleter *dlr,
4207
4183
  const int field_num = norm->field_num;
4208
4184
 
4209
4185
  if (si_norm_file_name(si, norm_file_name, field_num)) {
4210
- deleter_queue_file(dlr, norm_file_name);
4186
+ frt_deleter_queue_file(dlr, norm_file_name);
4211
4187
  }
4212
4188
  frt_si_advance_norm_gen(si, field_num);
4213
4189
  si_norm_file_name(si, norm_file_name, field_num);
@@ -4363,7 +4339,7 @@ static void sr_commit_i(FrtIndexReader *ir)
4363
4339
  if (SR(ir)->undelete_all || SR(ir)->deleted_docs_dirty) {
4364
4340
  if (si->del_gen >= 0) {
4365
4341
  frt_fn_for_generation(tmp_file_name, segment, "del", si->del_gen);
4366
- deleter_queue_file(ir->deleter, tmp_file_name);
4342
+ frt_deleter_queue_file(ir->deleter, tmp_file_name);
4367
4343
  }
4368
4344
  if (SR(ir)->undelete_all) {
4369
4345
  si->del_gen = -1;
@@ -5687,7 +5663,6 @@ static SegmentMergeInfo *smi_new(int base, FrtStore *store, FrtSegmentInfo *si)
5687
5663
  smi->store = frt_open_cmpd_store(store, file_name);
5688
5664
  }
5689
5665
 
5690
-
5691
5666
  sprintf(file_name, "%s.fdx", segment);
5692
5667
  smi->doc_cnt = smi->max_doc
5693
5668
  = smi->store->length(smi->store, file_name) / FIELDS_IDX_PTR_SIZE;
@@ -6116,14 +6091,7 @@ int frt_iw_doc_count(FrtIndexWriter *iw)
6116
6091
  return doc_cnt;
6117
6092
  }
6118
6093
 
6119
- #define MOVE_TO_COMPOUND_DIR(file_name)\
6120
- deleter_queue_file(dlr, file_name);\
6121
- frt_cw_add_file(cw, file_name)
6122
-
6123
- static void iw_create_compound_file(FrtStore *store, FrtFieldInfos *fis,
6124
- FrtSegmentInfo *si, char *cfs_file_name,
6125
- FrtDeleter *dlr)
6126
- {
6094
+ static void iw_create_compound_file(FrtStore *store, FrtFieldInfos *fis, FrtSegmentInfo *si, char *cfs_file_name, FrtDeleter *dlr) {
6127
6095
  int i;
6128
6096
  FrtCompoundWriter *cw;
6129
6097
  char file_name[FRT_SEGMENT_NAME_MAX_LENGTH];
@@ -6137,19 +6105,18 @@ static void iw_create_compound_file(FrtStore *store, FrtFieldInfos *fis,
6137
6105
  cw = frt_open_cw(store, cfs_file_name);
6138
6106
  for (i = 0; i < FRT_NELEMS(COMPOUND_EXTENSIONS); i++) {
6139
6107
  memcpy(ext, COMPOUND_EXTENSIONS[i], 4);
6140
- MOVE_TO_COMPOUND_DIR(file_name);
6108
+ frt_cw_add_file(cw, file_name);
6141
6109
  }
6142
6110
 
6143
6111
  /* Field norm file_names */
6144
6112
  for (i = fis->size - 1; i >= 0; i--) {
6145
- if (fi_has_norms(fis->fields[i])
6146
- && si_norm_file_name(si, file_name, i)) {
6147
- MOVE_TO_COMPOUND_DIR(file_name);
6113
+ if (fi_has_norms(fis->fields[i]) && si_norm_file_name(si, file_name, i)) {
6114
+ frt_cw_add_file(cw, file_name);
6148
6115
  }
6149
6116
  }
6150
6117
 
6151
6118
  /* Perform the merge */
6152
- frt_cw_close(cw);
6119
+ frt_cw_close(cw, dlr);
6153
6120
  }
6154
6121
 
6155
6122
  static void iw_commit_compound_file(FrtIndexWriter *iw, FrtSegmentInfo *si)
@@ -627,9 +627,9 @@ struct FrtDeleter {
627
627
 
628
628
  extern FrtDeleter *frt_deleter_new(FrtSegmentInfos *sis, FrtStore *store);
629
629
  extern void frt_deleter_destroy(FrtDeleter *dlr);
630
+ extern void frt_deleter_queue_file(FrtDeleter *dlr, const char *file_name);
630
631
  extern void frt_deleter_delete_file(FrtDeleter *dlr, char *file_name);
631
632
  extern void frt_deleter_find_deletable_files(FrtDeleter *dlr);
632
- extern void frt_deleter_delete_files(FrtDeleter *dlr, char **files, int file_cnt);
633
633
 
634
634
  /****************************************************************************
635
635
  *
@@ -859,6 +859,6 @@ typedef struct FrtCompoundWriter {
859
859
 
860
860
  extern FrtCompoundWriter *frt_open_cw(FrtStore *store, char *name);
861
861
  extern void frt_cw_add_file(FrtCompoundWriter *cw, char *id);
862
- extern void frt_cw_close(FrtCompoundWriter *cw);
862
+ extern void frt_cw_close(FrtCompoundWriter *cw, FrtDeleter *dlr);
863
863
 
864
864
  #endif
@@ -43,7 +43,14 @@ void *frt_erealloc(void *ptr, size_t size)
43
43
  return p;
44
44
  }
45
45
 
46
- /* void micro_sleep(const int micro_seconds)
46
+
47
+ struct timeval rb_time_interval _((VALUE));
48
+
49
+ extern void frt_micro_sleep(const int micro_seconds) {
50
+ rb_thread_wait_for(rb_time_interval(rb_float_new((double)micro_seconds/1000000.0)));
51
+ }
52
+
53
+ /* void frt_micro_sleep(const int micro_seconds)
47
54
  {
48
55
  #if (defined POSH_OS_WIN32 || defined POSH_OS_WIN64) && !defined __MINGW32__
49
56
  Sleep(micro_seconds / 1000);
@@ -5,7 +5,7 @@
5
5
  #include "frt_global.h"
6
6
  #include "frt_hash.h"
7
7
  #include "frt_hashset.h"
8
- #include "frb_threading.h"
8
+ #include "frt_threading.h"
9
9
 
10
10
  #define FRT_LOCK_PREFIX "ferret-"
11
11
  #define FRT_LOCK_EXT ".lck"
@@ -4,8 +4,8 @@
4
4
  #include "frt_except.h"
5
5
  #include "frt_hash.h"
6
6
  #include "frt_hashset.h"
7
- #include "frb_threading.h"
8
- #include "frb_lang.h"
7
+ #include "frt_threading.h"
8
+ #include "ruby.h"
9
9
 
10
10
  /* IDs */
11
11
  ID id_new;
@@ -1,10 +1,9 @@
1
1
  #ifndef __FERRET_H_
2
2
  #define __FERRET_H_
3
- #include <ruby.h>
4
3
  #include "frt_global.h"
5
4
  #include "frt_hashset.h"
6
5
  #include "frt_document.h"
7
- #include "frb_lang.h"
6
+ #include <ruby.h>
8
7
 
9
8
  /* IDs */
10
9
  extern ID id_new;
@@ -810,7 +810,7 @@ void Init_Test(void) {
810
810
  rb_define_singleton_method(mTest, "filter", frb_ts_filter, 0);
811
811
  rb_define_singleton_method(mTest, "fs_store", frb_ts_fs_store, 0);
812
812
  rb_define_singleton_method(mTest, "global", frb_ts_global, 0);
813
- rb_define_singleton_method(mTest, "hash", frb_ts_hash, 0);
813
+ rb_define_singleton_method(mTest, "test_hash", frb_ts_hash, 0);
814
814
  rb_define_singleton_method(mTest, "hashset", frb_ts_hashset, 0);
815
815
  rb_define_singleton_method(mTest, "helper", frb_ts_helper, 0);
816
816
  rb_define_singleton_method(mTest, "highlighter", frb_ts_highlighter, 0);
@@ -48,7 +48,7 @@ void test_compound_writer(TestCase *tc, void *data)
48
48
  cw = frt_open_cw(store, (char *)"cfile");
49
49
  frt_cw_add_file(cw, (char *)"file1");
50
50
  frt_cw_add_file(cw, (char *)"file2");
51
- frt_cw_close(cw);
51
+ frt_cw_close(cw, NULL);
52
52
 
53
53
  is = store->open_input(store, "cfile");
54
54
  Aiequal(2, frt_is_read_vint(is));
@@ -94,7 +94,7 @@ void test_compound_io(TestCase *tc, void *data)
94
94
  frt_cw_add_file(cw, (char *)"file1");
95
95
  frt_cw_add_file(cw, (char *)"file2");
96
96
  frt_cw_add_file(cw, (char *)"file3");
97
- frt_cw_close(cw);
97
+ frt_cw_close(cw, NULL);
98
98
 
99
99
  c_reader = frt_open_cmpd_store(store, "cfile");
100
100
  is1 = c_reader->open_input(c_reader, "file1");
@@ -137,7 +137,7 @@ void test_compound_io_many_files(TestCase *tc, void *data)
137
137
  frt_os_write_vint(os, MAGIC);
138
138
  frt_os_close(os);
139
139
  }
140
- frt_cw_close(cw);
140
+ frt_cw_close(cw, NULL);
141
141
 
142
142
  c_reader = frt_open_cmpd_store(store, "_.cfs");
143
143
  for (i = 0; i < TEST_FILE_CNT; i++) {
@@ -45,6 +45,7 @@ static void test_hash_str(TestCase *tc, void *data)
45
45
 
46
46
  size_t res;
47
47
  f = temp_open();
48
+ Assert(f != NULL, "Could not open tempfile");
48
49
  frt_h_str_print_keys(h, f);
49
50
  fseek(f, 0, SEEK_SET);
50
51
  res = fread(buf, 1, 100, f);
@@ -175,7 +175,7 @@ TestSuite *ts_threading(TestSuite *suite)
175
175
 
176
176
  tst_run_test(suite, test_number_to_str, NULL);
177
177
  tst_run_test(suite, test_threading_test, index);
178
- // tst_run_test(suite, test_threading, index);
178
+ tst_run_test(suite, test_threading, index);
179
179
 
180
180
  frt_index_destroy(index);
181
181
 
@@ -4,7 +4,7 @@ module Isomorfeus
4
4
  # This is a simplified interface to the index. See the TUTORIAL for more
5
5
  # information on how to use this class.
6
6
  class Index
7
- include Isomorfeus::Ferret::MonitorMixin
7
+ include MonitorMixin
8
8
  include Isomorfeus::Ferret::Store
9
9
  include Isomorfeus::Ferret::Search
10
10
 
@@ -1,5 +1,5 @@
1
1
  module Isomorfeus
2
2
  module Ferret
3
- VERSION = '0.13.3'
3
+ VERSION = '0.13.6'
4
4
  end
5
5
  end
@@ -2,7 +2,7 @@ require 'isomorfeus_ferret_ext'
2
2
  require 'isomorfeus/ferret/version'
3
3
  require 'isomorfeus/ferret/field_symbol'
4
4
  require 'isomorfeus/ferret/stdlib_patches'
5
- require 'isomorfeus/ferret/monitor'
5
+ require 'monitor'
6
6
  require 'isomorfeus/ferret/index/field_infos'
7
7
  require 'isomorfeus/ferret/index/index'
8
8
  require 'isomorfeus/ferret/document'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: isomorfeus-ferret
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.3
4
+ version: 0.13.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Biedermann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-19 00:00:00.000000000 Z
11
+ date: 2022-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -167,12 +167,9 @@ files:
167
167
  - ext/isomorfeus_ferret_ext/fio_tmpfile.h
168
168
  - ext/isomorfeus_ferret_ext/frb_analysis.c
169
169
  - ext/isomorfeus_ferret_ext/frb_index.c
170
- - ext/isomorfeus_ferret_ext/frb_lang.c
171
- - ext/isomorfeus_ferret_ext/frb_lang.h
172
170
  - ext/isomorfeus_ferret_ext/frb_qparser.c
173
171
  - ext/isomorfeus_ferret_ext/frb_search.c
174
172
  - ext/isomorfeus_ferret_ext/frb_store.c
175
- - ext/isomorfeus_ferret_ext/frb_threading.h
176
173
  - ext/isomorfeus_ferret_ext/frb_utils.c
177
174
  - ext/isomorfeus_ferret_ext/frt_analysis.c
178
175
  - ext/isomorfeus_ferret_ext/frt_analysis.h
@@ -360,7 +357,6 @@ files:
360
357
  - lib/isomorfeus/ferret/field_symbol.rb
361
358
  - lib/isomorfeus/ferret/index/field_infos.rb
362
359
  - lib/isomorfeus/ferret/index/index.rb
363
- - lib/isomorfeus/ferret/monitor.rb
364
360
  - lib/isomorfeus/ferret/stdlib_patches.rb
365
361
  - lib/isomorfeus/ferret/version.rb
366
362
  homepage: https://isomorfeus.com
@@ -1,9 +0,0 @@
1
- #include "frt_except.h"
2
- #include "frb_lang.h"
3
-
4
- struct timeval rb_time_interval _((VALUE));
5
-
6
- extern void frt_micro_sleep(const int micro_seconds)
7
- {
8
- rb_thread_wait_for(rb_time_interval(rb_float_new((double)micro_seconds/1000000.0)));
9
- }
@@ -1,17 +0,0 @@
1
- #ifndef FRT_LANG_H
2
- #define FRT_LANG_H
3
-
4
- #define RUBY_BINDINGS 1
5
-
6
- #include <stdarg.h>
7
- #include <ruby.h>
8
-
9
- #undef close
10
- #undef rename
11
- #undef read
12
-
13
- #define frt_emalloc xmalloc
14
- #define frt_ecalloc(n) xcalloc(n, 1)
15
- #define frt_erealloc xrealloc
16
-
17
- #endif
@@ -1,29 +0,0 @@
1
- #ifndef FRT_THREADING_H
2
- #define FRT_THREADING_H
3
-
4
- #include "frt_hash.h"
5
- #define UNTHREADED 1
6
-
7
- typedef void * frt_mutex_t;
8
- typedef struct FrtHash *frt_thread_key_t;
9
- typedef int frt_thread_once_t;
10
- #define FRT_MUTEX_INITIALIZER NULL
11
- #define FRT_THREAD_ONCE_INIT 1;
12
- #define frt_mutex_init(a, b)
13
- #define frt_mutex_lock(a)
14
- #define frt_mutex_trylock(a)
15
- #define frt_mutex_unlock(a)
16
- #define frt_mutex_destroy(a)
17
- #define frt_thread_key_create(a, b) frb_thread_key_create(a, b)
18
- #define frt_thread_key_delete(a) frb_thread_key_delete(a)
19
- #define frt_thread_setspecific(a, b) frb_thread_setspecific(a, b)
20
- #define frt_thread_getspecific(a) frb_thread_getspecific(a)
21
- #define frt_thread_once(a, b) frb_thread_once(a, b)
22
-
23
- void frb_thread_once(int *once_control, void (*init_routine)(void));
24
- void frb_thread_key_create(frt_thread_key_t *key, frt_free_ft destroy);
25
- void frb_thread_key_delete(frt_thread_key_t key);
26
- void frb_thread_setspecific(frt_thread_key_t key, const void *pointer);
27
- void *frb_thread_getspecific(frt_thread_key_t key);
28
-
29
- #endif
@@ -1,323 +0,0 @@
1
- # frozen_string_literal: false
2
- # = monitor.rb
3
- #
4
- # Copyright (C) 2001 Shugo Maeda <shugo@ruby-lang.org>
5
- #
6
- # This library is distributed under the terms of the Ruby license.
7
- # You can freely distribute/modify this library.
8
- #
9
-
10
- #
11
- # In concurrent programming, a monitor is an object or module intended to be
12
- # used safely by more than one thread. The defining characteristic of a
13
- # monitor is that its methods are executed with mutual exclusion. That is, at
14
- # each point in time, at most one thread may be executing any of its methods.
15
- # This mutual exclusion greatly simplifies reasoning about the implementation
16
- # of monitors compared to reasoning about parallel code that updates a data
17
- # structure.
18
- #
19
- # You can read more about the general principles on the Wikipedia page for
20
- # Monitors[http://en.wikipedia.org/wiki/Monitor_%28synchronization%29]
21
- #
22
- # == Examples
23
- #
24
- # === Simple object.extend
25
- #
26
- # require 'monitor.rb'
27
- #
28
- # buf = []
29
- # buf.extend(MonitorMixin)
30
- # empty_cond = buf.new_cond
31
- #
32
- # # consumer
33
- # Thread.start do
34
- # loop do
35
- # buf.synchronize do
36
- # empty_cond.wait_while { buf.empty? }
37
- # print buf.shift
38
- # end
39
- # end
40
- # end
41
- #
42
- # # producer
43
- # while line = ARGF.gets
44
- # buf.synchronize do
45
- # buf.push(line)
46
- # empty_cond.signal
47
- # end
48
- # end
49
- #
50
- # The consumer thread waits for the producer thread to push a line to buf
51
- # while <tt>buf.empty?</tt>. The producer thread (main thread) reads a
52
- # line from ARGF and pushes it into buf then calls <tt>empty_cond.signal</tt>
53
- # to notify the consumer thread of new data.
54
- #
55
- # === Simple Class include
56
- #
57
- # require 'monitor'
58
- #
59
- # class SynchronizedArray < Array
60
- #
61
- # include MonitorMixin
62
- #
63
- # def initialize(*args)
64
- # super(*args)
65
- # end
66
- #
67
- # alias :old_shift :shift
68
- # alias :old_unshift :unshift
69
- #
70
- # def shift(n=1)
71
- # self.synchronize do
72
- # self.old_shift(n)
73
- # end
74
- # end
75
- #
76
- # def unshift(item)
77
- # self.synchronize do
78
- # self.old_unshift(item)
79
- # end
80
- # end
81
- #
82
- # # other methods ...
83
- # end
84
- #
85
- # +SynchronizedArray+ implements an Array with synchronized access to items.
86
- # This Class is implemented as subclass of Array which includes the
87
- # MonitorMixin module.
88
- #
89
- module Isomorfeus
90
- module Ferret
91
- module MonitorMixin
92
- #
93
- # FIXME: This isn't documented in Nutshell.
94
- #
95
- # Since MonitorMixin.new_cond returns a ConditionVariable, and the example
96
- # above calls while_wait and signal, this class should be documented.
97
- #
98
- class ConditionVariable
99
- class Timeout < Exception; end
100
-
101
- #
102
- # Releases the lock held in the associated monitor and waits; reacquires the lock on wakeup.
103
- #
104
- # If +timeout+ is given, this method returns after +timeout+ seconds passed,
105
- # even if no other thread doesn't signal.
106
- #
107
- def wait(timeout = nil)
108
- Thread.handle_interrupt(Exception => :never) do
109
- @monitor.__send__(:mon_check_owner)
110
- count = @monitor.__send__(:mon_exit_for_cond)
111
- begin
112
- Thread.handle_interrupt(Exception => :immediate) do
113
- @cond.wait(@monitor.instance_variable_get(:@mon_mutex), timeout)
114
- end
115
- return true
116
- ensure
117
- @monitor.__send__(:mon_enter_for_cond, count)
118
- end
119
- end
120
- end
121
-
122
- #
123
- # Calls wait repeatedly while the given block yields a truthy value.
124
- #
125
- def wait_while
126
- while yield
127
- wait
128
- end
129
- end
130
-
131
- #
132
- # Calls wait repeatedly until the given block yields a truthy value.
133
- #
134
- def wait_until
135
- until yield
136
- wait
137
- end
138
- end
139
-
140
- #
141
- # Wakes up the first thread in line waiting for this lock.
142
- #
143
- def signal
144
- @monitor.__send__(:mon_check_owner)
145
- @cond.signal
146
- end
147
-
148
- #
149
- # Wakes up all threads waiting for this lock.
150
- #
151
- def broadcast
152
- @monitor.__send__(:mon_check_owner)
153
- @cond.broadcast
154
- end
155
-
156
- private
157
-
158
- def initialize(monitor)
159
- @monitor = monitor
160
- @cond = Thread::ConditionVariable.new
161
- end
162
- end
163
-
164
- def self.extend_object(obj)
165
- super(obj)
166
- obj.__send__(:mon_initialize)
167
- end
168
-
169
- #
170
- # Attempts to enter exclusive section. Returns +false+ if lock fails.
171
- #
172
- def mon_try_enter
173
- if @mon_owner != Thread.current
174
- unless @mon_mutex.try_lock
175
- return false
176
- end
177
- @mon_owner = Thread.current
178
- @mon_count = 0
179
- end
180
- @mon_count += 1
181
- return true
182
- end
183
- # For backward compatibility
184
- alias try_mon_enter mon_try_enter
185
-
186
- #
187
- # Enters exclusive section.
188
- #
189
- def mon_enter
190
- if @mon_owner != Thread.current
191
- @mon_mutex.lock
192
- @mon_owner = Thread.current
193
- @mon_count = 0
194
- end
195
- @mon_count += 1
196
- end
197
-
198
- #
199
- # Leaves exclusive section.
200
- #
201
- def mon_exit
202
- mon_check_owner
203
- @mon_count -=1
204
- if @mon_count == 0
205
- @mon_owner = nil
206
- @mon_mutex.unlock
207
- end
208
- end
209
-
210
- #
211
- # Returns true if this monitor is locked by any thread
212
- #
213
- def mon_locked?
214
- @mon_mutex.locked?
215
- end
216
-
217
- #
218
- # Returns true if this monitor is locked by current thread.
219
- #
220
- def mon_owned?
221
- @mon_mutex.locked? && @mon_owner == Thread.current
222
- end
223
-
224
- #
225
- # Enters exclusive section and executes the block. Leaves the exclusive
226
- # section automatically when the block exits. See example under
227
- # +MonitorMixin+.
228
- #
229
- def mon_synchronize
230
- # Prevent interrupt on handling interrupts; for example timeout errors
231
- # it may break locking state.
232
- Thread.handle_interrupt(Exception => :never){ mon_enter }
233
- begin
234
- yield
235
- ensure
236
- Thread.handle_interrupt(Exception => :never){ mon_exit }
237
- end
238
- end
239
- alias synchronize mon_synchronize
240
-
241
- #
242
- # Creates a new MonitorMixin::ConditionVariable associated with the
243
- # receiver.
244
- #
245
- def new_cond
246
- return ConditionVariable.new(self)
247
- end
248
-
249
- private
250
-
251
- # Use <tt>extend MonitorMixin</tt> or <tt>include MonitorMixin</tt> instead
252
- # of this constructor. Have look at the examples above to understand how to
253
- # use this module.
254
- def initialize(*args)
255
- super
256
- mon_initialize
257
- end
258
-
259
- # Initializes the MonitorMixin after being included in a class or when an
260
- # object has been extended with the MonitorMixin
261
- def mon_initialize
262
- if defined?(@mon_mutex) && @mon_mutex_owner_object_id == object_id
263
- raise ThreadError, "already initialized"
264
- end
265
- @mon_mutex = Thread::Mutex.new
266
- @mon_mutex_owner_object_id = object_id
267
- @mon_owner = nil
268
- @mon_count = 0
269
- end
270
-
271
- def mon_check_owner
272
- if @mon_owner != Thread.current
273
- raise ThreadError, "current thread not owner"
274
- end
275
- end
276
-
277
- def mon_enter_for_cond(count)
278
- @mon_owner = Thread.current
279
- @mon_count = count
280
- end
281
-
282
- def mon_exit_for_cond
283
- count = @mon_count
284
- @mon_owner = nil
285
- @mon_count = 0
286
- return count
287
- end
288
- end
289
-
290
- # Use the Monitor class when you want to have a lock object for blocks with
291
- # mutual exclusion.
292
- #
293
- # require 'monitor'
294
- #
295
- # lock = Monitor.new
296
- # lock.synchronize do
297
- # # exclusive access
298
- # end
299
- #
300
- class Monitor
301
- include MonitorMixin
302
- alias try_enter try_mon_enter
303
- alias enter mon_enter
304
- alias exit mon_exit
305
- end
306
- end
307
- end
308
-
309
- # Documentation comments:
310
- # - All documentation comes from Nutshell.
311
- # - MonitorMixin.new_cond appears in the example, but is not documented in
312
- # Nutshell.
313
- # - All the internals (internal modules Accessible and Initializable, class
314
- # ConditionVariable) appear in RDoc. It might be good to hide them, by
315
- # making them private, or marking them :nodoc:, etc.
316
- # - RDoc doesn't recognise aliases, so we have mon_synchronize documented, but
317
- # not synchronize.
318
- # - mon_owner is in Nutshell, but appears as an accessor in a separate module
319
- # here, so is hard/impossible to RDoc. Some other useful accessors
320
- # (mon_count and some queue stuff) are also in this module, and don't appear
321
- # directly in the RDoc output.
322
- # - in short, it may be worth changing the code layout in this file to make the
323
- # documentation easier