Avoiding some mutexes

This commit is contained in:
djes
2016-07-27 16:53:45 +02:00
parent 767261b3e1
commit b93f22adb1

25
osm.pb
View File

@@ -116,7 +116,6 @@ Module OSM
Moving.i Moving.i
Dirty.i ;To signal that drawing need a refresh Dirty.i ;To signal that drawing need a refresh
LoadingMutex.i
;CurlMutex.i ;seems that I can't thread curl ! :((((( ;CurlMutex.i ;seems that I can't thread curl ! :(((((
List TilesThreads.TileThread() List TilesThreads.TileThread()
@@ -240,7 +239,6 @@ Module OSM
OSM\MoveStartingPoint\x = - 1 OSM\MoveStartingPoint\x = - 1
OSM\TileSize = 256 OSM\TileSize = 256
OSM\MemCache\Mutex = CreateMutex() OSM\MemCache\Mutex = CreateMutex()
OSM\LoadingMutex = CreateMutex()
;OSM\CurlMutex = CreateMutex() ;OSM\CurlMutex = CreateMutex()
OSM\Dirty = #False OSM\Dirty = #False
OSM\Drawing\Semaphore = CreateSemaphore() OSM\Drawing\Semaphore = CreateSemaphore()
@@ -372,7 +370,6 @@ Module OSM
Debug "Check if we have this image in memory" Debug "Check if we have this image in memory"
LockMutex(OSM\LoadingMutex)
LockMutex(OSM\MemCache\Mutex) LockMutex(OSM\MemCache\Mutex)
ForEach OSM\MemCache\Image() ForEach OSM\MemCache\Image()
If Zoom = OSM\MemCache\Image()\Zoom And OSM\MemCache\Image()\xTile = XTile And OSM\MemCache\Image()\yTile = YTile If Zoom = OSM\MemCache\Image()\Zoom And OSM\MemCache\Image()\xTile = XTile And OSM\MemCache\Image()\yTile = YTile
@@ -384,7 +381,6 @@ Module OSM
EndIf EndIf
Next Next
UnlockMutex(OSM\MemCache\Mutex) UnlockMutex(OSM\MemCache\Mutex)
UnlockMutex(OSM\LoadingMutex)
ProcedureReturn nImage ProcedureReturn nImage
@@ -455,20 +451,23 @@ Module OSM
Protected *CacheImagePtr Protected *CacheImagePtr
Protected nImage.i = -1 Protected nImage.i = -1
LockMutex(OSM\LoadingMutex) LockMutex(OSM\MemCache\Mutex)
LockMutex(OSM\MemCache\Mutex) ;Push and pop as we are threaded
PushListPosition(OSM\MemCache\Image())
*CacheImagePtr = AddElement(OSM\MemCache\Image()) *CacheImagePtr = AddElement(OSM\MemCache\Image())
Debug " CacheImagePtr : " + Str(*CacheImagePtr) Debug " CacheImagePtr : " + Str(*CacheImagePtr)
OSM\MemCache\Image()\xTile = *Tile\OSMTileX OSM\MemCache\Image()\xTile = *Tile\OSMTileX
OSM\MemCache\Image()\yTile = *Tile\OSMTileY OSM\MemCache\Image()\yTile = *Tile\OSMTileY
OSM\MemCache\Image()\Zoom = *Tile\OSMZoom OSM\MemCache\Image()\Zoom = *Tile\OSMZoom
OSM\MemCache\Image()\nImage = -1 ;By now, this tile is in "loading" state, for thread synchro OSM\MemCache\Image()\nImage = -1 ;By now, this tile is in "loading" state, for thread synchro
PopListPosition(OSM\MemCache\Image())
UnlockMutex(OSM\MemCache\Mutex) UnlockMutex(OSM\MemCache\Mutex)
nImage = GetTileFromHDD(*Tile\OSMZoom, *Tile\OSMTileX, *Tile\OSMTileY) nImage = GetTileFromHDD(*Tile\OSMZoom, *Tile\OSMTileX, *Tile\OSMTileY)
If nImage = -1 If nImage = -1
nImage = GetTileFromWeb(*Tile\OSMZoom, *Tile\OSMTileX, *Tile\OSMTileY) nImage = GetTileFromWeb(*Tile\OSMZoom, *Tile\OSMTileX, *Tile\OSMTileY)
EndIf EndIf
LockMutex(OSM\MemCache\Mutex) LockMutex(OSM\MemCache\Mutex)
ChangeCurrentElement(OSM\MemCache\Image(), *CacheImagePtr)
If nImage <> -1 If nImage <> -1
Debug "Adding tile " + Str(nImage) + " to mem cache" Debug "Adding tile " + Str(nImage) + " to mem cache"
;AddTileToMemCache(Zoom, XTile, YTile, nImage) ;AddTileToMemCache(Zoom, XTile, YTile, nImage)
@@ -481,7 +480,6 @@ Module OSM
EndIf EndIf
UnlockMutex(OSM\MemCache\Mutex) UnlockMutex(OSM\MemCache\Mutex)
*Tile\nImage = nImage *Tile\nImage = nImage
UnlockMutex(OSM\LoadingMutex)
EndProcedure EndProcedure
@@ -673,10 +671,11 @@ Module OSM
;Delay(250) ;Delay(250)
*Drawing\PassNb + 1 *Drawing\PassNb + 1
SignalSemaphore(*Drawing\Semaphore) SignalSemaphore(*Drawing\Semaphore)
; Else ;TODO : Could be nice to avoid multiple redraws when not moving anymore
; ;Clean the semaphore ; Else
; Repeat ; ;Clean the semaphore
; Until TrySemaphore(*Drawing\Semaphore) = 0 ; Repeat
; Until TrySemaphore(*Drawing\Semaphore) = 0
EndIf EndIf
Until *Drawing\End Until *Drawing\End
@@ -975,8 +974,8 @@ CompilerIf #PB_Compiler_IsMainFile
CompilerEndIf CompilerEndIf
; IDE Options = PureBasic 5.42 LTS (Windows - x64) ; IDE Options = PureBasic 5.42 LTS (Windows - x64)
; CursorPosition = 661 ; CursorPosition = 672
; FirstLine = 642 ; FirstLine = 646
; Folding = ------ ; Folding = ------
; EnableUnicode ; EnableUnicode
; EnableThread ; EnableThread