home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gold Fish 2
/
goldfish_vol2_cd1.bin
/
files
/
comm
/
misc
/
cyberpager
/
source
/
library
/
handleresource.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-02-07
|
2KB
|
76 lines
#include "memory.h"
PagerHandle_t *__saveds __asm AllocPagerHandle(register __a0 STRPTR LogProgram)
{
PagerHandle_t *ph;
if (!LogProgram)
LogProgram = "-";
if (ph = MyAllocVec(sizeof(PagerHandle_t) + strlen(LogProgram) + 1)) {
InitSemaphore(&ph->ph_Sema);
ph->ph_LogProgram = (STRPTR)&ph[1];
ph->ph_LogService = "-";
ph->ph_LogWho = "-";
strcpy(ph->ph_LogProgram, LogProgram);
ph->ph_LogLevel = -1;
ph->ph_LogRetries = 0;
NewList(&ph->ph_LockList);
NewList(&ph->ph_ConfigList);
NewList((struct List *)&ph->ph_ServiceList);
NewList((struct List *)&ph->ph_AliasList);
ObtainSemaphore(&HandleListSema);
AddTail((struct List *)&HandleList, (struct Node *)&ph->ph_Node);
ReleaseSemaphore(&HandleListSema);
return ph;
}
return (PagerHandle_t *) NULL;
}
void __saveds __asm FreePagerHandle(register __a0 PagerHandle_t * ph)
{
PrivatePagerAlias_t *pals;
PrivatePagerService_t *psvc;
ConfigEntry_t *ce;
if (ph) {
ObtainSemaphore(&ph->ph_Sema);
while ((pals = (PrivatePagerAlias_t *) ph->ph_AliasList.mlh_Head) != (PrivatePagerAlias_t *) & ph->ph_AliasList.mlh_Tail) {
pals->pals_UseCount = 1; /* force the node to go
* away when we call
* FreePagerAlias() */
FreePagerAlias(&pals->pals_Alias);
}
while ((psvc = (PrivatePagerService_t *) ph->ph_ServiceList.mlh_Head) != (PrivatePagerService_t *) & ph->ph_ServiceList.mlh_Tail) {
psvc->psvc_UseCount = 1; /* force the node to go
* away when we call
* FreePagerService() */
FreePagerService(&psvc->psvc_Service);
}
while ((ce = (ConfigEntry_t *) ph->ph_ConfigList.lh_Head) != (ConfigEntry_t *) & ph->ph_ConfigList.lh_Tail) {
ce->ce_UseCount = 1; /* force the node to go away
* when we call
* FreePagerConfig() */
FreePagerConfig(ce->ce_Data);
}
UnLockFiles(ph);
ObtainSemaphore(&HandleListSema);
Remove((struct Node *)&ph->ph_Node);
ReleaseSemaphore(&HandleListSema);
ReleaseSemaphore(&ph->ph_Sema);
MyFreeVec(ph);
}
}