[libvirt] [PATCH 1/2] Java bindings for domain events

Daniel Veillard veillard at redhat.com
Fri Nov 21 13:49:21 UTC 2008


On Wed, Nov 19, 2008 at 11:22:31AM -0500, David Lively wrote:
> On Wed, 2008-11-19 at 10:35 -0500, David Lively wrote:
> > The patch already synchronizes operations using virConnect objects with
> > each other.  To avoid making illegal EventImpl callbacks from Java for
> > the current libvirt, I have to lock every Connect object known to Java
> > and hold off creating new connections (via open & friends) around an
> > EventImpl callback.  This sounds rather appalling to me, but it's
> > starting to sound like the only practical route in the short term
> > (unless it turns out we can rely on pthreads in WIN32 ...).
> 
> Hmmm ... maybe the less appalling :-) route is practical.  Currently, we
> require only the Windows equivalent of a simple pthread mutex.  We just
> need to support declaration, initialization, lock, unlock, and
> destruction, something like the following (thanks to Tom Hazel for
> pointing me to the Windows Mutex stuff):
> 
> #if (defined _WIN32 || defined __WIN32__)
> #define PTHREAD_MUTEX_T(v) HANDLE v
> #define pthread_mutex_init(lk,p) ((*(lk)) = CreateMutex(0, FALSE, 0))
> #define pthread_mutex_destroy(lk) CloseHandle(*(lk))
> #define pthread_mutex_lock(lk) WaitForSingleObject(*(lk), INFINITE)
> #define pthread_mutex_unlock(lk) ReleaseMutex(*(lk))
> #define pthread_sigmask(h, s, o) sigprocmask((h), (s), (o))
> #endif
> 
> I'm not a Windows guy, so maybe I'm missing something.  But this doesn't
> seem like a Big Deal ...

  note that libxml2 that we rely on has a fully ported mutex basic API
in libxml/threads.h

/*
 * xmlMutex are a simple mutual exception locks.
 */
typedef struct _xmlMutex xmlMutex;
typedef xmlMutex *xmlMutexPtr;

/*
 * xmlRMutex are reentrant mutual exception locks.
 */
typedef struct _xmlRMutex xmlRMutex;
typedef xmlRMutex *xmlRMutexPtr;

XMLPUBFUN xmlMutexPtr XMLCALL
                        xmlNewMutex     (void);
XMLPUBFUN void XMLCALL
                        xmlMutexLock    (xmlMutexPtr tok);
XMLPUBFUN void XMLCALL
                        xmlMutexUnlock  (xmlMutexPtr tok);
XMLPUBFUN void XMLCALL
                        xmlFreeMutex    (xmlMutexPtr tok);

XMLPUBFUN xmlRMutexPtr XMLCALL
                        xmlNewRMutex    (void);
XMLPUBFUN void XMLCALL
                        xmlRMutexLock   (xmlRMutexPtr tok);
XMLPUBFUN void XMLCALL
                        xmlRMutexUnlock (xmlRMutexPtr tok);
XMLPUBFUN void XMLCALL
                        xmlFreeRMutex   (xmlRMutexPtr tok);

 in case you really want to do the exclusive locking at the C level
while still being portable.

  Still it's probably better to try to implement most of this at the
Java level, at least IMHO,

Daniel

-- 
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel at veillard.com  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/




More information about the libvir-list mailing list