浏览代码

Fixed recursive mutex lock issues.

Sascha Zelzer 13 年之前
父节点
当前提交
8f5a5e59ca

+ 1 - 1
Libs/PluginFramework/ctkServiceRegistrationPrivate.cpp

@@ -27,7 +27,7 @@ ctkServiceRegistrationPrivate::ctkServiceRegistrationPrivate(
   const ctkDictionary& props)
   : ref(1), service(service), plugin(plugin), reference(this),
     properties(props), available(true), unregistering(false),
-    propsLock(QMutex::Recursive)
+    propsLock()
 {
 
 }

+ 5 - 8
Libs/PluginFramework/ctkServiceTracker.tpp

@@ -220,11 +220,7 @@ QList<ctkServiceReference> ctkServiceTracker<S,T>::getServiceReferences() const
   }
   {
     QMutexLocker lockT(t.data());
-    if (t->size() == 0)
-    {
-      return QList<ctkServiceReference>();
-    }
-    return t->getTracked();
+    return d->getServiceReferences_unlocked(t.data());
   }
 }
 
@@ -337,11 +333,12 @@ QList<T> ctkServiceTracker<S,T>::getServices() const
   }
   {
     QMutexLocker lockT(t.data());
-    QList<ctkServiceReference> references = getServiceReferences();
+    QList<ctkServiceReference> references = d->getServiceReferences_unlocked(t.data());
     QList<T> objects;
     foreach (ctkServiceReference ref, references)
     {
-      objects << getService(ref);
+      //objects << getService(ref);
+      objects << t->getCustomizedObject(ref);
     }
     return objects;
   }
@@ -358,7 +355,7 @@ T ctkServiceTracker<S,T>::getService() const
     if (d->DEBUG)
     {
       qDebug() << "ctkServiceTracker<S,T>::getService[cached]:"
-                   << d->filter;
+               << d->filter;
     }
     return service;
   }

+ 2 - 0
Libs/PluginFramework/ctkServiceTrackerPrivate.h

@@ -69,6 +69,8 @@ public:
   QList<ctkServiceReference> getInitialReferences(const QString& className,
                                                   const QString& filterString);
 
+  QList<ctkServiceReference> getServiceReferences_unlocked(ctkTrackedService<S,T>* t) const;
+
   /* set this to true to compile in debug messages */
   static const bool	DEBUG; //	= false;
 

+ 11 - 0
Libs/PluginFramework/ctkServiceTrackerPrivate.tpp

@@ -122,6 +122,17 @@ QList<ctkServiceReference> ctkServiceTrackerPrivate<S,T>::getInitialReferences(c
 
 //----------------------------------------------------------------------------
 template<class S, class T>
+QList<ctkServiceReference> ctkServiceTrackerPrivate<S,T>::getServiceReferences_unlocked(ctkTrackedService<S,T>* t) const
+{
+  if (t->size() == 0)
+  {
+    return QList<ctkServiceReference>();
+  }
+  return t->getTracked();
+}
+
+//----------------------------------------------------------------------------
+template<class S, class T>
 QSharedPointer<ctkTrackedService<S,T> > ctkServiceTrackerPrivate<S,T>::tracked() const
 {
   return trackedService;

+ 10 - 4
Libs/PluginFramework/ctkServices.cpp

@@ -63,7 +63,7 @@ ctkDictionary ctkServices::createServiceProperties(const ctkDictionary& in,
 
 //----------------------------------------------------------------------------
 ctkServices::ctkServices(ctkPluginFrameworkContext* fwCtx)
-  : mutex(QMutex::Recursive), framework(fwCtx)
+  : mutex(), framework(fwCtx)
 {
 
 }
@@ -166,7 +166,7 @@ ctkServiceReference ctkServices::get(ctkPluginPrivate* plugin, const QString& cl
 {
   QMutexLocker lock(&mutex);
   try {
-    QList<ctkServiceReference> srs = get(clazz, QString(), plugin);
+    QList<ctkServiceReference> srs = get_unlocked(clazz, QString(), plugin);
     if (framework->debug.service_reference)
     {
       qDebug() << "get service ref" << clazz << "for plugin"
@@ -186,9 +186,15 @@ ctkServiceReference ctkServices::get(ctkPluginPrivate* plugin, const QString& cl
 QList<ctkServiceReference> ctkServices::get(const QString& clazz, const QString& filter,
                                             ctkPluginPrivate* plugin) const
 {
-  Q_UNUSED(plugin)
-
   QMutexLocker lock(&mutex);
+  return get_unlocked(clazz, filter, plugin);
+}
+
+//----------------------------------------------------------------------------
+QList<ctkServiceReference> ctkServices::get_unlocked(const QString& clazz, const QString& filter,
+                                                     ctkPluginPrivate* plugin) const
+{
+  Q_UNUSED(plugin)
 
   QListIterator<ctkServiceRegistration>* s = 0;
   QList<ctkServiceRegistration> v;

+ 5 - 0
Libs/PluginFramework/ctkServices_p.h

@@ -179,6 +179,11 @@ public:
    */
   QList<ctkServiceRegistration> getUsedByPlugin(QSharedPointer<ctkPlugin> p) const;
 
+private:
+
+  QList<ctkServiceReference> get_unlocked(const QString& clazz, const QString& filter,
+                                          ctkPluginPrivate* plugin) const;
+
 };