Re: [AD] Allegro 4.1.6/Allegro 4.0.3 |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
> (And btw., since I upgraded my CVS yesterday, all newly compiled Allegro
> programs freeze if I hold any keyboard key longer than about 1 second. I
> didn't have time to investigate this closer though, and I also did a
> debian upgrade so it could be something else).
No problem under Windows of course. I got caught by the classical issue
relating to pthread mutexes: they don't support nested locking... and the
timer proc of the autorepeat feature reinstalls itself permanently.
Fixed thus in the CVS tree.
--
Eric Botcazou
--- /home/eric/cvs/allegro/src/unix/uthreads.c Tue Nov 26 14:46:38 2002
+++ allegro/src/unix/uthreads.c Thu Nov 28 18:33:31 2002
@@ -216,20 +216,32 @@
+/* custom mutex that supports nested locking */
+struct my_mutex {
+ int lock_count; /* level of nested locking */
+ pthread_t owner; /* thread which owns the mutex */
+ pthread_mutex_t actual_mutex; /* underlying mutex object */
+};
+
+
+
/* _unix_create_mutex:
* Creates a mutex and returns a pointer to it.
*/
void *_unix_create_mutex (void)
{
- pthread_mutex_t *mx;
+ struct my_mutex *mx;
- mx = malloc (sizeof (pthread_mutex_t));
+ mx = malloc (sizeof (struct my_mutex));
if (!mx) {
*allegro_errno = ENOMEM;
return NULL;
}
- pthread_mutex_init (mx, NULL);
+ mx->lock_count = 0;
+ mx->owner = NULL;
+
+ pthread_mutex_init (&mx->actual_mutex, NULL);
return (void *) mx;
}
@@ -241,9 +253,9 @@
*/
void _unix_destroy_mutex (void *handle)
{
- pthread_mutex_t *mx = (pthread_mutex_t *) handle;
+ struct my_mutex *mx = (struct my_mutex *) handle;
- pthread_mutex_destroy (mx);
+ pthread_mutex_destroy (&mx->actual_mutex);
free (mx);
}
@@ -255,9 +267,14 @@
*/
void _unix_lock_mutex (void *handle)
{
- pthread_mutex_t *mx = (pthread_mutex_t *) handle;
+ struct my_mutex *mx = (struct my_mutex *) handle;
- pthread_mutex_lock (mx);
+ if (mx->owner != pthread_self ()) {
+ pthread_mutex_lock (&mx->actual_mutex);
+ mx->owner = pthread_self ();
+ }
+
+ mx->lock_count++;
}
@@ -267,9 +284,14 @@
*/
void _unix_unlock_mutex (void *handle)
{
- pthread_mutex_t *mx = (pthread_mutex_t *) handle;
+ struct my_mutex *mx = (struct my_mutex *) handle;
- pthread_mutex_unlock (mx);
+ mx->lock_count--;
+
+ if (mx->lock_count == 0) {
+ mx->owner = NULL;
+ pthread_mutex_unlock (&mx->actual_mutex);
+ }
}
#endif