Threads and cache cleaning now mutually excluded
This commit is contained in:
240
PBMap.pb
240
PBMap.pb
@@ -47,6 +47,7 @@ DeclareModule PBMap
|
|||||||
#PB_MAP_TILE_CLEANUP = #PB_EventType_FirstCustomValue + 3
|
#PB_MAP_TILE_CLEANUP = #PB_EventType_FirstCustomValue + 3
|
||||||
|
|
||||||
Declare InitPBMap(window)
|
Declare InitPBMap(window)
|
||||||
|
Declare SetDebugLevel(level.i)
|
||||||
Declare SetOption(Option.s, Value.s)
|
Declare SetOption(Option.s, Value.s)
|
||||||
Declare.s GetOption(Option.s)
|
Declare.s GetOption(Option.s)
|
||||||
Declare LoadOptions(PreferencesFile.s = "PBMap.prefs")
|
Declare LoadOptions(PreferencesFile.s = "PBMap.prefs")
|
||||||
@@ -123,7 +124,7 @@ Module PBMap
|
|||||||
key.s
|
key.s
|
||||||
URL.s
|
URL.s
|
||||||
CacheFile.s
|
CacheFile.s
|
||||||
*GetImageThread
|
GetImageThread.i
|
||||||
Download.i
|
Download.i
|
||||||
Time.i
|
Time.i
|
||||||
Size.i
|
Size.i
|
||||||
@@ -292,15 +293,12 @@ Module PBMap
|
|||||||
Dragging.i
|
Dragging.i
|
||||||
Dirty.i ; To signal that drawing need a refresh
|
Dirty.i ; To signal that drawing need a refresh
|
||||||
|
|
||||||
*MemoryCacheManagementThread
|
MemoryCacheAccessNB.i ; Count the access to the memory cache. =0 no access ; >0 download threads ; -1 cleaning
|
||||||
ResourceAccessSemaphore.i ; To pause web loading threads
|
MemoryCacheAccessNBMutex.i ; Memorycache access variable mutual exclusion
|
||||||
ReadCountAccessSemaphore.i
|
|
||||||
ServiceQueueSemaphore.i
|
|
||||||
ReadCount.i
|
|
||||||
|
|
||||||
DownloadSlots.i ; Actual nb of used download slots
|
DownloadSlots.i ; Actual nb of used download slots
|
||||||
DownloadSlotsMutex.i ; To be sure that only one thread at a time can access to the DownloadSlots var
|
DownloadSlotsMutex.i ; To be sure that only one thread at a time can access to the DownloadSlots var
|
||||||
|
|
||||||
|
|
||||||
List TracksList.Tracks() ; To display a GPX track
|
List TracksList.Tracks() ; To display a GPX track
|
||||||
List Markers.Marker() ; To diplay marker
|
List Markers.Marker() ; To diplay marker
|
||||||
EditMarker.l
|
EditMarker.l
|
||||||
@@ -315,7 +313,7 @@ Module PBMap
|
|||||||
;-*** Global variables
|
;-*** Global variables
|
||||||
|
|
||||||
;-Show debug infos
|
;-Show debug infos
|
||||||
Global MyDebugLevel = 3
|
Global MyDebugLevel = 5
|
||||||
|
|
||||||
Global PBMap.PBMap, Null.i, NullPtrMem.i, *NullPtr = @NullPtrMem
|
Global PBMap.PBMap, Null.i, NullPtrMem.i, *NullPtr = @NullPtrMem
|
||||||
Global slash.s
|
Global slash.s
|
||||||
@@ -358,10 +356,15 @@ Module PBMap
|
|||||||
MessageRequester("PBMap", msg, #PB_MessageRequester_Ok)
|
MessageRequester("PBMap", msg, #PB_MessageRequester_Ok)
|
||||||
EndIf
|
EndIf
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
|
; Set the debug level allowing more or less debug infos
|
||||||
|
Procedure SetDebugLevel(level.i)
|
||||||
|
MyDebugLevel = level
|
||||||
|
EndProcedure
|
||||||
|
|
||||||
; Send debug infos to stdout (allowing mixed debug infos with curl or other libs)
|
; Send debug infos to stdout (allowing mixed debug infos with curl or other libs)
|
||||||
Procedure MyDebug(msg.s, DbgLevel = 0)
|
Procedure MyDebug(msg.s, DbgLevel = 0)
|
||||||
If PBMap\Options\Verbose And DbgLevel >= MyDebugLevel
|
If PBMap\Options\Verbose And DbgLevel <= MyDebugLevel
|
||||||
PrintN(msg)
|
PrintN(msg)
|
||||||
; Debug msg
|
; Debug msg
|
||||||
EndIf
|
EndIf
|
||||||
@@ -1050,60 +1053,63 @@ Module PBMap
|
|||||||
|
|
||||||
;-***
|
;-***
|
||||||
|
|
||||||
Procedure MemoryCacheManagement(*Void)
|
Procedure MemoryCacheManagement()
|
||||||
With PBMap
|
; MemoryCache access management
|
||||||
WaitSemaphore(\ServiceQueueSemaphore) ;serviceQueue.P(); // wait in line to be serviced
|
LockMutex(PBMap\MemoryCacheAccessNBMutex)
|
||||||
WaitSemaphore(\ResourceAccessSemaphore) ;resourceAccess.P(); // request exclusive access to resource
|
; If MemoryCache is not being used by a download thread
|
||||||
SignalSemaphore(\ServiceQueueSemaphore) ;serviceQueue.V(); // let next in line be serviced
|
If PBMap\MemoryCacheAccessNB = 0
|
||||||
EndWith
|
PBMap\MemoryCacheAccessNB = -1 ; Not really useful as the download thread are now blocked by the mutex, and this procedure is synchronous
|
||||||
; If cache size exceeds limit, try to delete the oldest tiles used (first in the time stack)
|
UnlockMutex(PBMap\MemoryCacheAccessNBMutex)
|
||||||
Protected CacheSize = MapSize(PBMap\MemCache\Images()) * Pow(PBMap\TileSize, 2) * 4 ; Size of a tile = TileSize * TileSize * 4 bytes (RGBA)
|
; If cache size exceeds limit, try to delete the oldest tiles used (first in the time stack)
|
||||||
Protected CacheLimit = PBMap\Options\MaxMemCache * 1024
|
Protected CacheSize = MapSize(PBMap\MemCache\Images()) * Pow(PBMap\TileSize, 2) * 4 ; Size of a tile = TileSize * TileSize * 4 bytes (RGBA)
|
||||||
MyDebug("Cache size : " + Str(CacheSize/1024) + " / CacheLimit : " + Str(CacheLimit/1024), 5)
|
Protected CacheLimit = PBMap\Options\MaxMemCache * 1024
|
||||||
If CacheSize > CacheLimit
|
MyDebug("Cache size : " + Str(CacheSize/1024) + " / CacheLimit : " + Str(CacheLimit/1024), 5)
|
||||||
;PBMap\MemoryCacheManagement = #True
|
If CacheSize > CacheLimit
|
||||||
MyDebug(" Cache full. Trying cache cleaning", 5)
|
MyDebug(" Cache full. Trying cache cleaning", 5)
|
||||||
ResetList(PBMap\MemCache\ImagesTimeStack())
|
ResetList(PBMap\MemCache\ImagesTimeStack())
|
||||||
; Try to free half the cache memory (one pass)
|
; Try to free half the cache memory (one pass)
|
||||||
While NextElement(PBMap\MemCache\ImagesTimeStack()) And CacheSize > (CacheLimit / 2) ; /2 = half
|
While NextElement(PBMap\MemCache\ImagesTimeStack()) And CacheSize > (CacheLimit / 2) ; /2 = half
|
||||||
Protected CacheMapKey.s = PBMap\MemCache\ImagesTimeStack()\MapKey
|
Protected CacheMapKey.s = PBMap\MemCache\ImagesTimeStack()\MapKey
|
||||||
;Protected Image = PBMap\MemCache\Images(CacheMapKey)\nImage
|
;Protected Image = PBMap\MemCache\Images(CacheMapKey)\nImage
|
||||||
; Is the loading over
|
; Is the loading over
|
||||||
If PBMap\MemCache\Images(CacheMapKey)\Tile = -1
|
If PBMap\MemCache\Images(CacheMapKey)\Tile = -1
|
||||||
MyDebug(" Delete " + CacheMapKey, 5)
|
MyDebug(" Delete " + CacheMapKey, 5)
|
||||||
If PBMap\MemCache\Images(CacheMapKey)\nImage;IsImage(PBMap\MemCache\Images(CacheMapKey)\nImage)
|
If PBMap\MemCache\Images(CacheMapKey)\nImage;IsImage(PBMap\MemCache\Images(CacheMapKey)\nImage)
|
||||||
FreeImage(PBMap\MemCache\Images(CacheMapKey)\nImage)
|
FreeImage(PBMap\MemCache\Images(CacheMapKey)\nImage)
|
||||||
MyDebug(" and free image nb " + Str(PBMap\MemCache\Images(CacheMapKey)\nImage), 5)
|
MyDebug(" and free image nb " + Str(PBMap\MemCache\Images(CacheMapKey)\nImage), 5)
|
||||||
PBMap\MemCache\Images(CacheMapKey)\nImage = 0
|
PBMap\MemCache\Images(CacheMapKey)\nImage = 0
|
||||||
EndIf
|
EndIf
|
||||||
DeleteMapElement(PBMap\MemCache\Images(), CacheMapKey)
|
DeleteMapElement(PBMap\MemCache\Images(), CacheMapKey)
|
||||||
DeleteElement(PBMap\MemCache\ImagesTimeStack(), 1)
|
DeleteElement(PBMap\MemCache\ImagesTimeStack(), 1)
|
||||||
ElseIf PBMap\MemCache\Images(CacheMapKey)\Tile = 0
|
ElseIf PBMap\MemCache\Images(CacheMapKey)\Tile = 0
|
||||||
MyDebug(" Delete " + CacheMapKey, 5)
|
MyDebug(" Delete " + CacheMapKey, 5)
|
||||||
DeleteMapElement(PBMap\MemCache\Images(), CacheMapKey)
|
DeleteMapElement(PBMap\MemCache\Images(), CacheMapKey)
|
||||||
DeleteElement(PBMap\MemCache\ImagesTimeStack(), 1)
|
DeleteElement(PBMap\MemCache\ImagesTimeStack(), 1)
|
||||||
ElseIf PBMap\MemCache\Images(CacheMapKey)\Tile > 0
|
ElseIf PBMap\MemCache\Images(CacheMapKey)\Tile > 0
|
||||||
; If the thread is running, try to abort the download
|
; If the thread is running, try to abort the download
|
||||||
If PBMap\MemCache\Images(CacheMapKey)\Tile\Download
|
If PBMap\MemCache\Images(CacheMapKey)\Tile\Download
|
||||||
AbortHTTP(PBMap\MemCache\Images(CacheMapKey)\Tile\Download)
|
AbortHTTP(PBMap\MemCache\Images(CacheMapKey)\Tile\Download)
|
||||||
|
EndIf
|
||||||
EndIf
|
EndIf
|
||||||
|
CacheSize = MapSize(PBMap\MemCache\Images()) * Pow(PBMap\TileSize, 2) * 4 ; Size of a tile = TileSize * TileSize * 4 bytes (RGBA)
|
||||||
|
Wend
|
||||||
|
MyDebug(" New cache size : " + Str(CacheSize/1024) + " / CacheLimit : " + Str(CacheLimit/1024), 5)
|
||||||
|
If CacheSize > CacheLimit
|
||||||
|
MyDebug(" Cache cleaning unsuccessfull, can't add new tiles.", 5)
|
||||||
EndIf
|
EndIf
|
||||||
CacheSize = MapSize(PBMap\MemCache\Images()) * Pow(PBMap\TileSize, 2) * 4 ; Size of a tile = TileSize * TileSize * 4 bytes (RGBA)
|
|
||||||
Wend
|
|
||||||
;PBMap\MemoryCacheManagement = #False
|
|
||||||
MyDebug(" New cache size : " + Str(CacheSize/1024) + " / CacheLimit : " + Str(CacheLimit/1024), 5)
|
|
||||||
If CacheSize > CacheLimit
|
|
||||||
MyDebug(" Cache cleaning unsuccessfull, can't add new tiles.", 5)
|
|
||||||
EndIf
|
EndIf
|
||||||
|
; We're no more accessing MemoryCache
|
||||||
|
LockMutex(PBMap\MemoryCacheAccessNBMutex)
|
||||||
|
PBMap\MemoryCacheAccessNB = 0 ; Not really useful as the download thread are now blocked
|
||||||
EndIf
|
EndIf
|
||||||
SignalSemaphore(PBMap\ResourceAccessSemaphore) ; resourceAccess.V(); // release resource access for next reader/writer
|
UnlockMutex(PBMap\MemoryCacheAccessNBMutex)
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
Procedure.i GetTileFromHDD(CacheFile.s)
|
Procedure.i GetTileFromHDD(CacheFile.s)
|
||||||
Protected nImage.i, LifeTime.i, MaxLifeTime.i
|
Protected nImage.i, LifeTime.i, MaxLifeTime.i
|
||||||
MaxLifeTime.i = PBMap\Options\TileLifetime
|
MaxLifeTime.i = PBMap\Options\TileLifetime
|
||||||
If FileSize(CacheFile) > 0 ; <> -1
|
If FileSize(CacheFile) > 0 ; <> -1
|
||||||
; Manage tile file lifetime
|
; Manage tile file lifetime
|
||||||
If MaxLifeTime <> -1
|
If MaxLifeTime <> -1
|
||||||
LifeTime = Date() - GetFileDate(CacheFile, #PB_Date_Modified) ; There's a bug with #PB_Date_Created
|
LifeTime = Date() - GetFileDate(CacheFile, #PB_Date_Modified) ; There's a bug with #PB_Date_Created
|
||||||
If LifeTime > MaxLifeTime
|
If LifeTime > MaxLifeTime
|
||||||
@@ -1156,23 +1162,13 @@ Module PBMap
|
|||||||
; EndIf
|
; EndIf
|
||||||
; ****
|
; ****
|
||||||
|
|
||||||
;-*** These are threaded
|
;-*** These are threaded
|
||||||
|
|
||||||
Threaded Progress = 0, Size = 0, Quit.i = #False
|
Threaded Progress = 0, Size = 0, Quit = #False
|
||||||
|
|
||||||
Procedure GetImageThread(*Tile.Tile)
|
Procedure GetImageThread(*Tile.Tile)
|
||||||
With PBMap
|
|
||||||
WaitSemaphore(\ServiceQueueSemaphore) ;serviceQueue.P(); // wait in line to be serviced
|
|
||||||
WaitSemaphore(\ReadCountAccessSemaphore) ;readCountAccess.P(); // request exclusive access to readCount
|
|
||||||
If \ReadCount = 0 ;If (readCount == 0) // If there are no readers already reading:
|
|
||||||
WaitSemaphore(\ResourceAccessSemaphore) ; resourceAccess.P(); // request resource access for readers (writers blocked)
|
|
||||||
EndIf
|
|
||||||
\ReadCount + 1 ;readCount++; // update count of active readers
|
|
||||||
SignalSemaphore(\ServiceQueueSemaphore) ;serviceQueue.V(); // let next in line be serviced
|
|
||||||
SignalSemaphore(\ReadCountAccessSemaphore) ;readCountAccess.V(); // release access to readCount
|
|
||||||
EndWith
|
|
||||||
MyDebug("Thread starting for image " + *Tile\CacheFile + "(" + *Tile\key + ")", 5)
|
MyDebug("Thread starting for image " + *Tile\CacheFile + "(" + *Tile\key + ")", 5)
|
||||||
; Waits for a free download slot
|
;*** Waits for a free download slot
|
||||||
LockMutex(PBMap\DownloadSlotsMutex)
|
LockMutex(PBMap\DownloadSlotsMutex)
|
||||||
While PBMap\DownloadSlots >= PBMap\Options\MaxDownloadSlots
|
While PBMap\DownloadSlots >= PBMap\Options\MaxDownloadSlots
|
||||||
UnlockMutex(PBMap\DownloadSlotsMutex)
|
UnlockMutex(PBMap\DownloadSlotsMutex)
|
||||||
@@ -1183,11 +1179,23 @@ Module PBMap
|
|||||||
ProcedureReturn #False
|
ProcedureReturn #False
|
||||||
EndIf
|
EndIf
|
||||||
MyDebug(" Thread for image " + *Tile\CacheFile + " waiting a download slot", 5)
|
MyDebug(" Thread for image " + *Tile\CacheFile + " waiting a download slot", 5)
|
||||||
Delay(500)
|
Delay(20)
|
||||||
LockMutex(PBMap\DownloadSlotsMutex)
|
LockMutex(PBMap\DownloadSlotsMutex)
|
||||||
Wend
|
Wend
|
||||||
PBMap\DownloadSlots + 1
|
PBMap\DownloadSlots + 1
|
||||||
UnlockMutex(PBMap\DownloadSlotsMutex)
|
UnlockMutex(PBMap\DownloadSlotsMutex)
|
||||||
|
;***
|
||||||
|
; MemoryCache access management
|
||||||
|
LockMutex(PBMap\MemoryCacheAccessNBMutex)
|
||||||
|
; If MemoryCache is currently being cleaned, wait
|
||||||
|
While PBMap\MemoryCacheAccessNB = -1
|
||||||
|
UnlockMutex(PBMap\MemoryCacheAccessNBMutex)
|
||||||
|
Delay(20)
|
||||||
|
LockMutex(PBMap\MemoryCacheAccessNBMutex)
|
||||||
|
Wend
|
||||||
|
; We're accessing MemoryCache
|
||||||
|
PBMap\MemoryCacheAccessNB + 1
|
||||||
|
UnlockMutex(PBMap\MemoryCacheAccessNBMutex)
|
||||||
*Tile\Download = ReceiveHTTPFile(*Tile\URL, *Tile\CacheFile, #PB_HTTP_Asynchronous)
|
*Tile\Download = ReceiveHTTPFile(*Tile\URL, *Tile\CacheFile, #PB_HTTP_Asynchronous)
|
||||||
If *Tile\Download
|
If *Tile\Download
|
||||||
Repeat
|
Repeat
|
||||||
@@ -1215,27 +1223,23 @@ Module PBMap
|
|||||||
AbortHTTP(*Tile\Download)
|
AbortHTTP(*Tile\Download)
|
||||||
EndIf
|
EndIf
|
||||||
EndSelect
|
EndSelect
|
||||||
;EndIf
|
Delay(200) ; Frees CPU
|
||||||
Delay(500) ; Frees CPU
|
|
||||||
Until Quit
|
Until Quit
|
||||||
LockMutex(PBMap\DownloadSlotsMutex)
|
|
||||||
PBMap\DownloadSlots - 1
|
|
||||||
UnlockMutex(PBMap\DownloadSlotsMutex)
|
|
||||||
PostEvent(#PB_Event_Gadget, PBMap\Window, PBmap\Gadget, #PB_MAP_TILE_CLEANUP, *Tile) ; To free memory outside the thread
|
|
||||||
EndIf
|
EndIf
|
||||||
With PBMap
|
; End of the memory cache access
|
||||||
WaitSemaphore(\ReadCountAccessSemaphore) ;readCountAccess.P(); // request exclusive access to readCount
|
LockMutex(PBMap\MemoryCacheAccessNBMutex)
|
||||||
\ReadCount - 1 ;readCount--; // update count of active readers
|
PBMap\MemoryCacheAccessNB - 1
|
||||||
If \ReadCount = 0 ;If (readCount == 0) // If there are no readers left:
|
UnlockMutex(PBMap\MemoryCacheAccessNBMutex)
|
||||||
SignalSemaphore(\ResourceAccessSemaphore) ; resourceAccess.V(); // release resource access for all
|
; Frees a download slot
|
||||||
EndIf
|
LockMutex(PBMap\DownloadSlotsMutex)
|
||||||
SignalSemaphore(\ReadCountAccessSemaphore) ;readCountAccess.V();
|
PBMap\DownloadSlots - 1
|
||||||
EndWith
|
UnlockMutex(PBMap\DownloadSlotsMutex)
|
||||||
|
PostEvent(#PB_Event_Gadget, PBMap\Window, PBmap\Gadget, #PB_MAP_TILE_CLEANUP, *Tile) ; To free memory outside the thread
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
;-***
|
;-***
|
||||||
|
|
||||||
Procedure.i GetTile(key.s, URL.s, CacheFile.s)
|
Procedure.i GetTile(key.s, URL.s, CacheFile.s)
|
||||||
; Try to find the tile in memory cache
|
; Try to find the tile in memory cache
|
||||||
Protected *timg.ImgMemCach = FindMapElement(PBMap\MemCache\Images(), key)
|
Protected *timg.ImgMemCach = FindMapElement(PBMap\MemCache\Images(), key)
|
||||||
If *timg
|
If *timg
|
||||||
@@ -2478,24 +2482,19 @@ Module PBMap
|
|||||||
PBMap\Redraw = #True
|
PBMap\Redraw = #True
|
||||||
Case #PB_MAP_RETRY
|
Case #PB_MAP_RETRY
|
||||||
PBMap\Redraw = #True
|
PBMap\Redraw = #True
|
||||||
;- Tile cleanup
|
;- Tile web loading thread cleanup
|
||||||
|
; After a Web tile loading thread, clean the tile structure memory, see GetImageThread()
|
||||||
Case #PB_MAP_TILE_CLEANUP
|
Case #PB_MAP_TILE_CLEANUP
|
||||||
*Tile = EventData()
|
*Tile = EventData()
|
||||||
key = *Tile\key
|
key = *Tile\key
|
||||||
; After a Web tile loading thread, clean the tile structure memory, see GetImageThread()
|
|
||||||
*Tile\Download = 0
|
*Tile\Download = 0
|
||||||
;Debug key + " cleanup event"
|
|
||||||
|
|
||||||
If *Tile\Size ; <> 0
|
If *Tile\Size ; <> 0
|
||||||
FreeMemory(PBMap\MemCache\Images(key)\Tile) ; Frees the data needed for the thread
|
FreeMemory(*Tile) ; Frees the data needed for the thread (*tile=PBMap\MemCache\Images(key)\Tile)
|
||||||
PBMap\MemCache\Images(key)\Tile = -1 ; Clears the data ptr, and says that the web loading thread has finished successfully
|
PBMap\MemCache\Images(key)\Tile = -1 ; Clears the data ptr, and says that the web loading thread has finished successfully
|
||||||
Else
|
Else
|
||||||
FreeMemory(PBMap\MemCache\Images(key)\Tile) ; Frees the data needed for the thread
|
FreeMemory(*Tile) ; Frees the data needed for the thread (*tile=PBMap\MemCache\Images(key)\Tile)
|
||||||
PBMap\MemCache\Images(key)\Tile = 0 ; Clears the data ptr, and says that the web loading thread has finished unsuccessfully
|
PBMap\MemCache\Images(key)\Tile = 0 ; Clears the data ptr, and says that the web loading thread has finished unsuccessfully
|
||||||
EndIf
|
EndIf
|
||||||
;Debug "=" + Str(PBMap\MemCache\Images(key)\Tile)
|
|
||||||
;Protected timg = PBMap\MemCache\Images(key)\Tile\nImage ; Get this new tile image nb
|
|
||||||
;PBMap\MemCache\Images(key)\nImage = timg ; Stores it in the cache using the key
|
|
||||||
PBMap\ThreadsNB - 1
|
PBMap\ThreadsNB - 1
|
||||||
PBMap\Redraw = #True
|
PBMap\Redraw = #True
|
||||||
EndSelect
|
EndSelect
|
||||||
@@ -2504,8 +2503,8 @@ Module PBMap
|
|||||||
; Redraws at regular intervals
|
; Redraws at regular intervals
|
||||||
Procedure TimerEvents()
|
Procedure TimerEvents()
|
||||||
If EventTimer() = PBMap\Timer And (PBMap\Redraw Or PBMap\Dirty)
|
If EventTimer() = PBMap\Timer And (PBMap\Redraw Or PBMap\Dirty)
|
||||||
|
MemoryCacheManagement()
|
||||||
Drawing()
|
Drawing()
|
||||||
PBMap\MemoryCacheManagementThread = CreateThread(@MemoryCacheManagement(), Null)
|
|
||||||
EndIf
|
EndIf
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
@@ -2532,12 +2531,11 @@ Module PBMap
|
|||||||
|
|
||||||
Procedure Quit()
|
Procedure Quit()
|
||||||
PBMap\Drawing\End = #True
|
PBMap\Drawing\End = #True
|
||||||
;PBMap\MemoryCacheManagement = #True ; Tells web loading threads to pause
|
|
||||||
; Wait for loading threads to finish nicely. Passed 2 seconds, kills them.
|
; Wait for loading threads to finish nicely. Passed 2 seconds, kills them.
|
||||||
Protected TimeCounter = ElapsedMilliseconds()
|
Protected TimeCounter = ElapsedMilliseconds()
|
||||||
Repeat
|
Repeat
|
||||||
ForEach PBMap\MemCache\Images()
|
ForEach PBMap\MemCache\Images()
|
||||||
If PBMap\MemCache\Images()\Tile > 0
|
If PBMap\MemCache\Images()\Tile > 0
|
||||||
If IsThread(PBMap\MemCache\Images()\Tile\GetImageThread)
|
If IsThread(PBMap\MemCache\Images()\Tile\GetImageThread)
|
||||||
If ElapsedMilliseconds() - TimeCounter > 2000
|
If ElapsedMilliseconds() - TimeCounter > 2000
|
||||||
; Should not occur
|
; Should not occur
|
||||||
@@ -2556,25 +2554,30 @@ Module PBMap
|
|||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
Procedure InitPBMap(Window)
|
Procedure InitPBMap(Window)
|
||||||
Protected Result.i
|
With PBMap
|
||||||
PBMap\ZoomMin = 1
|
Protected Result.i
|
||||||
PBMap\ZoomMax = 18
|
\ZoomMin = 1
|
||||||
PBMap\Dragging = #False
|
\ZoomMax = 18
|
||||||
PBMap\TileSize = 256
|
\Dragging = #False
|
||||||
PBMap\Dirty = #False
|
\TileSize = 256
|
||||||
PBMap\EditMarker = #False
|
\Dirty = #False
|
||||||
PBMap\Font = LoadFont(#PB_Any, "Arial", 20, #PB_Font_Bold)
|
\EditMarker = #False
|
||||||
PBMap\Window = Window
|
\Font = LoadFont(#PB_Any, "Arial", 20, #PB_Font_Bold)
|
||||||
PBMap\Timer = 1
|
\Window = Window
|
||||||
PBMap\Mode = #MODE_DEFAULT
|
\Timer = 1
|
||||||
PBMap\DownloadSlotsMutex = CreateMutex()
|
\Mode = #MODE_DEFAULT
|
||||||
PBMap\ResourceAccessSemaphore = CreateSemaphore(1)
|
\DownloadSlotsMutex = CreateMutex()
|
||||||
PBMap\ReadCountAccessSemaphore = CreateSemaphore(1)
|
If \DownloadSlotsMutex = #False
|
||||||
PBMap\ServiceQueueSemaphore = CreateSemaphore(1)
|
MyDebug("Cannot create a mutex", 0)
|
||||||
If PBMap\DownloadSlotsMutex = #False
|
End
|
||||||
MyDebug("Cannot create a mutex", 0)
|
EndIf
|
||||||
End
|
\MemoryCacheAccessNB = 0
|
||||||
EndIf
|
\MemoryCacheAccessNBMutex = CreateMutex()
|
||||||
|
If \MemoryCacheAccessNBMutex = #False
|
||||||
|
MyDebug("Cannot create a mutex", 0)
|
||||||
|
End
|
||||||
|
EndIf
|
||||||
|
EndWith
|
||||||
LoadOptions()
|
LoadOptions()
|
||||||
TechnicalImagesCreation()
|
TechnicalImagesCreation()
|
||||||
SetLocation(0, 0)
|
SetLocation(0, 0)
|
||||||
@@ -2747,7 +2750,8 @@ CompilerIf #PB_Compiler_IsMainFile
|
|||||||
PBMap::InitPBMap(#Window_0)
|
PBMap::InitPBMap(#Window_0)
|
||||||
PBMap::SetOption("ShowDegrees", "1") : Degrees = 0
|
PBMap::SetOption("ShowDegrees", "1") : Degrees = 0
|
||||||
PBMap::SetOption("ShowDebugInfos", "1")
|
PBMap::SetOption("ShowDebugInfos", "1")
|
||||||
PBMap::SetOption("Verbose", "1")
|
PBMap::SetDebugLevel(4)
|
||||||
|
PBMap::SetOption("Verbose", "0")
|
||||||
PBMap::SetOption("ShowScale", "1")
|
PBMap::SetOption("ShowScale", "1")
|
||||||
PBMap::SetOption("Warning", "1")
|
PBMap::SetOption("Warning", "1")
|
||||||
PBMap::SetOption("ShowMarkersLegend", "1")
|
PBMap::SetOption("ShowMarkersLegend", "1")
|
||||||
@@ -2890,8 +2894,8 @@ CompilerIf #PB_Compiler_IsMainFile
|
|||||||
CompilerEndIf
|
CompilerEndIf
|
||||||
|
|
||||||
; IDE Options = PureBasic 5.60 (Windows - x64)
|
; IDE Options = PureBasic 5.60 (Windows - x64)
|
||||||
; CursorPosition = 1231
|
; CursorPosition = 2751
|
||||||
; FirstLine = 1151
|
; FirstLine = 2738
|
||||||
; Folding = -------------------
|
; Folding = -------------------
|
||||||
; EnableThread
|
; EnableThread
|
||||||
; EnableXP
|
; EnableXP
|
||||||
|
Reference in New Issue
Block a user