mirror of
				https://gitlab.com/freepascal.org/fpc/source.git
				synced 2025-11-04 09:02:22 +01: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;
 | 
			
		||||
var i : integer;
 | 
			
		||||
begin
 | 
			
		||||
  inc(RefCount);
 | 
			
		||||
  //debugln('InitializeCups RefCount=',dbgs(RefCount));
 | 
			
		||||
  if RefCount = 1 then
 | 
			
		||||
  if InterLockedIncrement(RefCount)=1 then
 | 
			
		||||
  begin
 | 
			
		||||
    for i:=0 to MaxcupsLibs do
 | 
			
		||||
    begin
 | 
			
		||||
@ -1193,7 +1192,7 @@ begin
 | 
			
		||||
    if CupsLibHandle = nilhandle then
 | 
			
		||||
    begin
 | 
			
		||||
      //debugln('InitializeCups load cups lib failed');
 | 
			
		||||
      RefCount := 0;
 | 
			
		||||
      InterLockedDecrement(RefCount);
 | 
			
		||||
      raise EInOutError.Create('Can not load cups library');
 | 
			
		||||
    end;
 | 
			
		||||
  end;
 | 
			
		||||
@ -1361,13 +1360,11 @@ end;
 | 
			
		||||
procedure FinalizeCups;
 | 
			
		||||
begin
 | 
			
		||||
  //debugln('* FinalizeCups');
 | 
			
		||||
  if RefCount>0 then
 | 
			
		||||
    Dec(RefCount);
 | 
			
		||||
    
 | 
			
		||||
  if RefCount=0 then
 | 
			
		||||
 | 
			
		||||
  if InterLockedDecrement(RefCount)=0 then
 | 
			
		||||
  begin
 | 
			
		||||
    if (CupsLibHandle<>NilHandle) and not UnloadLibrary(CupsLibHandle) then
 | 
			
		||||
      Inc(RefCount)
 | 
			
		||||
      InterLockedIncrement(RefCount)
 | 
			
		||||
    else
 | 
			
		||||
      CupsLibHandle := NilHandle;
 | 
			
		||||
  end;
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user