English Amiga Board


Go Back   English Amiga Board > Coders > Coders. System

 
 
Thread Tools
Old 28 November 2017, 02:10   #1
AGS
XoXo/Tasko Developer
 
AGS's Avatar
 
Join Date: Dec 2013
Location: Munich
Age: 48
Posts: 450
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
AGS is offline  
Old 28 November 2017, 02:31   #2
PeterK
Registered User
 
Join Date: Apr 2005
Location: digital hell, Germany, after 1984, but worse
Posts: 3,365
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.
PeterK is offline  
Old 28 November 2017, 08:06   #3
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 6,985
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.
thomas is online now  
Old 28 November 2017, 17:37   #4
AGS
XoXo/Tasko Developer
 
AGS's Avatar
 
Join Date: Dec 2013
Location: Munich
Age: 48
Posts: 450
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)?

Last edited by AGS; 28 November 2017 at 19:36.
AGS is offline  
Old 28 November 2017, 22:43   #5
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 6,985
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.
thomas is online now  
Old 28 November 2017, 22:49   #6
AGS
XoXo/Tasko Developer
 
AGS's Avatar
 
Join Date: Dec 2013
Location: Munich
Age: 48
Posts: 450
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?
AGS is offline  
Old 28 November 2017, 23:06   #7
mark_k
Registered User
 
Join Date: Aug 2004
Location:
Posts: 3,333
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.
mark_k is offline  
Old 28 November 2017, 23:19   #8
AGS
XoXo/Tasko Developer
 
AGS's Avatar
 
Join Date: Dec 2013
Location: Munich
Age: 48
Posts: 450
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.
AGS is offline  
Old 29 November 2017, 08:18   #9
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 6,985
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.
thomas is online now  
Old 29 November 2017, 10:23   #10
AGS
XoXo/Tasko Developer
 
AGS's Avatar
 
Join Date: Dec 2013
Location: Munich
Age: 48
Posts: 450
Is it safe to remove the library from the exec list and from memory in open (if it fails)?
AGS is offline  
Old 29 November 2017, 17:31   #11
mark_k
Registered User
 
Join Date: Aug 2004
Location:
Posts: 3,333
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.

Last edited by mark_k; 30 November 2017 at 21:52.
mark_k is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
cannot open rtg.library AGS support.WinUAE 6 02 April 2015 18:41
Open-source graphics library Don_Adan Coders. System 32 15 January 2013 22:15
dos.library Open() hangs MrD Coders. Asm / Hardware 15 24 July 2012 19:55
Need a small win98 prog, to open and close a directX screen... keropi Retrogaming General Discussion 9 25 April 2008 18:43

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.21670 seconds with 15 queries