Changeset 41 for pa_proposals/trunk
- Timestamp:
- 10/20/02 18:42:51 (6 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pa_proposals/trunk/012-AdditionalTerminateBehavior.html
r4 r41 18 18 <P><A href="index.html">Enhancement Proposals Index</A>, 19 19 <A href="http://www.portaudio.com/">PortAudio Home Page</A></P> 20 <P>Updated: July 23, 2002 </P>20 <P>Updated: October 21, 2002 </P> 21 21 22 22 <H4>Status</H4> … … 27 27 28 28 <P> 29 Some host APIs (eg ASIO, MME and DirectSound under Windows NT) can require a reboot to free devices when they are not closed properly (due to a program not calling Pa_Close() either in error, or due to a crash.)As a quality of implementation issue PortAudio should seek to avoid such circumstances.29 Some host APIs (eg ASIO, MME and DirectSound under Windows NT) can require a reboot to free devices when they are not closed properly due to a program not calling Pa_CloseStream() either in error, or due to a crash. As a quality of implementation issue PortAudio should seek to avoid such circumstances. 30 30 </P> 31 31 32 32 <H4>Proposal</H4> 33 33 34 <P>The definition of Pa_Terminate() should be extended as follows:</P> 34 <P> 35 To improve the chances that all streams are closed before an application using PortAudio exits, PortAudio will keep track of all open streams and automatically close any that are still open when Pa_Terminate() is called. If a process calls Pa_Initialise()/Pa_Terminate() in two or more separate subsystems, the first call to Pa_Terminate() must not close streams beloning to another subsystem. Therefore, PortAudio will require calls to Pa_Initialize() to be correctly matched with calls to Pa_Terminate(), and will only close open streams when the final call to Pa_Terminate() is made for which it has registered a matching Pa_Initialize(). 36 </P> 37 38 39 <P>The definition of Pa_Initialize() will be extended as follows:</P> 35 40 36 41 <PRE> 37 /* 38 Pa_Terminate() is the library termination function - call this after 39 using the library. This function deallocates all resources allocated 40 by PortAudio since it was initializied using Pa_Initialize(). Any open 41 PortAudioStreams are closed. 42 /** Library initialization function - call this before using PortAudio. 43 This function initialises internal data structures and prepares underlying 44 host APIs for use. This function MUST be called before using any other 45 PortAudio API functions. 42 46 43 Pa_Terminate() MUST be called before exiting a program which 44 uses PortAudio. Failure to do so may result in serious resource 45 leaks, such as audio devices not being available until the next reboot. 47 If Pa_Initialize() is called multiple times, each call must be matched with 48 a corresponding call to Pa_Terminate(). Pairs of calls to 49 Pa_Initialize()/Pa_Terminate() may overlap, and are not requireed to be fully 50 nested. 51 */ 52 PaError Pa_Initialize( void ); 53 </PRE> 54 55 56 <P>The definition of Pa_Terminate() will be extended as follows:</P> 57 58 <PRE> 59 /** Library termination function - call this when finished using PortAudio. 60 This function deallocates all resources allocated by PortAudio since it was 61 initializied by a call to Pa_Initialize(). In cases where Pa_Initialize() has 62 been called multiple times, each call must be matched with a corresponding call 63 to Pa_Terminate(). The final matching call to Pa_Terminate() will automatically 64 close any PortAudio streams that are still open. 65 66 Pa_Terminate() MUST be called before exiting a program which uses PortAudio. 67 Failure to do so may result in serious resource leaks, such as audio devices 68 not being available until the next reboot. 46 69 */ 47 70 PaError Pa_Terminate( void ); … … 51 74 52 75 <P> 53 One possible implementation strategy would be to add a "next" member to the internal stream data structure thus making it a linked list node, which could be linked into a list of all open streams. 76 One possible implementation strategy would be to add a "next" member to the internal stream data structure thus making it a linked list node, which could be linked into a list of all open streams. It has been noted that using a doubly linked list would make closing streams a constant-time operation. 54 77 </P> 55 78 … … 61 84 62 85 <P> 63 There has been some discussion about the behavior of nesting multiple calls to Pa_Initialize() and Pa_Terminate() - there is no intention of changing the current behaviour, which is that PortAudio has two states: "Initialized" and "Uninitialized" - in the Initialized state, Pa_Initialize() does nothing and returns an error, in the Uninitialized state Pa_Terminate() does nothing and returns an error. 64 [META]This assertion needs to be checked against the v19-devel implementation.[/META] 86 The original (V18 and previous) behavior of calling Pa_Initialize() / Pa_Terminate() multiple times was that the first call to Pa_Initialize() would initialize the library, and the first call to Pa_Terminate() would uninitialize it. For some time it was considered desirable to retain this behavior. However, as noted above, this is not the best behavior for clients who initialize PortAudio multiple times from independent subsystems - especially when Pa_Terminate() can close all open streams. It was concluded that it was best to require matched calls to Pa_Initialize()/Pa_Terminate() as described in this proposal. 65 87 </P> 66 88 … … 68 90 69 91 <P> 70 This proposal changes the termination behaviour of PortAudio to reduce the likelihood of resource leaks.</P> 92 This proposal changes the termination behaviour of PortAudio to reduce the likelihood of resource leaks. 93 </P> 71 94 72 95 <P>
