多线程下载情形下,可能多线程访问fuzzy_handle,对其操作使用mutex锁保护。

This commit is contained in:
zhengchao
2015-12-08 13:01:49 +08:00
parent 461e50cdb0
commit 1e7800862e
3 changed files with 10 additions and 1 deletions

View File

@@ -1052,6 +1052,7 @@ stream_para_t Maat_stream_scan_digest_start(Maat_feather_t feather,int table_id,
sp->thread_num=thread_num; sp->thread_num=thread_num;
sp->total_len=total_len; sp->total_len=total_len;
sp->fuzzy_hash_handle=tmp_fuzzy_handle; sp->fuzzy_hash_handle=tmp_fuzzy_handle;
pthread_mutex_init(&(sp->fuzzy_mutex),NULL);
return sp; return sp;
} }
@@ -1092,19 +1093,25 @@ int Maat_stream_scan_digest(stream_para_t * stream_para, const char * data, int
{ {
return 0; return 0;
} }
pthread_mutex_lock(&(sp->fuzzy_mutex));
sp->acc_scan_len+=fuzzy_feed(sp->fuzzy_hash_handle, data, (unsigned int)data_len,offset); sp->acc_scan_len+=fuzzy_feed(sp->fuzzy_hash_handle, data, (unsigned int)data_len,offset);
pthread_mutex_unlock(&(sp->fuzzy_mutex));
do_query=REACH_QUERY_THRESH(sp->total_len, sp->acc_scan_len, sp->query_point,8); do_query=REACH_QUERY_THRESH(sp->total_len, sp->acc_scan_len, sp->query_point,8);
if(do_query==0) if(do_query==0)
{ {
return 0; return 0;
} }
pthread_mutex_lock(&(sp->fuzzy_mutex));
digest_len=fuzzy_status(sp->fuzzy_hash_handle, HASH_LENGTH); digest_len=fuzzy_status(sp->fuzzy_hash_handle, HASH_LENGTH);
pthread_mutex_unlock(&(sp->fuzzy_mutex));
if(digest_len==0) if(digest_len==0)
{ {
return 0; return 0;
} }
digest_buff=(char*)malloc(sizeof(char)*digest_len); digest_buff=(char*)malloc(sizeof(char)*digest_len);
pthread_mutex_lock(&(sp->fuzzy_mutex));
fuzzy_digest(sp->fuzzy_hash_handle,digest_buff, digest_len); fuzzy_digest(sp->fuzzy_hash_handle,digest_buff, digest_len);
pthread_mutex_unlock(&(sp->fuzzy_mutex));
if(0==pthread_rwlock_tryrdlock(GIE_rwlock)) if(0==pthread_rwlock_tryrdlock(GIE_rwlock))
{ {
if(GIE_handle!=NULL) if(GIE_handle!=NULL)
@@ -1156,6 +1163,7 @@ void Maat_stream_scan_digest_end(stream_para_t* stream_para)
} }
} }
fuzzy_destroy_handle(sp->fuzzy_hash_handle); fuzzy_destroy_handle(sp->fuzzy_hash_handle);
pthread_mutex_destroy(&(sp->fuzzy_mutex));
assert(sp->last_cache==NULL); assert(sp->last_cache==NULL);
assert(sp->scan_buff==NULL); assert(sp->scan_buff==NULL);
free(sp); free(sp);

View File

@@ -24,7 +24,7 @@
#include "mesa_fuzzy.h" #include "mesa_fuzzy.h"
#include "great_index_engine.h" #include "great_index_engine.h"
int MAAT_FRAME_VERSION_1_3_20151119=0; int MAAT_FRAME_VERSION_1_3_20151208=0;
const char *maat_module="MAAT Frame"; const char *maat_module="MAAT Frame";
const char* CHARSET_STRING[]={"CHARSET_NONE","GBK","BIG5","UNICODE","UTF-8"}; const char* CHARSET_STRING[]={"CHARSET_NONE","GBK","BIG5","UNICODE","UTF-8"};

View File

@@ -263,6 +263,7 @@ struct _stream_para_t
long acc_scan_len; long acc_scan_len;
unsigned long long total_len; unsigned long long total_len;
fuzzy_handle_t *fuzzy_hash_handle; fuzzy_handle_t *fuzzy_hash_handle;
pthread_mutex_t fuzzy_mutex;
unsigned char query_point[8]; unsigned char query_point[8];
}; };
struct _Maat_scanner_t struct _Maat_scanner_t