[Libreoffice-commits] core.git: vcl/inc vcl/ios

Tor Lillqvist tml at iki.fi
Sat Mar 30 05:35:29 PDT 2013


 vcl/inc/ios/iosinst.hxx |    1 
 vcl/ios/iosinst.cxx     |   84 ++++++++++++++++++++++++++++++++++++++++++------
 2 files changed, 75 insertions(+), 10 deletions(-)

New commits:
commit 428ae24e55b1b2d7c9578d0e8ac58bb8e202c3be
Author: Tor Lillqvist <tml at iki.fi>
Date:   Sat Mar 30 14:28:13 2013 +0200

    Unbreak use of pthread condition variables
    
    I am not really satisfied yet with how the UI redrawing in the app now
    works (during startup, which of course is more or less all the app
    does so far).
    
    It can take quite some time before a "link" (function to be called)
    posted with PostUserEvent() gets run (if there are lots of
    time-consuming other "user events" in the queue already, or
    something?), and blocking the UI thread for that time is not
    acceptable. Will have to come up with some more complicated solution.
    
    Change-Id: Icab20183df3bc4980ae33f0502d10397802cc391

diff --git a/vcl/inc/ios/iosinst.hxx b/vcl/inc/ios/iosinst.hxx
index 654bd58..3b87de6 100644
--- a/vcl/inc/ios/iosinst.hxx
+++ b/vcl/inc/ios/iosinst.hxx
@@ -53,6 +53,7 @@ public:
                   const basegfx::B2IBox& rDamageRect);
 
     typedef struct {
+        bool done;
         CGContextRef context;
         CGRect rect;
     } RenderWindowsArg;
diff --git a/vcl/ios/iosinst.cxx b/vcl/ios/iosinst.cxx
index b2c1516..4767c46 100644
--- a/vcl/ios/iosinst.cxx
+++ b/vcl/ios/iosinst.cxx
@@ -18,7 +18,7 @@
  */
 
 #include <premac.h>
-#include <CoreGraphics/CoreGraphics.h>
+#include <UIKit/UIKit.h>
 #include <postmac.h>
 
 #include <osl/detail/ios-bootstrap.h>
@@ -87,9 +87,26 @@ IosSalInstance *IosSalInstance::getInstance()
 IosSalInstance::IosSalInstance( SalYieldMutex *pMutex )
     : SvpSalInstance( pMutex )
 {
-    pthread_cond_init( &m_aRenderCond, NULL );
-    pthread_mutex_init( &m_aRenderMutex, NULL );
-    pthread_mutex_lock( &m_aRenderMutex );
+    int rc;
+
+    rc = pthread_cond_init( &m_aRenderCond, NULL );
+    SAL_WARN_IF( rc != 0, "vcl.ios", "pthread_cond_init failed: " << strerror( rc ) );
+
+#if OSL_DEBUG_LEVEL > 0
+    pthread_mutexattr_t mutexattr;
+
+    rc = pthread_mutexattr_init( &mutexattr );
+    SAL_WARN_IF( rc != 0, "vcl.ios", "pthread_mutexattr_init failed: " << strerror( rc ) );
+
+    rc = pthread_mutexattr_settype( &mutexattr, PTHREAD_MUTEX_ERRORCHECK );
+    SAL_WARN_IF( rc != 0, "vcl.ios", "pthread_mutexattr_settype failed: " << strerror( rc ) );
+
+    rc = pthread_mutex_init( &m_aRenderMutex, &mutexattr );
+    SAL_WARN_IF( rc != 0, "vcl.ios", "pthread_mutex_init failed: " << strerror( rc ) );
+#else
+    rc = pthread_mutex_init( &m_aRenderMutex, NULL );
+    SAL_WARN_IF( rc != 0, "vcl.ios", "pthread_mutex_init failed: " << strerror( rc ) );
+#endif
 }
 
 IosSalInstance::~IosSalInstance()
@@ -264,9 +281,20 @@ void lo_set_view_size(int width, int height)
 
 IMPL_LINK( IosSalInstance, RenderWindows, RenderWindowsArg*, arg )
 {
-    int i = 0;
-    std::list< SalFrame* >::const_iterator it;
-    for( it = getFrames().begin(); it != getFrames().end(); i++, it++ ) {
+    int rc;
+
+    NSLog(@"RenderWindows: start");
+
+    rc = pthread_mutex_lock( &m_aRenderMutex );
+    SAL_WARN_IF( rc != 0, "vcl.ios", "pthread_mutex_lock failed: " << strerror( rc ) );
+
+    NSLog(@"RenderWindows: mutex locked");
+
+    NSDate *a = [NSDate date];
+
+    for( std::list< SalFrame* >::const_iterator it = getFrames().begin();
+         it != getFrames().end();
+         it++ ) {
         SvpSalFrame *pFrame = static_cast<SvpSalFrame *>(*it);
         SalFrameGeometry aGeom = pFrame->GetGeometry();
         CGRect bbox = CGRectMake( aGeom.nX, aGeom.nY, aGeom.nWidth, aGeom.nHeight );
@@ -291,19 +319,55 @@ IMPL_LINK( IosSalInstance, RenderWindows, RenderWindowsArg*, arg )
             CGContextDrawImage( arg->context, bbox, image );
         }
     }
-    pthread_cond_signal( &m_aRenderCond );
+
+    arg->done = true;
+
+    rc = pthread_cond_signal( &m_aRenderCond );
+    SAL_WARN_IF( rc != 0, "vcl.ios", "pthread_cond_signal failed:" << strerror( rc ) );
+
+    NSLog(@"RenderWindows: took %f s", [[NSDate date] timeIntervalSinceDate: a]);
+
+    rc = pthread_mutex_unlock( &m_aRenderMutex );
+    SAL_WARN_IF( rc != 0, "vcl.ios", "pthread_mutex_unlock failed: " << strerror( rc ) );
+
+    NSLog(@"RenderWindows: mutex unlocked");
+
     return 0;
 }
 
 extern "C"
 void lo_render_windows( CGContextRef context, CGRect rect )
 {
+    int rc;
     IosSalInstance *pInstance = IosSalInstance::getInstance();
+
     if ( pInstance == NULL )
         return;
-    IosSalInstance::RenderWindowsArg arg = { context, rect };
+
+    NSLog(@"lo_render_windows: start");
+
+    rc = pthread_mutex_lock( &pInstance->m_aRenderMutex );
+    if (rc != 0) {
+        SAL_WARN( "vcl.ios", "pthread_mutex_lock failed: " << strerror( rc ) );
+        return;
+    }
+
+    NSLog(@"lo_render_windows: mutex locked");
+
+    IosSalInstance::RenderWindowsArg arg = { false, context, rect };
     Application::PostUserEvent( LINK( pInstance, IosSalInstance, RenderWindows), &arg );
-    pthread_cond_wait( &pInstance->m_aRenderCond, &pInstance->m_aRenderMutex );
+
+    while (!arg.done) {
+        rc = pthread_cond_wait( &pInstance->m_aRenderCond, &pInstance->m_aRenderMutex );
+        SAL_WARN_IF( rc != 0, "vcl.ios", "pthread_cond_wait failed: " << strerror( rc ) );
+    }
+
+    NSLog(@"lo_render_windows: mutex unlocked");
+
+    rc = pthread_mutex_unlock( &pInstance->m_aRenderMutex );
+    SAL_WARN_IF( rc != 0, "vcl.ios", "pthread_mutex_unlock failed: " << strerror( rc ) );
+
+    NSLog(@"lo_render_windows: done");
 }
 
 extern "C"


More information about the Libreoffice-commits mailing list