X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Fdrv%2Fiocache.c;h=2b4755cfe57b02fc483be62fe39f00c306f4548d;hb=c967d91a4794ec9c0ec7dab438c033f4c0b49952;hp=f42957c755d7a58ab0b60e8efa02197909227399;hpb=a4ce2e60f783c9e71447edc03f20f937b8abf35a;p=tpg%2Facess2.git diff --git a/Kernel/drv/iocache.c b/Kernel/drv/iocache.c index f42957c7..2b4755cf 100644 --- a/Kernel/drv/iocache.c +++ b/Kernel/drv/iocache.c @@ -25,7 +25,7 @@ struct sIOCache { tIOCache *Next; int SectorSize; - int Lock; + tMutex Lock; int Mode; Uint32 ID; tIOCache_WriteCallback Write; @@ -35,7 +35,7 @@ struct sIOCache }; // === GLOBALS === - int glIOCache_Caches; +tShortSpinlock glIOCache_Caches; tIOCache *gIOCache_Caches = NULL; int giIOCache_NumCaches = 0; @@ -46,7 +46,7 @@ tIOCache *gIOCache_Caches = NULL; */ tIOCache *IOCache_Create( tIOCache_WriteCallback Write, Uint32 ID, int SectorSize, int CacheSize ) { - tIOCache *ret = malloc( sizeof(tIOCache) ); + tIOCache *ret = calloc( 1, sizeof(tIOCache) ); // Sanity Check if(!ret) return NULL; @@ -57,14 +57,12 @@ tIOCache *IOCache_Create( tIOCache_WriteCallback Write, Uint32 ID, int SectorSiz ret->ID = ID; ret->Write = Write; ret->CacheSize = CacheSize; - ret->CacheUsed = 0; - ret->Entries = 0; // Append to list - LOCK( &glIOCache_Caches ); + SHORTLOCK( &glIOCache_Caches ); ret->Next = gIOCache_Caches; gIOCache_Caches = ret; - RELEASE( &glIOCache_Caches ); + SHORTREL( &glIOCache_Caches ); // Return return ret; @@ -87,9 +85,9 @@ int IOCache_Read( tIOCache *Cache, Uint64 Sector, void *Buffer ) } // Lock - LOCK( &Cache->Lock ); + Mutex_Acquire( &Cache->Lock ); if(Cache->CacheSize == 0) { - RELEASE( &Cache->Lock ); + Mutex_Release( &Cache->Lock ); LEAVE('i', -1); return -1; } @@ -101,7 +99,7 @@ int IOCache_Read( tIOCache *Cache, Uint64 Sector, void *Buffer ) if( ent->Num == Sector ) { memcpy(Buffer, ent->Data, Cache->SectorSize); ent->LastAccess = now(); - RELEASE( &Cache->Lock ); + Mutex_Release( &Cache->Lock ); LEAVE('i', 1); return 1; } @@ -110,7 +108,7 @@ int IOCache_Read( tIOCache *Cache, Uint64 Sector, void *Buffer ) if(ent->Num > Sector) break; } - RELEASE( &Cache->Lock ); + Mutex_Release( &Cache->Lock ); LEAVE('i', 0); return 0; } @@ -130,9 +128,9 @@ int IOCache_Add( tIOCache *Cache, Uint64 Sector, void *Buffer ) return -1; // Lock - LOCK( &Cache->Lock ); + Mutex_Acquire( &Cache->Lock ); if(Cache->CacheSize == 0) { - RELEASE( &Cache->Lock ); + Mutex_Release( &Cache->Lock ); return -1; } @@ -142,7 +140,7 @@ int IOCache_Add( tIOCache *Cache, Uint64 Sector, void *Buffer ) { // Is it already here? if( ent->Num == Sector ) { - RELEASE( &Cache->Lock ); + Mutex_Release( &Cache->Lock ); return 0; } @@ -197,7 +195,7 @@ int IOCache_Add( tIOCache *Cache, Uint64 Sector, void *Buffer ) Cache->CacheUsed ++; // Release Spinlock - RELEASE( &Cache->Lock ); + Mutex_Release( &Cache->Lock ); // Return success return 1; @@ -215,9 +213,9 @@ int IOCache_Write( tIOCache *Cache, Uint64 Sector, void *Buffer ) if(!Cache || !Buffer) return -1; // Lock - LOCK( &Cache->Lock ); + Mutex_Acquire( &Cache->Lock ); if(Cache->CacheSize == 0) { - RELEASE( &Cache->Lock ); + Mutex_Release( &Cache->Lock ); return -1; } @@ -234,7 +232,7 @@ int IOCache_Write( tIOCache *Cache, Uint64 Sector, void *Buffer ) ent->LastWrite = 0; } - RELEASE( &Cache->Lock ); + Mutex_Release( &Cache->Lock ); return 1; } // It's a sorted list, so as soon as we go past `Sector` we know @@ -242,7 +240,7 @@ int IOCache_Write( tIOCache *Cache, Uint64 Sector, void *Buffer ) if(ent->Num > Sector) break; } - RELEASE( &Cache->Lock ); + Mutex_Release( &Cache->Lock ); return 0; } @@ -257,9 +255,9 @@ void IOCache_Flush( tIOCache *Cache ) if( Cache->Mode == IOCACHE_VIRTUAL ) return; // Lock - LOCK( &Cache->Lock ); + Mutex_Acquire( &Cache->Lock ); if(Cache->CacheSize == 0) { - RELEASE( &Cache->Lock ); + Mutex_Release( &Cache->Lock ); return; } @@ -270,7 +268,7 @@ void IOCache_Flush( tIOCache *Cache ) ent->LastWrite = 0; } - RELEASE( &Cache->Lock ); + Mutex_Release( &Cache->Lock ); } /** @@ -282,9 +280,9 @@ void IOCache_Destroy( tIOCache *Cache ) tIOCache_Ent *ent, *prev = NULL; // Lock - LOCK( &Cache->Lock ); + Mutex_Acquire( &Cache->Lock ); if(Cache->CacheSize == 0) { - RELEASE( &Cache->Lock ); + Mutex_Release( &Cache->Lock ); return; } @@ -302,24 +300,24 @@ void IOCache_Destroy( tIOCache *Cache ) Cache->CacheSize = 0; - RELEASE( &Cache->Lock ); + Mutex_Release( &Cache->Lock ); // Remove from list - LOCK( &glIOCache_Caches ); + SHORTLOCK( &glIOCache_Caches ); { - tIOCache *ent; - tIOCache *prev = (tIOCache*)&gIOCache_Caches; - for(ent = gIOCache_Caches; - ent; - prev = ent, ent = ent->Next ) + tIOCache *cache; + tIOCache *prev_cache = (tIOCache*)&gIOCache_Caches; + for(cache = gIOCache_Caches; + cache; + prev_cache = cache, cache = cache->Next ) { - if(ent == Cache) { - prev->Next = ent->Next; + if(cache == Cache) { + prev_cache->Next = cache->Next; break; } } } - RELEASE( &glIOCache_Caches ); + SHORTREL( &glIOCache_Caches ); free(Cache); }