On Mon, Feb 20, 2012 at 4:57 PM, Enlightenment SVN <[email protected]> wrote: > Log: > ecore: rewrite of Ecore_Thread internal to use Eina_Lock and > ecore_main_loop_thread_safe_call_async. > > NOTES: It is now safer and faster. I doubt I will have more time before the > release to finish > ecore_thread_message_run, nor to make the shutdown nicer. > > > Author: cedric > Date: 2012-02-20 07:57:18 -0800 (Mon, 20 Feb 2012) > New Revision: 68164 > Trac: http://trac.enlightenment.org/e/changeset/68164 > > Modified: > trunk/ecore/ChangeLog trunk/ecore/NEWS > trunk/ecore/src/lib/ecore/ecore_thread.c > > Modified: trunk/ecore/ChangeLog > =================================================================== > --- trunk/ecore/ChangeLog 2012-02-20 14:06:04 UTC (rev 68163) > +++ trunk/ecore/ChangeLog 2012-02-20 15:57:18 UTC (rev 68164) > @@ -505,3 +505,6 @@ > > * Improve callbacks in ecore_evas to use typedefs for readability. > > +2012-02-20 Cedric Bail > + > + * Rewrite internal of Ecore_Thread to use Eina_Lock and > ecore_main_loop_thread_safe_call_async. > > Modified: trunk/ecore/NEWS > =================================================================== > --- trunk/ecore/NEWS 2012-02-20 14:06:04 UTC (rev 68163) > +++ trunk/ecore/NEWS 2012-02-20 15:57:18 UTC (rev 68164) > @@ -31,8 +31,10 @@ > - certificates can now be added for STARTTTLS > * ecore_win32: > - fix modifiers value on Windows XP > + * ecore_thread: > + - use eina_lock > + - use Ecore thread safe async call > > - > Ecore 1.1.0 > > Changes since Ecore 1.0.0: > > Modified: trunk/ecore/src/lib/ecore/ecore_thread.c > =================================================================== > --- trunk/ecore/src/lib/ecore/ecore_thread.c 2012-02-20 14:06:04 UTC (rev > 68163) > +++ trunk/ecore/src/lib/ecore/ecore_thread.c 2012-02-20 15:57:18 UTC (rev > 68164) > @@ -17,6 +17,25 @@ > > #ifdef EFL_HAVE_THREADS > > +# define LK(x) Eina_Lock x > +# define LKI(x) eina_lock_new(&(x)) > +# define LKD(x) eina_lock_free(&(x)) > +# define LKL(x) eina_lock_take(&(x)) > +# define LKU(x) eina_lock_release(&(x)) > + > +# define CD(x) Eina_Condition x > +# define CDI(x, m) eina_condition_new(&(x), &(m)) > +# define CDD(x) eina_condition_free(&(x)) > +# define CDB(x) eina_condition_broadcast(&(x)) > +# define CDW(x, t) eina_condition_timedwait(&(x), t) > + > +# define LRWK(x) Eina_RWLock x > +# define LRWKI(x) eina_rwlock_new(&(x)); > +# define LRWKD(x) eina_rwlock_free(&(x)); > +# define LRWKWL(x) eina_rwlock_take_write(&(x)); > +# define LRWKRL(x) eina_rwlock_take_read(&(x)); > +# define LRWKU(x) eina_rwlock_release(&(x)); > + > # ifdef EFL_HAVE_POSIX_THREADS > # include <pthread.h> > # ifdef __linux__ > @@ -31,28 +50,9 @@ > # define PHE(x, y) pthread_equal(x, y) > # define PHS() pthread_self() > # define PHC(x, f, d) pthread_create(&(x), NULL, (void *)f, d) > -# define PHJ(x, p) pthread_join(x, (void **)(&(p))) > +# define PHJ(x) pthread_join(x, NULL) > # define PHA(x) pthread_cancel(x) > > -# define CD(x) pthread_cond_t x > -# define CDI(x) pthread_cond_init(&(x), NULL); > -# define CDD(x) pthread_cond_destroy(&(x)); > -# define CDB(x) pthread_cond_broadcast(&(x)); > -# define CDW(x, y, t) pthread_cond_timedwait(&(x), &(y), t); > - > -# define LK(x) pthread_mutex_t x > -# define LKI(x) pthread_mutex_init(&(x), NULL); > -# define LKD(x) pthread_mutex_destroy(&(x)); > -# define LKL(x) pthread_mutex_lock(&(x)); > -# define LKU(x) pthread_mutex_unlock(&(x)); > - > -# define LRWK(x) pthread_rwlock_t x > -# define LRWKI(x) pthread_rwlock_init(&(x), NULL); > -# define LRWKD(x) pthread_rwlock_destroy(&(x)); > -# define LRWKWL(x) pthread_rwlock_wrlock(&(x)); > -# define LRWKRL(x) pthread_rwlock_rdlock(&(x)); > -# define LRWKU(x) pthread_rwlock_unlock(&(x)); > - > # else /* EFL_HAVE_WIN32_THREADS */ > > # define WIN32_LEAN_AND_MEAN > @@ -108,209 +108,9 @@ > return 0; > } > > -# define PHJ(x, p) _ecore_thread_win32_join(x, (void **)(&(p))) > +# define PHJ(x) _ecore_thread_win32_join(x, NULL) > # define PHA(x) TerminateThread(x->thread, 0) > > -# define LK(x) HANDLE x > -# define LKI(x) x = CreateMutex(NULL, FALSE, NULL) > -# define LKD(x) CloseHandle(x) > -# define LKL(x) WaitForSingleObject(x, INFINITE) > -# define LKU(x) ReleaseMutex(x) > - > -typedef struct > -{ > - HANDLE semaphore; > - LONG threads_count; > - CRITICAL_SECTION threads_count_lock; > -} win32_cond; > - > -# define CD(x) win32_cond * x > - > -# define CDI(x) \ > - do { \ > - x = (win32_cond *)calloc(1, sizeof(win32_cond)); \ > - if (x) \ > - { \ > - x->semaphore = CreateSemaphore(NULL, 0, 0x7fffffff, NULL); \ > - if (x->semaphore) \ > - InitializeCriticalSection(&x->threads_count_lock); \ > - else \ > - { \ > - free(x); \ > - x = NULL; \ > - } \ > - } \ > - } while (0) > - > -# define CDD(x) \ > - do { \ > - CloseHandle(x->semaphore); \ > - free(x); \ > - x = NULL; \ > - } while (0) > - > -# define CDB(x) \ > - do { \ > - EnterCriticalSection(&x->threads_count_lock); \ > - if (x->threads_count > 0) \ > - ReleaseSemaphore(x->semaphore, x->threads_count, NULL); \ > - LeaveCriticalSection (&x->threads_count_lock); \ > - } while (0) > - > -int > -_ecore_thread_win32_cond_timedwait(win32_cond *c, > - HANDLE *external_mutex, > - struct timeval *t) > -{ > - DWORD res; > - DWORD val = t->tv_sec * 1000 + (t->tv_usec / 1000); > - LKL(external_mutex); > - EnterCriticalSection (&c->threads_count_lock); > - c->threads_count++; > - LeaveCriticalSection (&c->threads_count_lock); > - LKU(external_mutex); > - res = WaitForSingleObject(c->semaphore, val); > - if (res == WAIT_OBJECT_0) > - return 0; > - else > - return -1; > -} > - > -# define CDW(x, y, t) _ecore_thread_win32_cond_timedwait(x, y, t) > - > -typedef struct > -{ > - LONG readers_count; > - LONG writers_count; > - int readers; > - int writers; > - LK(mutex); > - CD(cond_read); > - CD(cond_write); > -} win32_rwl; > - > -# define LRWK(x) win32_rwl * x > -# define LRWKI(x) \ > - do { \ > - x = (win32_rwl *)calloc(1, sizeof(win32_rwl)); \ > - if (x) \ > - { \ > - LKI(x->mutex); \ > - if (x->mutex) \ > - { \ > - CDI(x->cond_read); \ > - if (x->cond_read) \ > - { \ > - CDI(x->cond_write); \ > - if (!x->cond_write) \ > - { \ > - CDD(x->cond_read); \ > - LKD(x->mutex); \ > - free(x); \ > - x = NULL; \ > - } \ > - } \ > - else \ > - { \ > - LKD(x->mutex); \ > - free(x); \ > - x = NULL; \ > - } \ > - } \ > - else \ > - { \ > - free(x); \ > - x = NULL; \ > - } \ > - } \ > - } while (0) > - > -# define LRWKD(x) \ > - do { \ > - LKU(x->mutex); \ > - LKD(x->mutex); \ > - CDD(x->cond_write); \ > - CDD(x->cond_read); \ > - free(x); \ > - } while (0) > -# define LRWKWL(x) > \ > - do { > \ > - DWORD res; > \ > - LKU(x->mutex); > \ > - if (x->writers || x->readers > 0) > \ > - { > \ > - x->writers_count++; > \ > - while (x->writers || x->readers > 0) > \ > - { > \ > - EnterCriticalSection(&x->cond_write->threads_count_lock); > \ > - x->cond_read->threads_count++; > \ > - LeaveCriticalSection(&x->cond_write->threads_count_lock); > \ > - res = WaitForSingleObject(x->cond_write->semaphore, > INFINITE); \ > - if (res != WAIT_OBJECT_0) break; > \ > - } > \ > - x->writers_count--; > \ > - } > \ > - if (res == 0) x->writers_count = 1; > \ > - LKU(x->mutex); > \ > - } while (0) > -# define LRWKRL(x) > \ > - do { > \ > - DWORD res; > \ > - LKL(x->mutex); > \ > - if (x->writers) > \ > - { > \ > - x->readers_count++; > \ > - while (x->writers) > \ > - { > \ > - EnterCriticalSection(&x->cond_write->threads_count_lock); > \ > - x->cond_read->threads_count++; > \ > - LeaveCriticalSection(&x->cond_write->threads_count_lock); > \ > - res = WaitForSingleObject(x->cond_write->semaphore, > INFINITE); \ > - if (res != WAIT_OBJECT_0) break; > \ > - } > \ > - x->readers_count--; > \ > - } > \ > - if (res == 0) > \ > - x->readers++; > \ > - LKU(x->mutex); > \ > - } while (0) > -# define LRWKU(x) \ > - do { \ > - LKL(x->mutex); \ > - if (x->writers) \ > - { \ > - x->writers = 0; \ > - if (x->readers_count == 1) \ > - { \ > - EnterCriticalSection(&x->cond_read->threads_count_lock); \ > - if (x->cond_read->threads_count > 0) \ > - ReleaseSemaphore(x->cond_read->semaphore, 1, 0); \ > - LeaveCriticalSection(&x->cond_read->threads_count_lock); \ > - } \ > - else if (x->readers_count > 0) \ > - CDB(x->cond_read); \ > - else if (x->writers_count > 0) \ > - { \ > - EnterCriticalSection (&x->cond_write->threads_count_lock); \ > - if (x->cond_write->threads_count > 0) \ > - ReleaseSemaphore(x->cond_write->semaphore, 1, 0); \ > - LeaveCriticalSection (&x->cond_write->threads_count_lock); \ > - } \ > - } \ > - else if (x->readers > 0) \ > - { \ > - x->readers--; \ > - if (x->readers == 0 && x->writers_count > 0) \ > - { \ > - EnterCriticalSection (&x->cond_write->threads_count_lock); \ > - if (x->cond_write->threads_count > 0) \ > - ReleaseSemaphore(x->cond_write->semaphore, 1, 0); \ > - LeaveCriticalSection (&x->cond_write->threads_count_lock); \ > - } \ > - } \ > - LKU(x->mutex); \ > - } while (0) > - > # endif > > #endif > @@ -336,14 +136,24 @@ > { > Ecore_Thread_Cb func_heavy; > Ecore_Thread_Notify_Cb func_notify; > - Ecore_Pipe *notify; > > - Ecore_Pipe *direct_pipe; > Ecore_Pthread_Worker *direct_worker; > > int send; > int received; > } feedback_run; > + struct { > + Ecore_Thread_Cb func_main; > + Ecore_Thread_Notify_Cb func_notify; > + > + Ecore_Pipe *send; > + Ecore_Pthread_Worker *direct_worker; > + > + struct { > + int send; > + int received; > + } from, to; > + } message_run; > } u; > > Ecore_Thread_Cb func_cancel; > @@ -357,47 +167,63 @@ > > const void *data; > > - Eina_Bool cancel : 1; > - Eina_Bool feedback_run : 1; > - Eina_Bool kill : 1; > - Eina_Bool reschedule : 1; > - Eina_Bool no_queue : 1; > + volatile int cancel; > + > +#ifdef EFL_HAVE_THREADS > + LK(cancel_mutex); > +#endif > + > + Eina_Bool message_run : 1; > + Eina_Bool feedback_run : 1; > + Eina_Bool kill : 1; > + Eina_Bool reschedule : 1; > + Eina_Bool no_queue : 1; > }; > > #ifdef EFL_HAVE_THREADS > typedef struct _Ecore_Pthread_Data Ecore_Pthread_Data; > - > struct _Ecore_Pthread_Data > { > Ecore_Pthread_Worker *death_job; > - Ecore_Pipe *p; > void *data; > PH(thread); > }; > + > +typedef struct _Ecore_Pthread_Notify Ecore_Pthread_Notify; > +struct _Ecore_Pthread_Notify > +{ > + Ecore_Pthread_Worker *work; > + const void *user_data; > +}; > + > +typedef void *(*Ecore_Thread_Sync_Cb)(void* data, Ecore_Thread *thread); > + > +typedef struct _Ecore_Pthread_Message Ecore_Pthread_Message; > +struct _Ecore_Pthread_Message > +{ > + union { > + Ecore_Thread_Cb async; > + Ecore_Thread_Sync_Cb sync; > + } u; > +
can you rplace "pthread" by just "thread" string (even if it's internal code) ? Vincent ------------------------------------------------------------------------------ Try before you buy = See our experts in action! The most comprehensive online learning library for Microsoft developers is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, Metro Style Apps, more. Free future releases when you subscribe now! http://p.sf.net/sfu/learndevnow-dev2 _______________________________________________ enlightenment-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/enlightenment-devel
