home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Phase 1
/
phase1.bin
/
Utilities
/
ForceIcon
/
Source
/
Rendezvous.h
< prev
next >
Wrap
C/C++ Source or Header
|
1995-07-19
|
3KB
|
151 lines
/**********************************************************************/
/* Try to find Semaphore or create it */
/**********************************************************************/
static struct FIconSema *FindFIconSema(void)
{
struct FIconSema *FIconSema;
// Semaphore already created ???
Forbid();
if((FIconSema = (struct FIconSema *)FindSemaphore("ForceIcon rendezvous")))
{
// Already launched ???
#ifndef PREFSRUN
if(!FIconSema->ServerTask)
FIconSema->ServerTask = FindTask(NULL);
else
{
DisplayError(ERR_NO_RELAUNCH, NULL);
Signal(FIconSema->ServerTask, SIGBREAKF_CTRL_C);
FIconSema = NULL;
}
#endif
if(FIconSema)
{
// One user more
FIconSema->UseCount++;
}
Permit();
}
else
{
if((FIconSema = AllocVec(sizeof(struct FIconSema), MEMF_CLEAR | MEMF_PUBLIC)))
{
// Try to create pool
if((FIconSema->FIconPool = AsmCreatePool(MEMF_CLEAR | MEMF_PUBLIC, 4096, 2048, SysBase)))
{
// Copy name of semaphore
strcpy(FIconSema->Name, "ForceIcon rendezvous");
// Set up semaphore
FIconSema->FIconSema.ss_Link.ln_Name = FIconSema->Name;
FIconSema->UseCount = 1;
// Add semaphore to list of public semaphores
AddSemaphore(&FIconSema->FIconSema);
// Add address of calling task
#ifndef PREFSRUN
FIconSema->ServerTask = FindTask(NULL);
#endif
// Initialize VolumeList
NewList(&FIconSema->VolumeList);
// Load in preferences
ObtainSemaphore(&FIconSema->FIconSema);
Permit();
LoadPrefs(FIconSema);
ReleaseSemaphore(&FIconSema->FIconSema);
Forbid();
}
else
{
FreeVec(FIconSema);
FIconSema = NULL;
}
}
// Display error on failure
if(!FIconSema)
DisplayError(ERR_NOMEM, NULL);
Permit();
}
return(FIconSema);
}
/**********************************************************************/
/* Release/remove FIconSemaphore */
/**********************************************************************/
static void RemoveFIconSema(struct FIconSema *FIconSema)
{
if(FIconSema)
{
// Remove Semaphore from memory, or simply "log" out ???
ObtainSemaphore(&FIconSema->FIconSema);
Forbid();
ReleaseSemaphore(&FIconSema->FIconSema);
// We`re no longer available
#ifndef PREFSRUN
FIconSema->ServerTask = NULL;
#endif
// Semaphore still in use ???
if(!--FIconSema->UseCount)
{
if(FIconSema->FIconPool)
{
// Free list of patches
FreeDevVolList(&FIconSema->VolumeList);
// Remove Pool
AsmDeletePool(FIconSema->FIconPool, SysBase);
}
// Remove Semaphore
RemSemaphore(&FIconSema->FIconSema);
// Free memory associated
FreeVec(FIconSema);
}
Permit();
}
}