This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
pthread_mutex_unlock when mutex is not locked
- From: Rubén Pérez de Aranda Alonso <rperez at sidsa dot es>
- To: ecos-discuss at sources dot redhat dot com
- Date: Wed, 27 Apr 2005 10:24:42 +0200
- Subject: [ECOS] pthread_mutex_unlock when mutex is not locked
- Organization: SIDSA
Hi all,
I have found a problem when I want to unlock a mutex that is not locked
by any thread. This scenario can be needed when we want to signal
a resource in hardware is free from a DSR, that is executed by a
peripheral interrupt, to threads that requires the access to this
resource. The thread will execute a lock before access to resource.
The DSR will be executing an unlock for each HW interrupt although
there aren't threads accessing to the resource.
I think the mutex must verify the lock condition before perform
an unlock operation.
I have added the next code in Cyg_Mutex::unlock(void) method:
void
Cyg_Mutex::unlock(void)
{
CYG_REPORT_FUNCTION();
// ---------------------
if (!locked)
{
CYG_INSTRUMENT_MUTEX(UNLOCK, this, 0);
CYG_REPORT_RETURN();
return;
}
// ---------------------
[...]
This scenario can also be solved using message queues or semaphores.
I prefer mutexes because the unlock condition is when their count
is equal to zero, and, in semaphores, the unlock condition is when
their count is > 0.
Regards,
Rubén
--
______________________________________________________________
Rubén Israel Pérez de Aranda Alonso
SIDSA - Semiconductores Investigación y Diseño S.A.
Parque Tecnológico de Madrid Phone : +34 91 803 5052
C/ Torres Quevedo, nº 1 Fax: +34 91 803 9557
28760 TRES CANTOS (Madrid) (SPAIN)
e-mail: rperez@sidsa.com www.sidsa.com
______________________________________________________________
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss