A mutual exclusion device is necessary.

OW_get, OW_put, and OW_finish all lock the common mutex.

If OW_get and OW_put /really can/ be used simultaneously, then a
condition is required:


in OW_get and OW_put:

LOCK(mutex);
level++;
UNLOCK(mutex);
{ real code }
LOCK(mutex);
level--;
SIGNAL(cond);
UNLOCK(mutex);


and in OW_finish:

LOCK(mutex);
while (level > 0) COND(cond,mutex);
{ destroy interface safely now }
UNLOCK(mutex); 


in pthreads this is:

pthread_cond_t cond;
pthread_mutex_t mutex;

#define COND(q,p) pthread_cond_wait(&q,&p)
#define SIGNAL(q) pthread_cond_signal(&q)
#define LOCK(q) pthread_mutex_lock(&q)
#define UNLOCK(q) pthread_mutex_unlock(&q)


NOTE: this is NOT the same mutex as you're using for acessing indev
(capi_mutex) - but a different one JUST for this cond variable.


BY THE WAY, shouldn't these things be static? Is there really a reason
user programs should have access to it?


On Sun, 2005-10-16 at 22:57 -0400, Paul Alfille wrote:
> Added the same protection for the SWIG prototype (owperl, owpython, owphp).
> 
> It occurs to me that it is possible that a "OW_finish" could be called while 
> an OW_get or OW_put is in progress -- could be messy since the adapters would 
> be disappearing while being used. I'll have to get out the old textbook to 
> figure the proper flag for this one -- a semaphore?
> 
> Paul
> 
> On Sunday 16 October 2005 01:33 am, Paul Alfille wrote:
> > Ok uploaded some OWCAPI changes.
> >
> > 1. I've put in your char** mode. I'm really starting to warm up to it.
> >
> > 2. Protection against multiple "init"s, no "init"s, simultaneous "init"s...
> >
> > Paul
> 
> 
> -------------------------------------------------------
> This SF.Net email is sponsored by:
> Power Architecture Resource Center: Free content, downloads, discussions,
> and more. http://solutions.newsforge.com/ibmarch.tmpl
> _______________________________________________
> Owfs-developers mailing list
> Owfs-developers@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/owfs-developers
-- 
Internet Connection High Quality Web Hosting
http://www.internetconnection.net/



-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Owfs-developers mailing list
Owfs-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/owfs-developers

Reply via email to