public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* [ECOS] correct handling of condition variables from DSRs
@ 2006-05-22 15:37 Neundorf, Alexander
  2006-05-23  4:49 ` [ECOS] " Sergei Organov
  0 siblings, 1 reply; 6+ messages in thread
From: Neundorf, Alexander @ 2006-05-22 15:37 UTC (permalink / raw)
  To: ecos-discuss

Hi,

the eCos docs say that condition variables can be signalled also from DSRs. Usually, in order to signal a change, the following code is required:

cyg_mutex_lock(&condition_mutex)
// ... modify the data
cyg_cond_signal(&condition_var);
cyg_mutex_unlock(&condition_mutex);


When doing this from a DSR, the mutex can't be locked, so I only can do:

cyg_cond_signal(&condition_var);


In order to receive the signal, usually I would:

cyg_mutex_lock(...);
cyg_cond_wait(...);
...
cyg_mutex_unlock();


Now this isn't synchronized with the DSR. The mutex docs say that cyg_scheduler_lock() has to be used, so it becomes:

cyg_scheduler_lock();
cyg_mutex_lock(...);
cyg_cond_wait(...);
...
cyg_mutex_unlock();
cyg_scheduler_unlock();

But the same protection has to be used when signalling from a thread, since otherwise the DSR could modify the data which are only protected by the mutex, right ?
So in order to signal the condition correctly from a thread I have to do the following:

cyg_scheduler_lock();
cyg_mutex_lock(&condition_mutex)
// ... modify the data
cyg_cond_signal(&condition_var);
cyg_mutex_unlock(&condition_mutex);
cyg_scheduler_unlock();


But since now all three participants (sender from DSR, sender from thread, receiver) are all synchronized using cyg_scheduler_lock(), do I actually still need the mutex at all ? Or can I simply ignore it ?

Bye
Alex

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2006-05-23  6:49 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-05-22 15:37 [ECOS] correct handling of condition variables from DSRs Neundorf, Alexander
2006-05-23  4:49 ` [ECOS] " Sergei Organov
2006-05-23  5:48   ` Fabian Scheler
2006-05-23  6:22     ` Sergei Organov
2006-05-23  6:26       ` Fabian Scheler
2006-05-23  6:49         ` Sergei Organov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).