Ported to AROS.
[AROS-Contrib.git] / libs / mpega / support.c
blobd0465e967ff1240666db0c4447b5cd2a393774bf
1 #include <exec/memory.h>
2 #include <exec/semaphores.h>
3 #include <proto/exec.h>
4 #include <proto/dos.h>
5 #include <string.h>
7 #define PoolSize 131072
8 static void *MemPool = NULL;
9 static struct SignalSemaphore PoolSem;
11 ULONG InitSupport(void)
13 if ((MemPool = CreatePool(MEMF_PUBLIC, PoolSize, PoolSize)))
15 InitSemaphore(&PoolSem);
16 return 1;
19 return 0;
22 void RemoveSupport(void)
24 if (MemPool)
26 DeletePool(MemPool);
27 MemPool = NULL;
31 void *malloc(unsigned long size)
33 ULONG *MyMemory;
35 if (size == 0) return NULL;
36 size += 8;
38 ObtainSemaphore(&PoolSem);
39 MyMemory = (ULONG *)AllocPooled(MemPool, size);
40 ReleaseSemaphore(&PoolSem);
42 if (MyMemory)
44 *MyMemory++ = size;
46 if ((ULONG)MyMemory & 7)
48 *MyMemory++ = 0;
52 return((void *)MyMemory);
55 void *calloc(unsigned long nobj, unsigned long size)
57 unsigned long siz = size * nobj;
58 void *ptr;
60 if ((ptr = malloc(siz)))
61 bzero(ptr, siz);
63 return ptr;
66 void free(void *ptr)
68 ULONG *MemPtr;
69 ULONG Size;
71 if (ptr == NULL) return;
73 MemPtr = ptr;
74 Size = *--MemPtr;
76 if (Size == 0)
78 Size = *--MemPtr;
81 ObtainSemaphore(&PoolSem);
82 FreePooled(MemPool, MemPtr, Size);
83 ReleaseSemaphore(&PoolSem);