From 2cba317c98f3cbc42a77614fa5a967f3dc727340 Mon Sep 17 00:00:00 2001 From: barbieri Date: Tue, 23 Dec 2008 21:20:43 +0000 Subject: [PATCH] attempt to fix image preload thread bugs 1: module refcount. image preload will use modules from threads, there is a possibility to crash due wrong reference counting. actually much more can fail, we need to check modules don't keep that needs exclusive access in globals or per-Evas_Module, but that's another issue. TODO: replace spinlocks with atomic operations. git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/evas@38309 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- src/lib/file/evas_module.c | 18 ++++++++++++++++++ src/lib/file/evas_module.h | 4 ++++ 2 files changed, 22 insertions(+) diff --git a/src/lib/file/evas_module.c b/src/lib/file/evas_module.c index 71d8ee8..39dbb8c 100644 --- a/src/lib/file/evas_module.c +++ b/src/lib/file/evas_module.c @@ -174,6 +174,9 @@ evas_module_init(void) em->handle = NULL; em->data = NULL; em->loaded = 0; +#if defined(HAVE_PTHREAD_H) && defined(BUILD_ASYNC_PRELOAD) + pthread_spin_init(&em->lock, PTHREAD_PROCESS_PRIVATE); +#endif if (em->type == EVAS_MODULE_TYPE_ENGINE) { Evas_Module_Engine *eme; @@ -306,20 +309,35 @@ evas_module_unload(Evas_Module *em) em->func.close = NULL; em->api = NULL; em->loaded = 0; +#if defined(HAVE_PTHREAD_H) && defined(BUILD_ASYNC_PRELOAD) + pthread_spin_destroy(&em->lock); +#endif } void evas_module_ref(Evas_Module *em) { +#if defined(HAVE_PTHREAD_H) && defined(BUILD_ASYNC_PRELOAD) + pthread_spin_lock(&em->lock); +#endif em->ref++; /* printf("M: %s ref++ = %i\n", em->name, em->ref); */ +#if defined(HAVE_PTHREAD_H) && defined(BUILD_ASYNC_PRELOAD) + pthread_spin_unlock(&em->lock); +#endif } void evas_module_unref(Evas_Module *em) { +#if defined(HAVE_PTHREAD_H) && defined(BUILD_ASYNC_PRELOAD) + pthread_spin_lock(&em->lock); +#endif em->ref--; /* printf("M: %s ref-- = %i\n", em->name, em->ref); */ +#if defined(HAVE_PTHREAD_H) && defined(BUILD_ASYNC_PRELOAD) + pthread_spin_unlock(&em->lock); +#endif } static int use_count = 0; diff --git a/src/lib/file/evas_module.h b/src/lib/file/evas_module.h index 06765df..76ef125 100644 --- a/src/lib/file/evas_module.h +++ b/src/lib/file/evas_module.h @@ -50,6 +50,10 @@ struct _Evas_Module int ref; /* how many refs */ int last_used; /* the cycle count when it was last used */ +#if defined(HAVE_PTHREAD_H) && defined(BUILD_ASYNC_PRELOAD) + pthread_spinlock_t lock; +#endif + unsigned char loaded : 1; }; -- 2.7.4