Page 1 of 1
[avoided] Using IExec->AllocSysObjectTags() in library?
Posted: Fri Aug 16, 2013 2:19 pm
by gazelle
I'm now creating an async process in my libInit() code to install the IDOS->NotifyVar() notification (as mentioned in the other thread).
I want to use the NP_NotifyOnDeathMessage so my expunge code can wait until the notify process is gone. For this i need a replyport for the deathmessage. Now the autodocs for AllocSysObjectTags() says to call FreeSysObject() only within the same task but for the library this can't be guaranteed.
My solution is to AllocVecTags() the memory for the port and message and initialize it myself (no signal for the port and PA_IGNORE for action). Is this correct?
edit: The autodocs also mentions that MEMF_PUBLIC is used for ASOT_PORT. What should I use, MEMF_PUBLIC or MEMF_SHARED?
Re: Using IExec->AllocSysObjectTags() in library?
Posted: Fri Aug 16, 2013 8:27 pm
by ssolie
You need to find a way to free the memory from the same Task which allocated it. Anything else is a bad idea.
Re: Using IExec->AllocSysObjectTags() in library?
Posted: Fri Aug 16, 2013 11:04 pm
by gazelle
But I can't. The libInit() is called from "ramlib" but the libExpunge could be called from anyone.
Re: Using IExec->AllocSysObjectTags() in library?
Posted: Sat Aug 17, 2013 4:12 am
by colinw
These features basically require that you know what task is going to persist to receive the
deathmessage or deathsignal. Unfortunately, from a library context, that's the one thing you
can't know in advance. So these are not going to help you a lot here, sorry.
So, may I suggest that you just put the new notify process in; IExec->Wait(SIGBREAKF_CTRL_C);
after installing the notification, then, from whatever task calls the expunge vector,
just use the SafeSignal() source code example #2 in the IDOS->ProcessScan() autodoc.
Call the SafeSignal() routine in a loop, with a small delay after each itteration, until it returns FALSE,
which means that Elvis has left the building.
Store the PID of the notify process in the library base when it starts up.
See also; IDOS->GetPID();
Re: Using IExec->AllocSysObjectTags() in library?
Posted: Sat Aug 17, 2013 4:51 am
by Belxjander
Does the LibraryBase and Interface need to remain sharable?
Are you allowing for tracking who opens you?
and while LibInit is fixated to ramlib, you can force a LibExpunge on ramlib... by blocking the allowance of LibOpen and LibClose to call into LibExpunge.
If LibClose never calls LibExpunge then LibExpunge will be called by ramlib when required is my understanding.
the other thing to look for is to limit some specifics for when ramlib is the caller and "delay" expunge until that is true.
I am performing something similar for my own polymorph-vmm project based on who called along with needing multiple caller context tracking,
I'm in the middle of verifying that I am happy with this code before pushing to the public repository...
I'll give you a link to the original code I am working from for this that I wrote some years ago if it at all helps
EDIT: I just saw what ColinW posted... and the above code I can offer includes an internal "daemon" process... which would be a good place for any context restricted resources such as what you want
Re: Using IExec->AllocSysObjectTags() in library?
Posted: Sat Aug 17, 2013 7:26 am
by gazelle
@colinw
Ok. I allready use the SafeSignal() to send the ctrl-c to my process. I get the PID from IDOS->IoErr() as documented in the CreateNewProcTags() description. There is no IDOS->GetPID in the current SDK,
libBase->notifyProcessID = IDOS->IoErr();
Code: Select all
struct Process *notifyProc = IDOS->CreateNewProcTags(NP_Entry, notifyProcessEntry,
NP_Child, FALSE,
NP_Input, ZERO,
NP_Output, ZERO,
NP_CurrentDir, ZERO,
NP_HomeDir, ZERO,
NP_Name, "my.library prefs notify",
NP_CopyVars, FALSE,
NP_UserData, libBase,
TAG_END);
if (notifyProc != NULL)
{
libBase->notifyProcessID = IDOS->IoErr();
@Belxjander:
Thanks for the offer, but I don't want to be context sensitive or track every caller.
I will just do as colinw suggested.
Code: Select all
do
{
done = safeSignalNotifyProcess(libBase);
IDOS->Delay(5);
count++;
} while (!done && (count < 10));
Re: Using IExec->AllocSysObjectTags() in library?
Posted: Sat Aug 17, 2013 9:00 am
by colinw
gazelle wrote:
(...)
There is no IDOS->GetPID in the current SDK,
Ok, that's not good, i'll try and remedy that with management ASAP.
Re: Using IExec->AllocSysObjectTags() in library?
Posted: Sat Aug 17, 2013 11:06 pm
by colinw
gazelle wrote:@colinw
Ok. I allready use the SafeSignal() to send the ctrl-c to my process. I get the PID from IDOS->IoErr() as documented in the CreateNewProcTags() description. There is no IDOS->GetPID in the current SDK,
[...]
I will just do as colinw suggested.
Code: Select all
do
{
done = safeSignalNotifyProcess(libBase);
IDOS->Delay(5);
count++;
}
while (!done && (count < 10));
I think that last line should be;
You want to call SafeSignal() at least twice, once to signal the process to exit,
and the second time to receive a failure return code so you know the process has exited.
The above only signals once and leaves immediately, there is no verification.
Also, I would allow AT LEAST 10 seconds before giving up, you could be a low pri task
and competing with something rather busy at the time of exit.
Re: [avoided] Using IExec->AllocSysObjectTags() in library?
Posted: Mon Aug 19, 2013 1:19 am
by gazelle
Yeah, I noticed the error while implementing it. The actual code looks like:
Code: Select all
do
{
DEBUGF(15, ("waiting for notify process to die\n"));
again = safeSignalNotifyProcess(libBase);
IDOS->Delay(5);
count++;
} while (again && (count < 200));
I changed the counter to 20 seconds, thanks for notifying me.