1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2026-01-26 21:41:34 +03:00
Files
libxml2/include/private/threads.h
Daniel P. Berrangé 80798c406c xmlschemastypes: ensure thread safe global initialization
Relying on a plain integer flag, with no synchronization primitives does
not give thread-safe initialization. All reads & writes of the
xmlSchemaTypesInitialized flag need to be protected by a mutex to ensure
suitable memory barriers & thus correct ordering wrt any speculative
execution.

A separate internal initializer tied to xmlParserInit is used to create
the mutex used for synchronization, similarly to how catalog.c works.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2025-06-26 17:46:01 +01:00

70 lines
1.3 KiB
C

#ifndef XML_THREADS_H_PRIVATE__
#define XML_THREADS_H_PRIVATE__
#include <libxml/threads.h>
#ifdef LIBXML_THREAD_ENABLED
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#ifdef _WIN32_WINNT
#undef _WIN32_WINNT
#endif
#define _WIN32_WINNT 0x0600
#include <windows.h>
#define HAVE_WIN32_THREADS
#else
#include <pthread.h>
#define HAVE_POSIX_THREADS
#endif
#endif
/*
* xmlMutex are a simple mutual exception locks
*/
struct _xmlMutex {
#ifdef HAVE_POSIX_THREADS
pthread_mutex_t lock;
#elif defined HAVE_WIN32_THREADS
CRITICAL_SECTION cs;
#else
int empty;
#endif
};
/*
* xmlRMutex are reentrant mutual exception locks
*/
struct _xmlRMutex {
#ifdef HAVE_POSIX_THREADS
pthread_mutex_t lock;
unsigned int held;
unsigned int waiters;
pthread_t tid;
pthread_cond_t cv;
#elif defined HAVE_WIN32_THREADS
CRITICAL_SECTION cs;
#else
int empty;
#endif
};
XML_HIDDEN void
xmlInitMutex(xmlMutex *mutex);
XML_HIDDEN void
xmlCleanupMutex(xmlMutex *mutex);
XML_HIDDEN void
xmlInitRMutex(xmlRMutex *mutex);
XML_HIDDEN void
xmlCleanupRMutex(xmlRMutex *mutex);
#ifdef LIBXML_SCHEMAS_ENABLED
XML_HIDDEN void
xmlInitSchemasTypesInternal(void);
XML_HIDDEN void
xmlCleanupSchemasTypesInternal(void);
#endif
#endif /* XML_THREADS_H_PRIVATE__ */