clobbers Gimp::lock() and Gimp::unlock() replacing them with ones that use lockfiles and flock. In many versions of Gimp/Perl, the lock methods don't do anything. This causes parallel connections to share data, such as active brushes and colors, and the active layer. This is a big problem when you're using gimp to generate dynamic web graphics. Note that this only works if all the clients are on the same system. Otherwise, you'll need to use Gimp->server_eval() to run most of this from inside the Perl-Server process. Which is fine, but then it doesn't also act as a yield.
use Gimp;
use Fcntl ':flock';
my ( $lockfile, $lock_fh );
Gimp::initialized() or Gimp::init() or Gimp::initialized() or die "fai
+led connecting to gimp server";
$lockfile = '/tmp/gimplock-' . Gimp->server_eval( q[$$] ); # append th
+e Perl-Server pid to the lockfile name, in case you have multiple Per
+l-Servers
{
no warnings 'redefine';
*Gimp::lock = sub {
open( $lock_fh, ">>$lockfile" )
or die "failed opening lockfile '$lockfile' for appending: $
+!";
return flock( $lock_fh, LOCK_EX );
};
*Gimp::yield = *Gimp::lock{CODE};
*Gimp::unlock = sub {
flock( $lock_fh, LOCK_UN );
};
}
Gimp::lock();
# ... do something with gimp ...
Gimp::yield(); # give somebody else a turn
# ... do something else with gimp ...
Gimp::unlock();