This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

ecos sync problem: Does it work well?



Hi,nickg! in support to tcp/ip stack,ecos packs two new sync function: cyg_tsleep(...) cyg_wakeup(...) in synch.c file. according to ecos scheduler,I doubt it does not work well as following:

int cyg_tsleep(void *chan, int pri, char *wmesg, int timo)
{
int i, res = 0;
struct wakeup_event *ev; cyg_tick_count_t sleep_time;
cyg_handle_t self = cyg_thread_self();
int old_splflags = 0; // no flags held


cyg_scheduler_lock();//*******************lock=1,threads switch will be impossible until last cyg_scheduler_unlock(),right?********************/

// Safely find a free slot:
for (i = 0, ev = wakeup_list; i < CYGPKG_NET_NUM_WAKEUP_EVENTS; i++, ev++) {
if (ev->chan == 0) {
ev->chan = chan;
break;
}
}
CYG_ASSERT( i < CYGPKG_NET_NUM_WAKEUP_EVENTS, "no sleep slots" );
CYG_ASSERT( 1 == cyg_scheduler_read_lock(),
"Tsleep - called with scheduler locked" );
// Defensive:
if ( i >= CYGPKG_NET_NUM_WAKEUP_EVENTS ) {
cyg_scheduler_unlock();
return ETIMEDOUT;
}


// If we are the owner, then we must release the mutex when
// we wait.
if ( self == splx_thread ) {
old_splflags = spl_state; // Keep them for restoration
CYG_ASSERT( spl_state, "spl_state not set" );
// Also want to assert that the mutex is locked...
CYG_ASSERT( splx_mutex.locked, "Splx mutex not locked" );
CYG_ASSERT( (cyg_handle_t)splx_mutex.owner == self, "Splx mutex not mine" );
splx_thread = 0;
spl_state = 0;
cyg_mutex_unlock( &splx_mutex );
}


// Re-initialize the semaphore - it might have counted up arbitrarily
// in the time between a prior sleeper being signalled and them
// actually running.
cyg_semaphore_init(&ev->sem, 0);


// This part actually does the wait:
// As of the new kernel, we can do this without unlocking the scheduler
if (timo) {
sleep_time = cyg_current_time() + timo;
if (!cyg_semaphore_timed_wait(&ev->sem, sleep_time)) { /**********lock will >1,never wait!!!*****************************/
if( cyg_current_time() >= sleep_time )
res = ETIMEDOUT;
else
res = EINTR;
}
} else {
if (!cyg_semaphore_wait(&ev->sem) ) {**********never wait for lock>1
res = EINTR;
}
}


ev->chan = 0; // Free the slot - the wakeup call cannot do this.
if ( old_splflags ) { // restore to previous state
// As of the new kernel, we can do this with the scheduler locked
cyg_mutex_lock( &splx_mutex ); // this might wait
CYG_ASSERT( 0 == splx_thread, "Splx thread set in tsleep" );
CYG_ASSERT( 0 == spl_state, "spl_state set in tsleep" );
splx_thread = self; // got it now...
spl_state = old_splflags;
}


cyg_scheduler_unlock();/****************till here,lock=0,threads switch is possible,this means tsleep will never sleep!!!*************** /
return res;
}




right?
but i do not know why redhat reported that stack works well?


BRS johnsonest

_________________________________________________________________
免费下载 MSN Explorer: http://explorer.msn.com/lccn



-- Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos and search the list archive: http://sources.redhat.com/ml/ecos-discuss


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]