English Amiga Board

English Amiga Board (https://eab.abime.net/index.php)
-   Coders. System (https://eab.abime.net/forumdisplay.php?f=113)
-   -   No signals in library open/close code? (https://eab.abime.net/showthread.php?t=89621)

AGS 28 November 2017 02:10

No signals in library open/close code?
 
Hello,

how can I make my lib wait in its close() code (the place where the counter is decremented) for a Task to finish first? The Task was started in the open() code. Signals do not work as close() seems to be executed in Forbid().

greets,
ags

PeterK 28 November 2017 02:31

It might be dangerous, but did you try to Permit() before reducing the open count, then wait for the signal from your task, Forbid() again and finally reduce the open count and return. Sounds crazy and may crash the system, but who knows? Trying is better than dying. :D

thomas 28 November 2017 08:06

You don't need to call Permit. Every Wait call pauses the Forbid state until it returns.

And of course signals work everywhere. Just make sure that the signal you want to wait for is allocated to the task which calls Wait and that the other task which shall set the signal knows which task waits for it.

Signal() is the function which sends a signal to another task.

SetSignal() only acts on the local task and cannot be used for inter-task communication.

Also be aware that AllocSignal returns a signal number while all other signal functions take a signal mask.

AGS 28 November 2017 17:37

What happens when I return 0 from LibOpen(), for example in the case that the process that I need to wait for in LibClose() could not launch in LibOpen() (where it is launched now)? Does exec then expunge the library or is LibOpen() a code that may not fail? The logical place to launch the process would be the library initialisation code, but that is executed by ramlib and maybe I may not do such there? Where can I find more documentation about these topics? On the developer CD I found this:

Code:

  ; There are two different things that might be returned from the Close routine.  If the
  ; library is no longer open and there is a delayed expunge then Close should return the
  ; segment list (as given to Init).  Otherwise close should return NULL.

Can this mean a fail in open should cause a direct expunge in my case (and return 0)?

thomas 28 November 2017 22:43

You are mixing open and close.

If open fails, then nothing happens. You have to ensure yourself that everything you allocated before you detect the failure is freed.

Close will only be called if open succeeded. Close should expunge the library only if a previous call to expunge failed because the library was still opened.

AGS 28 November 2017 22:49

So when my initialisations that I do in open fail I may remove the library from the exec list and from memory (same as I do in expunge) and then return 0?

mark_k 28 November 2017 23:06

There's a distinction between initialisation and library open/close routines.

Your initialisation routine is called once when the library is loaded from disk. The first time some program OpenLibrary()s your library, Exec loads it from disk and executes your intialisation routine. That's where you would typically allocate memory for the library base, create your task etc. Then Exec calls your library open routine (offset -6 from library base).

If your initialisation routine returns failure, your library won't be added to the system list.

If your initialisation routine succeeded then the library will be added to the system list. Then your open routine would be called.

AGS 28 November 2017 23:19

I am aware of these differences. I just was yet not able to launch the process from the initcode. I need to pass the process a pointer and the launched process waits until it got that pointer (i write it in TC_userdata). I use the "SIGBREAKF_CTRL_F" signal to wait in the process.

thomas 29 November 2017 08:18

Normally you would start the process, send a message with the pointer to its pr_MsgPort and wait for the reply. The new process would first wait for its pr_MsgPort, get the message, read the pointer and reply the message.

AGS 29 November 2017 10:23

Is it safe to remove the library from the exec list and from memory in open (if it fails)?

mark_k 29 November 2017 17:31

If the library's open count is 0 Exec will automatically unload it if needed (to free memory). Your expunge function would be called at that time.

I guess you could call your expunge function from your open routine though??? Your expunge routine would check the open count and only do anything if it's zero.

Also, you could manually expunge your library. Maybe add an option to do that in some program which uses the library? There's an example code fragment in the RemLibrary() autodoc.


All times are GMT +2. The time now is 18:02.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.

Page generated in 0.20253 seconds with 11 queries