Changeset 11022


Ignore:
Timestamp:
03/08/10 22:42:09 (2 years ago)
Author:
adamk
Message:

Speculative fix to the threading vs SQLite bug

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Padre/lib/Padre/SlaveDriver.pm

    r11008 r11022  
    7878        } => $class; 
    7979        $SlaveDriver->_init_events; 
     80 
     81        # There is no database/locking protection 
     82        # here, so this must happen before we make 
     83        # a long-term connection to the database. 
    8084        $SlaveDriver->{master} = threads->create( 
    8185            \&_slave_driver_loop, 
     
    8387            $SlaveDriver->{tid_queue} 
    8488        ); 
     89 
    8590        return $SlaveDriver; 
    8691    } 
     
    213218        last if $args eq 'STOP'; 
    214219        my $task_queue    = Padre::SlaveDriver->new->task_queue; 
     220 
     221        # Apply the database anti-lock, so there are no active DBI connection 
     222        # handles at the time we spawn the thread. 
     223        # If Padre::DB is not loaded at all, the following returns false and 
     224        # we never make the calls to the non-existant class. 
     225        my $locked = Padre::DB->can('connected') && Padre::DB->connected; 
     226        if ( $locked ) { 
     227            Padre::DB->commit; 
     228        } 
     229 
     230        # Do the actual thread spawn 
    215231        my $worker_thread = threads->create( \&_worker_loop, $task_queue ); 
    216         my $tid           = $worker_thread->tid; 
    217         $outqueue->enqueue($tid); 
     232 
     233        # Release the anti-lock on the database 
     234        if ( $locked ) { 
     235            Padre::DB->begin; 
     236        } 
     237 
     238        # Continue onwards with thready stuff 
     239        $outqueue->enqueue($worker_thread->tid); 
    218240    } 
    219241    return 1; 
Note: See TracChangeset for help on using the changeset viewer.