Mercurial > ecos
changeset 455:1287356aa9e5
* src/mutex.cxx (pthread_cond_timedwait): Initialize clock converters
only once ever.
| author | jlarmour |
|---|---|
| date | Tue, 10 Dec 2002 02:28:21 +0000 |
| parents | 63ad56f95b9a |
| children | 2842412ce230 |
| files | packages/compat/posix/current/ChangeLog packages/compat/posix/current/src/mutex.cxx |
| diffstat | 2 files changed, 36 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/packages/compat/posix/current/ChangeLog +++ b/packages/compat/posix/current/ChangeLog @@ -1,3 +1,9 @@ +2002-12-10 Wade Jensen <waj4news@cox.net> +2002-12-10 Jonathan Larmour <jifl@eCosCentric.com> + + * src/mutex.cxx (pthread_cond_timedwait): Initialize clock converters + only once ever. + 2002-11-26 Nick Garnett <nickg@ecoscentric.com> * src/signal.cxx: Changed the three routines added in the last
--- a/packages/compat/posix/current/src/mutex.cxx +++ b/packages/compat/posix/current/src/mutex.cxx @@ -41,7 +41,7 @@ //#####DESCRIPTIONBEGIN#### // // Author(s): nickg -// Contributors: nickg, jlarmour +// Contributors: nickg, jlarmour, Wade Jensen // Date: 2000-03-27 // Purpose: POSIX pthread implementation // Description: This file contains the implementation of the POSIX pthread @@ -500,12 +500,37 @@ externC int pthread_cond_timedwait (pthr PTHREAD_CHECK( mutex ); PTHREAD_CHECK( abstime ); - cyg_tick_count ticks; - struct Cyg_Clock::converter ns_converter, sec_converter; + // Only initialize the converters once or they will consume a huge + // amount or runtime. + + static struct Cyg_Clock::converter ns_converter; + static struct Cyg_Clock::converter sec_converter; + static volatile cyg_atomic conv_init; + if (!conv_init) + { + + // Try to avoid unnecessarily locking the scheduler when we are not + // initializing the converters. Check the conv_init flag again to + // avoid race conditions. + + struct Cyg_Clock::converter temp_ns_converter, temp_sec_converter; - Cyg_Clock::real_time_clock->get_other_to_clock_converter( 1, &ns_converter ); - Cyg_Clock::real_time_clock->get_other_to_clock_converter( 1000000000, &sec_converter ); + Cyg_Clock::real_time_clock + ->get_other_to_clock_converter( 1, &temp_ns_converter ); + Cyg_Clock::real_time_clock + ->get_other_to_clock_converter( 1000000000, &temp_sec_converter ); + Cyg_Scheduler::lock(); + if (!conv_init) + { + ns_converter = temp_ns_converter; + sec_converter = temp_sec_converter; + conv_init=1; + } + Cyg_Scheduler::unlock(); + } + + cyg_tick_count ticks; ticks = Cyg_Clock::convert( abstime->tv_sec, &sec_converter ); ticks += Cyg_Clock::convert( abstime->tv_nsec, &ns_converter );
