X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=index%2Frecindex.c;h=4563fc469ec16fce847277ded74acfb0dd7b7305;hb=5e7516d00451ada59a311fad05e8e3959242cdc7;hp=81e390bce12fdb7352f1ce59d0d4d535c8dc062c;hpb=967d839b42a38836f6ef9ac271f4185460bcb6ea;p=idzebra-moved-to-github.git diff --git a/index/recindex.c b/index/recindex.c index 81e390b..4563fc4 100644 --- a/index/recindex.c +++ b/index/recindex.c @@ -4,7 +4,23 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: recindex.c,v $ - * Revision 1.27 1999-10-29 10:02:33 adam + * Revision 1.32 2002-04-05 08:46:26 adam + * Zebra with full functionality + * + * Revision 1.31 2001/02/26 22:14:59 adam + * Updated for BZIP2 1.0.X. Configure script doesn't enable 64 bit LFS + * on broken glibc on Redhat 7.0. + * + * Revision 1.30 2000/07/13 10:14:20 heikki + * Removed compiler warnings when making zebra + * + * Revision 1.29 2000/04/05 09:49:35 adam + * On Unix, zebra/z'mbol uses automake. + * + * Revision 1.28 1999/12/08 22:44:45 adam + * Zebra/Z'mbol dependencies added. + * + * Revision 1.27 1999/10/29 10:02:33 adam * Fixed decompression buffer overflow. * * Revision 1.26 1999/07/06 13:34:57 adam @@ -393,6 +409,7 @@ Records rec_open (BFiles bfs, int rw, int compression_method) p->cache_cur = 0; p->record_cache = (struct record_cache_entry *) xmalloc (sizeof(*p->record_cache)*p->cache_max); + zebra_mutex_init (&p->mutex); return p; } @@ -525,7 +542,12 @@ static void rec_write_multiple (Records p, int saveCount) #if HAVE_BZLIB_H csize = out_offset + (out_offset >> 6) + 620; rec_tmp_expand (p, csize); - i = bzBuffToBuffCompress (p->tmp_buf+sizeof(int)+sizeof(short)+ +#ifdef BZ_CONFIG_ERROR + i = BZ2_bzBuffToBuffCompress +#else + i = bzBuffToBuffCompress +#endif + (p->tmp_buf+sizeof(int)+sizeof(short)+ sizeof(char), &csize, out_buf, out_offset, 1, 0, 30); if (i != BZ_OK) @@ -632,6 +654,7 @@ void rec_close (Records *pp) assert (p); + zebra_mutex_destroy (&p->mutex); rec_cache_flush (p, 0); xfree (p->record_cache); @@ -652,8 +675,7 @@ void rec_close (Records *pp) *pp = NULL; } - -Record rec_get (Records p, int sysno) +static Record rec_get_int (Records p, int sysno) { int i, in_size, r; Record rec, *recp; @@ -662,7 +684,9 @@ Record rec_get (Records p, int sysno) char *nptr, *cptr; char *in_buf = 0; char *bz_buf = 0; +#if HAVE_BZLIB_H int bz_size; +#endif char compression_method; assert (sysno > 0); @@ -719,7 +743,12 @@ Record rec_get (Records p, int sysno) while (1) { bz_buf = (char *) xmalloc (bz_size); - i = bzBuffToBuffDecompress (bz_buf, &bz_size, in_buf, in_size, 0, 0); +#ifdef BZ_CONFIG_ERROR + i = BZ2_bzBuffToBuffDecompress +#else + i = bzBuffToBuffDecompress +#endif + (bz_buf, &bz_size, in_buf, in_size, 0, 0); logf (LOG_LOG, "decompress %5d %5d", in_size, bz_size); if (i == BZ_OK) break; @@ -788,7 +817,17 @@ Record rec_get (Records p, int sysno) return rec; } -Record rec_new (Records p) +Record rec_get (Records p, int sysno) +{ + Record rec; + zebra_mutex_lock (&p->mutex); + + rec = rec_get_int (p, sysno); + zebra_mutex_unlock (&p->mutex); + return rec; +} + +static Record rec_new_int (Records p) { int sysno, i; Record rec; @@ -816,10 +855,21 @@ Record rec_new (Records p) return rec; } +Record rec_new (Records p) +{ + Record rec; + zebra_mutex_lock (&p->mutex); + + rec = rec_new_int (p); + zebra_mutex_unlock (&p->mutex); + return rec; +} + void rec_del (Records p, Record *recpp) { Record *recp; + zebra_mutex_lock (&p->mutex); (p->head.no_records)--; if ((recp = rec_cache_lookup (p, (*recpp)->sysno, recordFlagDelete))) { @@ -831,6 +881,7 @@ void rec_del (Records p, Record *recpp) rec_cache_insert (p, *recpp, recordFlagDelete); rec_rm (recpp); } + zebra_mutex_unlock (&p->mutex); *recpp = NULL; } @@ -838,6 +889,7 @@ void rec_put (Records p, Record *recpp) { Record *recp; + zebra_mutex_lock (&p->mutex); if ((recp = rec_cache_lookup (p, (*recpp)->sysno, recordFlagWrite))) { rec_rm (recp); @@ -848,6 +900,7 @@ void rec_put (Records p, Record *recpp) rec_cache_insert (p, *recpp, recordFlagWrite); rec_rm (recpp); } + zebra_mutex_unlock (&p->mutex); *recpp = NULL; }