|
@@ -1,4 +1,4 @@
|
|
-{$mode objfpc}
|
|
|
|
|
|
+{$mode objfpc}{$h+}
|
|
|
|
|
|
{$ifdef BSD}
|
|
{$ifdef BSD}
|
|
{$linklib c}
|
|
{$linklib c}
|
|
@@ -5725,7 +5725,7 @@ procedure ReleaseSQLite;
|
|
|
|
|
|
var
|
|
var
|
|
SQLiteLibraryHandle: TLibHandle;
|
|
SQLiteLibraryHandle: TLibHandle;
|
|
- DefaultLibrary: String = Sqlite3Lib;
|
|
|
|
|
|
+ SQLiteDefaultLibrary: String = Sqlite3Lib;
|
|
{$ENDIF LOAD_DYNAMICALLY}
|
|
{$ENDIF LOAD_DYNAMICALLY}
|
|
|
|
|
|
implementation
|
|
implementation
|
|
@@ -5912,46 +5912,45 @@ var
|
|
|
|
|
|
function TryInitialiseSqlite(const LibraryName: string): Boolean;
|
|
function TryInitialiseSqlite(const LibraryName: string): Boolean;
|
|
begin
|
|
begin
|
|
- Result := false;
|
|
|
|
- if (RefCount=0) then
|
|
|
|
|
|
+ if InterlockedIncrement(RefCount) = 1 then
|
|
begin
|
|
begin
|
|
SQLiteLibraryHandle := LoadLibrary(LibraryName);
|
|
SQLiteLibraryHandle := LoadLibrary(LibraryName);
|
|
- Result := (SQLiteLibraryHandle <> nilhandle);
|
|
|
|
|
|
+ Result := (SQLiteLibraryHandle <> NilHandle);
|
|
if not Result then
|
|
if not Result then
|
|
|
|
+ begin
|
|
|
|
+ RefCount := 0;
|
|
Exit;
|
|
Exit;
|
|
- Inc(RefCount);
|
|
|
|
|
|
+ end;
|
|
LoadedLibrary := LibraryName;
|
|
LoadedLibrary := LibraryName;
|
|
LoadAddresses(SQLiteLibraryHandle);
|
|
LoadAddresses(SQLiteLibraryHandle);
|
|
- end else begin
|
|
|
|
- if (LoadedLibrary <> LibraryName) then
|
|
|
|
- raise EInoutError.CreateFmt(SErrAlreadyLoaded,[LoadedLibrary]);
|
|
|
|
- Inc(RefCount);
|
|
|
|
|
|
+ end else
|
|
Result := True;
|
|
Result := True;
|
|
- end;
|
|
|
|
end;
|
|
end;
|
|
|
|
|
|
procedure InitialiseSQLite;
|
|
procedure InitialiseSQLite;
|
|
begin
|
|
begin
|
|
- InitialiseSQLite(DefaultLibrary);
|
|
|
|
|
|
+ InitialiseSQLite(SQLiteDefaultLibrary);
|
|
end;
|
|
end;
|
|
|
|
|
|
procedure InitialiseSQLite(LibraryName: String);
|
|
procedure InitialiseSQLite(LibraryName: String);
|
|
begin
|
|
begin
|
|
|
|
+ if (LoadedLibrary <> '') and (LoadedLibrary <> LibraryName) then
|
|
|
|
+ raise EInoutError.CreateFmt(SErrAlreadyLoaded,[LoadedLibrary]);
|
|
|
|
+
|
|
if not TryInitialiseSQLIte(LibraryName) then
|
|
if not TryInitialiseSQLIte(LibraryName) then
|
|
raise EInOutError.CreateFmt(SErrLoadFailed,[LibraryName]);
|
|
raise EInOutError.CreateFmt(SErrLoadFailed,[LibraryName]);
|
|
end;
|
|
end;
|
|
|
|
|
|
procedure ReleaseSQLite;
|
|
procedure ReleaseSQLite;
|
|
begin
|
|
begin
|
|
- if RefCount > 1 then
|
|
|
|
- Dec(RefCount)
|
|
|
|
- else
|
|
|
|
- if UnloadLibrary(SQLiteLibraryHandle) then
|
|
|
|
- begin
|
|
|
|
- Dec(RefCount);
|
|
|
|
- SQLiteLibraryHandle := NilHandle;
|
|
|
|
- LoadedLibrary := '';
|
|
|
|
- end;
|
|
|
|
|
|
+ if InterlockedDecrement(RefCount) <= 0 then
|
|
|
|
+ begin
|
|
|
|
+ if SQLiteLibraryHandle <> NilHandle then
|
|
|
|
+ UnloadLibrary(SQLiteLibraryHandle);
|
|
|
|
+ SQLiteLibraryHandle := NilHandle;
|
|
|
|
+ LoadedLibrary := '';
|
|
|
|
+ RefCount := 0;
|
|
|
|
+ end;
|
|
end;
|
|
end;
|
|
|
|
|
|
{$ENDIF}
|
|
{$ENDIF}
|