mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-18 03:09:11 +02:00
* made libcups initialization/finalization more threadsafe
git-svn-id: trunk@37620 -
This commit is contained in:
parent
4b8dcd676c
commit
0c07db3904
@ -1179,9 +1179,8 @@ var RefCount : integer;
|
|||||||
procedure InitializeCups;
|
procedure InitializeCups;
|
||||||
var i : integer;
|
var i : integer;
|
||||||
begin
|
begin
|
||||||
inc(RefCount);
|
|
||||||
//debugln('InitializeCups RefCount=',dbgs(RefCount));
|
//debugln('InitializeCups RefCount=',dbgs(RefCount));
|
||||||
if RefCount = 1 then
|
if InterLockedIncrement(RefCount)=1 then
|
||||||
begin
|
begin
|
||||||
for i:=0 to MaxcupsLibs do
|
for i:=0 to MaxcupsLibs do
|
||||||
begin
|
begin
|
||||||
@ -1193,7 +1192,7 @@ begin
|
|||||||
if CupsLibHandle = nilhandle then
|
if CupsLibHandle = nilhandle then
|
||||||
begin
|
begin
|
||||||
//debugln('InitializeCups load cups lib failed');
|
//debugln('InitializeCups load cups lib failed');
|
||||||
RefCount := 0;
|
InterLockedDecrement(RefCount);
|
||||||
raise EInOutError.Create('Can not load cups library');
|
raise EInOutError.Create('Can not load cups library');
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -1361,13 +1360,11 @@ end;
|
|||||||
procedure FinalizeCups;
|
procedure FinalizeCups;
|
||||||
begin
|
begin
|
||||||
//debugln('* FinalizeCups');
|
//debugln('* FinalizeCups');
|
||||||
if RefCount>0 then
|
|
||||||
Dec(RefCount);
|
if InterLockedDecrement(RefCount)=0 then
|
||||||
|
|
||||||
if RefCount=0 then
|
|
||||||
begin
|
begin
|
||||||
if (CupsLibHandle<>NilHandle) and not UnloadLibrary(CupsLibHandle) then
|
if (CupsLibHandle<>NilHandle) and not UnloadLibrary(CupsLibHandle) then
|
||||||
Inc(RefCount)
|
InterLockedIncrement(RefCount)
|
||||||
else
|
else
|
||||||
CupsLibHandle := NilHandle;
|
CupsLibHandle := NilHandle;
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user