home *** CD-ROM | disk | FTP | other *** search
- #include <exec/types.h>
- #include <exec/memory.h>
- #include <exec/semaphores.h>
- #include <proto/exec.h>
-
- struct StackEntry {
- struct Node se_Node;
- ULONG se_Value;
- };
-
- struct SignalSemaphore StackSema;
- struct List StackList;
- struct Library *SysBase;
-
- int __saveds __asm
- __UserLibInit (register __a6
- struct Library *stacklib) {
- SysBase = (*((void**)4));
- NewList(&StackList);
- InitSemaphore(&StackSema);
- return(0);
- }
-
- void __saveds __asm
- __UserLibCleanup (register __a6
- struct Library *stacklib) {
- struct StackEntry *se;
- while(se = (struct StackEntry*)
- RemHead(&StackList)) {
- FreeMem((UBYTE*)se,
- sizeof(struct StackEntry));
- }
- return;
- }
-
- ULONG __asm __saveds LIB_Pop(void) {
- ULONG val = -1;
- struct StackEntry *se;
- ObtainSemaphore(&StackSema);
- if(se = (struct StackEntry*)
- RemHead(&StackList)) {
- val = se->se_Value;
- FreeMem((UBYTE*)se,
- sizeof(struct StackEntry));
- }
- ReleaseSemaphore(&StackSema);
- return(val);
- }
-
- ULONG __asm __saveds
- LIB_Push(register __d0 ULONG val) {
- struct StackEntry *se;
- ObtainSemaphore(&StackSema);
- if(se=(struct StackEntry*)AllocMem
- (sizeof(struct StackEntry),
- MEMF_PUBLIC|MEMF_CLEAR)) {
- se->se_Value = val;
- AddHead(&StackList,&se->se_Node);
- }
- else val = -1;
- ReleaseSemaphore(&StackSema);
- return(val);
- }
-
-