Ensure thread safety by ensuring that tag_defs[] is thread local.
This has some overhead but is negligible on modern systems.
This commit is contained in:
Jim Derry 2021-08-14 21:36:38 -04:00
parent c8fbde5903
commit 28068b1273
2 changed files with 17 additions and 6 deletions

View file

@ -509,10 +509,10 @@ extern "C" {
# if defined(_MSC_VER) # if defined(_MSC_VER)
# define fileno _fileno # define fileno _fileno
#if !defined(NDEBUG) && !defined(ENABLE_DEBUG_LOG) && !defined(DISABLE_DEBUG_LOG) # if !defined(NDEBUG) && !defined(ENABLE_DEBUG_LOG) && !defined(DISABLE_DEBUG_LOG)
#define ENABLE_DEBUG_LOG # define ENABLE_DEBUG_LOG
#endif # endif
#endif # endif
# define access _access # define access _access
# define strcasecmp _stricmp # define strcasecmp _stricmp
@ -553,6 +553,13 @@ extern "C" {
# endif # endif
# endif # endif
# ifndef TIDY_THREAD_LOCAL
# ifdef _MSC_VER
# define TIDY_THREAD_LOCAL __declspec( thread )
# endif
# endif
#endif /* _WIN32 */ #endif /* _WIN32 */
@ -600,6 +607,10 @@ extern "C" {
# define TIDY_STRUCT # define TIDY_STRUCT
#endif #endif
#ifndef TIDY_THREAD_LOCAL
# define TIDY_THREAD_LOCAL __thread
#endif
typedef unsigned char byte; typedef unsigned char byte;
typedef uint tchar; /* single, full character */ typedef uint tchar; /* single, full character */

View file

@ -166,7 +166,7 @@ static CheckAttribs CheckHTML;
* but allow this table to be ADJUSTED if NOT HTML5 * but allow this table to be ADJUSTED if NOT HTML5
* was static const Dict tag_defs[] = * was static const Dict tag_defs[] =
\*/ \*/
static Dict tag_defs[] = static TIDY_THREAD_LOCAL Dict tag_defs[] =
{ {
{ TidyTag_UNKNOWN, "unknown!", VERS_UNKNOWN, NULL, (0), NULL, NULL }, { TidyTag_UNKNOWN, "unknown!", VERS_UNKNOWN, NULL, (0), NULL, NULL },