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