Skip to content

Commit

Permalink
submem functions (locks added)
Browse files Browse the repository at this point in the history
  • Loading branch information
prokushev committed Apr 10, 2024
1 parent a0cc509 commit 5939210
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions OS2/CPI/doscalls/submem.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ the following restrictions:
3. This notice may not be removed or altered from any source distribution.
---------------------------------------------------*/

#define INCL_DOSSPINLOCK

#include "kal.h"

struct FreeHeapBlock;
Expand All @@ -29,8 +31,9 @@ struct HeapHeader {
ULONG flags; //flags to DosSubSetMem
ULONG size; //in bytes
struct FreeHeapBlock *firstFree;
HSPINLOCK lock;
// SpinMutexSemaphore lock;
char _filler[ 64 - sizeof(ULONG)*2 - sizeof(struct FreeHeapBlock*) /*- sizeof(SpinMutexSemaphore)*/ ];
char _filler[ 64 - sizeof(ULONG)*2 - sizeof(struct FreeHeapBlock*) - sizeof(HSPINLOCK /*SpinMutexSemaphore*/) ];
};

struct FreeHeapBlock {
Expand All @@ -51,6 +54,7 @@ APIRET APIENTRY DosSubSetMem(PVOID pbBase,
APIRET rc;
struct HeapHeader *hh=(struct HeapHeader*)pbBase;
if(hh->flags&DOSSUB_SERIALIZE)
DosAcquireSpinLock(hh->lock);
;//hh->lock.Request();
if(cb<hh->size) {
rc = 310; //dossub_shrink
Expand All @@ -72,7 +76,7 @@ APIRET APIENTRY DosSubSetMem(PVOID pbBase,
hh->size = cb;
}
if(hh->flags&DOSSUB_SERIALIZE)
;//hh->lock.Release();
DosReleaseSpinLock(hh->lock);//hh->lock.Release();
return rc;
} else if(flag&DOSSUB_INIT) {
struct HeapHeader *hh=(struct HeapHeader*)pbBase;
Expand All @@ -82,8 +86,9 @@ APIRET APIENTRY DosSubSetMem(PVOID pbBase,
hh->flags = flag;
hh->size = cb;
if(flag&DOSSUB_SERIALIZE)
//if(!hh->lock.Initialize())
// return 1;//(APIRET)GetLastError();
if (DosCreateSpinLock(&hh->lock))
//if(!hh->lock.Initialize())
return 1;//(APIRET)GetLastError();
hh->firstFree = (struct FreeHeapBlock*)(hh+1);
hh->firstFree->next = 0;
hh->firstFree->size = cb - sizeof(*hh);
Expand All @@ -110,7 +115,7 @@ APIRET APIENTRY DosSubAllocMem(PVOID pbBase,
cb = (cb+7)&0xFFFFFFF8;

if(hh->flags&DOSSUB_SERIALIZE)
;//hh->lock.Request();
DosAcquireSpinLock(hh->lock);//hh->lock.Request();

while(p) {
if(p->size>=cb)
Expand Down Expand Up @@ -141,7 +146,7 @@ APIRET APIENTRY DosSubAllocMem(PVOID pbBase,
rc = 311; //dossub_nomem

if(hh->flags&DOSSUB_SERIALIZE)
;//hh->lock.Release();
DosReleaseSpinLock(hh->lock);//hh->lock.Release();

return rc;
}
Expand All @@ -163,7 +168,7 @@ APIRET APIENTRY DosSubFreeMem(PVOID pbBase,
return 87; //invalid parameter FixMe

if(hh->flags&DOSSUB_SERIALIZE)
;//hh->lock.Request();
DosAcquireSpinLock(hh->lock);//hh->lock.Request();


if((char*)pb+cb >= (char*)pbBase+hh->size) {
Expand Down Expand Up @@ -206,7 +211,7 @@ APIRET APIENTRY DosSubFreeMem(PVOID pbBase,
}

if(hh->flags&DOSSUB_SERIALIZE)
;//hh->lock.Release();
DosReleaseSpinLock(hh->lock);//hh->lock.Release();

return rc;
}
Expand All @@ -219,11 +224,6 @@ APIRET APIENTRY DosSubUnsetMem(PVOID pbBase)
if(!pbBase)
return 87; //invalid parameter
if(hh->flags&DOSSUB_SERIALIZE)
;//hh->lock.Finalize();
DosFreeSpinLock(hh->lock);//hh->lock.Finalize();
return 0;
}





0 comments on commit 5939210

Please sign in to comment.