mirror of
https://github.com/kerberos-io/openalpr-base.git
synced 2025-10-05 23:06:56 +08:00
Fixed threading issue in Onigura Regex library
This commit is contained in:
@@ -21,6 +21,8 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
tthread::mutex regexrule_mutex_m;
|
||||
|
||||
namespace alpr
|
||||
{
|
||||
|
||||
@@ -28,6 +30,7 @@ namespace alpr
|
||||
{
|
||||
this->original = pattern;
|
||||
this->region = region;
|
||||
this->regex = "";
|
||||
|
||||
this->valid = false;
|
||||
string::iterator end_it = utf8::find_invalid(pattern.begin(), pattern.end());
|
||||
@@ -90,13 +93,17 @@ namespace alpr
|
||||
numchars++;
|
||||
}
|
||||
|
||||
// Onigurama is not thread safe when compiling regex. Using a mutex to ensure that
|
||||
// we don't crash
|
||||
regexrule_mutex_m.lock();
|
||||
UChar* cstr_pattern = (UChar* )this->regex.c_str();
|
||||
OnigErrorInfo einfo;
|
||||
|
||||
//cout << "Pattern: " << cstr_pattern << endl;
|
||||
int r = onig_new(&onig_regex, cstr_pattern, cstr_pattern + strlen((char* )cstr_pattern),
|
||||
ONIG_OPTION_DEFAULT, ONIG_ENCODING_UTF8, ONIG_SYNTAX_DEFAULT, &einfo);
|
||||
|
||||
regexrule_mutex_m.unlock();
|
||||
|
||||
if (r != ONIG_NORMAL) {
|
||||
//char s[ONIG_MAX_ERROR_MESSAGE_LEN];
|
||||
//onig_error_code_to_str(s, r, &einfo);
|
||||
|
@@ -26,6 +26,7 @@
|
||||
#include <vector>
|
||||
#include "support/regex/oniguruma.h"
|
||||
#include "support/utf8.h"
|
||||
#include "support/tinythread.h"
|
||||
|
||||
namespace alpr
|
||||
{
|
||||
|
Reference in New Issue
Block a user