[ECOS] Scheduler lock in Doug Lea's mallock implementation
bob.koninckx@o-3s.com
bob.koninckx@o-3s.com
Thu Aug 17 06:45:00 GMT 2006
Hi,
Can someone explain me why the default memory allocator locks the scheduler? I would expect it to be legitimate for a low priority thread with no real time constraints to do dynamic memory allocation without influencing the real-time behaviour of threads with real-time constraints, as long as they have a higher priority. We experienced timing problems with high priority real-time threads that do not touch the heap because of dynamic memory allocation in a lower priority thread without real-time constraints and traced it down to the code snippet from packages/services/memalloc/common/current/include/mempolt2.inl below
// get some memory; wait if none available
template <class T>
inline cyg_uint8 *
Cyg_Mempolt2<T>::alloc( cyg_int32 size )
{
CYG_REPORT_FUNCTION();
// Prevent preemption
Cyg_Scheduler::lock();
CYG_ASSERTCLASS( this, "Bad this pointer");
cyg_uint8 *ret;
ret = pool.try_alloc( size );
if ( ret ) {
Cyg_Scheduler::unlock();
CYG_ASSERTCLASS( this, "Bad this pointer");
CYG_REPORT_RETVAL( ret );
return ret;
}
Cyg_Thread *self = Cyg_Thread::self();
Mempolt2WaitInfo waitinfo( size );
CYG_MEMALLOC_FAIL(size);
self->set_wait_info( (CYG_ADDRWORD)&waitinfo );
self->set_sleep_reason( Cyg_Thread::WAIT );
self->sleep();
queue.enqueue( self );
CYG_ASSERT( 1 == Cyg_Scheduler::get_sched_lock(),
"Called with non-zero scheduler lock");
// Unlock scheduler and allow other threads to run
Cyg_Scheduler::unlock();
[...]
Thanks,
Bob
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss
More information about the Ecos-discuss
mailing list