99 |
If Emacs sets malloc hooks (! SYSTEM_MALLOC) and the emacs_blocked_* |
If Emacs sets malloc hooks (! SYSTEM_MALLOC) and the emacs_blocked_* |
100 |
functions below are called from malloc, there is a chance that one |
functions below are called from malloc, there is a chance that one |
101 |
of these threads preempts the Emacs main thread and the hook variables |
of these threads preempts the Emacs main thread and the hook variables |
102 |
end up in a inconsistent state. So we have a mutex to prevent that (note |
end up in an inconsistent state. So we have a mutex to prevent that (note |
103 |
that the backend handles concurrent access to malloc within its own threads |
that the backend handles concurrent access to malloc within its own threads |
104 |
but Emacs code running in the main thread is not included in that control). |
but Emacs code running in the main thread is not included in that control). |
105 |
|
|
109 |
To prevent that, we only call BLOCK/UNBLOCK from the main thread. */ |
To prevent that, we only call BLOCK/UNBLOCK from the main thread. */ |
110 |
|
|
111 |
static pthread_mutex_t alloc_mutex; |
static pthread_mutex_t alloc_mutex; |
|
pthread_t main_thread; |
|
112 |
|
|
113 |
#define BLOCK_INPUT_ALLOC \ |
#define BLOCK_INPUT_ALLOC \ |
114 |
do \ |
do \ |
1309 |
pthread_mutexattr_init (&attr); |
pthread_mutexattr_init (&attr); |
1310 |
pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE); |
pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE); |
1311 |
pthread_mutex_init (&alloc_mutex, &attr); |
pthread_mutex_init (&alloc_mutex, &attr); |
|
|
|
|
main_thread = pthread_self (); |
|
1312 |
#endif /* HAVE_GTK_AND_PTHREAD */ |
#endif /* HAVE_GTK_AND_PTHREAD */ |
1313 |
|
|
1314 |
if (__free_hook != emacs_blocked_free) |
if (__free_hook != emacs_blocked_free) |