[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: branches/KDE/3.5/kdepim/kresources/remote
From: Will Stephenson <wstephenson () kde ! org>
Date: 2007-01-25 17:07:17
Message-ID: 1169744837.260714.25252.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 627092 by wstephens:
This patch uses the resource's own KABC::Lock to lock the cache file, which inhibits \
the file_copy operation that causes the error. The resource detects its cache is \
locked after having loaded the cache, but before refreshing the cache.
The result of adding this lock is that if two processes are simultaneously reloading \
the resource, the winner will first load the cached version (call it C-1) and then \
load C0 after fetching it. The loser will load C-1, encounter the lock and stop. On \
the next iteration, Winner gets C1 and Loser gets C0.
So the result of the lockstep is that loser is at most out of date by one version of \
the resource. A better synchronisation would be if we had distributed locks so that \
Loser is notified when Winner releases its lock and then loads the fresh cache file.
M +19 -14 resourceremote.cpp
--- branches/KDE/3.5/kdepim/kresources/remote/resourceremote.cpp #627091:627092
@@ -40,7 +40,7 @@
#include <libkcal/journal.h>
#include <libkcal/filestorage.h>
-#include <kabc/locknull.h>
+#include <kabc/lock.h>
#include <kresources/configwidget.h>
@@ -93,7 +93,7 @@
setType( "remote" );
- mLock = new KABC::LockNull( true );
+ mLock = new KABC::Lock( cacheFile() );
enableChangeNotification();
}
@@ -188,21 +188,25 @@
emit resourceChanged( this );
- kdDebug() << "Download from: " << mDownloadUrl << endl;
+ if ( mLock->lock() )
+ {
+ kdDebug() << "Download from: " << mDownloadUrl << endl;
- mDownloadJob = KIO::file_copy( mDownloadUrl, KURL( cacheFile() ), -1, true,
- false, !mUseProgressManager );
- connect( mDownloadJob, SIGNAL( result( KIO::Job * ) ),
- SLOT( slotLoadJobResult( KIO::Job * ) ) );
- if ( mUseProgressManager ) {
- connect( mDownloadJob, SIGNAL( percent( KIO::Job *, unsigned long ) ),
- SLOT( slotPercent( KIO::Job *, unsigned long ) ) );
- mProgress = KPIM::ProgressManager::createProgressItem(
- KPIM::ProgressManager::getUniqueID(), i18n("Downloading Calendar") );
+ mDownloadJob = KIO::file_copy( mDownloadUrl, KURL( cacheFile() ), -1, true,
+ false, !mUseProgressManager );
+ connect( mDownloadJob, SIGNAL( result( KIO::Job * ) ),
+ SLOT( slotLoadJobResult( KIO::Job * ) ) );
+ if ( mUseProgressManager ) {
+ connect( mDownloadJob, SIGNAL( percent( KIO::Job *, unsigned long ) ),
+ SLOT( slotPercent( KIO::Job *, unsigned long ) ) );
+ mProgress = KPIM::ProgressManager::createProgressItem(
+ KPIM::ProgressManager::getUniqueID(), i18n("Downloading Calendar") );
- mProgress->setProgress( 0 );
+ mProgress->setProgress( 0 );
+ }
}
-
+ else
+ kdDebug() << "ResourceRemote::load(): cache file is locked - something else must \
be loading the file" << endl; return true;
}
@@ -234,6 +238,7 @@
mProgress = 0;
}
+ mLock->unlock();
emit resourceLoaded( this );
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic