? 640508-3_locking.patch
? libraries/simplepie.inc
Index: includes/FeedsImporter.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/feeds/includes/FeedsImporter.inc,v
retrieving revision 1.19
diff -u -p -r1.19 FeedsImporter.inc
--- includes/FeedsImporter.inc	19 Jun 2010 19:40:43 -0000	1.19
+++ includes/FeedsImporter.inc	4 Jul 2010 21:29:25 -0000
@@ -75,7 +75,11 @@ class FeedsImporter extends FeedsConfigu
    *   Throws Exception if an error occurs when expiring items.
    */
   public function expire($time = NULL) {
-    return $this->processor->expire($time);
+    if (lock_acquire("feeds_expire_{$this->id}", 60.0)) {
+      $result = $this->processor->expire($time);
+      lock_release("feeds_expire_{$this->id}");
+    }
+    return $result;
   }
 
   /**
Index: includes/FeedsSource.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/feeds/includes/FeedsSource.inc,v
retrieving revision 1.13
diff -u -p -r1.13 FeedsSource.inc
--- includes/FeedsSource.inc	19 Jun 2010 19:40:43 -0000	1.13
+++ includes/FeedsSource.inc	4 Jul 2010 21:29:25 -0000
@@ -124,6 +124,9 @@ class FeedsSource extends FeedsConfigura
    *   Throws Exception if an error occurs when importing.
    */
   public function import() {
+    if (!$this->acquireLock('import')) {
+      return FEEDS_BATCH_ACTIVE;
+    }
     try {
       if (!$this->batch || !($this->batch instanceof FeedsImportBatch)) {
         $this->batch = $this->importer->fetcher->fetch($this);
@@ -136,10 +139,12 @@ class FeedsSource extends FeedsConfigura
       }
     }
     catch (Exception $e) {
+      $this->releaseLock('import');
       unset($this->batch);
       $this->save();
       throw $e;
     }
+    $this->releaseLock('import');
     $this->save();
     return $result;
   }
@@ -155,6 +160,9 @@ class FeedsSource extends FeedsConfigura
    *   Throws Exception if an error occurs when clearing.
    */
   public function clear() {
+    if (!$this->acquireLock('clear')) {
+      return FEEDS_BATCH_ACTIVE;
+    }
     try {
       $this->importer->fetcher->clear($this);
       $this->importer->parser->clear($this);
@@ -167,10 +175,12 @@ class FeedsSource extends FeedsConfigura
       }
     }
     catch (Exception $e) {
+      $this->releaseLock('clear');
       unset($this->batch);
       $this->save();
       throw $e;
     }
+    $this->releaseLock('clear');
     $this->save();
     return $result;
   }
@@ -288,4 +298,27 @@ class FeedsSource extends FeedsConfigura
       }
     }
   }
+
+  /**
+   * Acquire lock for this source.
+   *
+   * @param $action
+   *   A string identifying the action to acquire a lock for.
+   *
+   * @return
+   *   TRUE if a lock could be acquired, FALSE otherwise.
+   */
+  protected function acquireLock($action) {
+    return lock_acquire("feeds_source_{$this->id}_{$this->feed_nid}_$action", 60);
+  }
+
+  /**
+   * Release a lock for this source.
+   *
+   * @param $action
+   *   A string identifying the action to release the lock for.
+   */
+  protected function releaseLock($action) {
+    lock_release("feeds_source_{$this->id}_{$this->feed_nid}_$action");
+  }
 }
