Mercurial > sdl-ios-xcode
comparison src/cdrom/macosx/CAGuard.h @ 613:9c6717a1c66f
Added MacOS X CD-ROM audio support (thanks Max and Darrell)
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 15 Apr 2003 16:33:56 +0000 |
parents | |
children | b8d311d90021 |
comparison
equal
deleted
inserted
replaced
612:0648505b1f8b | 613:9c6717a1c66f |
---|---|
1 /* | |
2 SDL - Simple DirectMedia Layer | |
3 Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Sam Lantinga | |
4 | |
5 This library is free software; you can redistribute it and/or | |
6 modify it under the terms of the GNU Library General Public | |
7 License as published by the Free Software Foundation; either | |
8 version 2 of the License, or (at your option) any later version. | |
9 | |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 Library General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU Library General Public | |
16 License along with this library; if not, write to the Free | |
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | |
19 Sam Lantinga | |
20 slouken@libsdl.org | |
21 */ | |
22 /* | |
23 Note: This file hasn't been modified so technically we have to keep the disclaimer :-( | |
24 | |
25 | |
26 Copyright: © Copyright 2002 Apple Computer, Inc. All rights reserved. | |
27 | |
28 Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc. | |
29 ("Apple") in consideration of your agreement to the following terms, and your | |
30 use, installation, modification or redistribution of this Apple software | |
31 constitutes acceptance of these terms. If you do not agree with these terms, | |
32 please do not use, install, modify or redistribute this Apple software. | |
33 | |
34 In consideration of your agreement to abide by the following terms, and subject | |
35 to these terms, Apple grants you a personal, non-exclusive license, under AppleÕs | |
36 copyrights in this original Apple software (the "Apple Software"), to use, | |
37 reproduce, modify and redistribute the Apple Software, with or without | |
38 modifications, in source and/or binary forms; provided that if you redistribute | |
39 the Apple Software in its entirety and without modifications, you must retain | |
40 this notice and the following text and disclaimers in all such redistributions of | |
41 the Apple Software. Neither the name, trademarks, service marks or logos of | |
42 Apple Computer, Inc. may be used to endorse or promote products derived from the | |
43 Apple Software without specific prior written permission from Apple. Except as | |
44 expressly stated in this notice, no other rights or licenses, express or implied, | |
45 are granted by Apple herein, including but not limited to any patent rights that | |
46 may be infringed by your derivative works or by other works in which the Apple | |
47 Software may be incorporated. | |
48 | |
49 The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO | |
50 WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED | |
51 WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
52 PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN | |
53 COMBINATION WITH YOUR PRODUCTS. | |
54 | |
55 IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR | |
56 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE | |
57 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
58 ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION | |
59 OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT | |
60 (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN | |
61 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
62 */ | |
63 /*============================================================================= | |
64 CAGuard.h | |
65 | |
66 =============================================================================*/ | |
67 #if !defined(__CAGuard_h__) | |
68 #define __CAGuard_h__ | |
69 | |
70 //============================================================================= | |
71 // Includes | |
72 //============================================================================= | |
73 | |
74 #include <CoreAudio/CoreAudioTypes.h> | |
75 #include <pthread.h> | |
76 | |
77 | |
78 //============================================================================= | |
79 // CAGuard | |
80 // | |
81 // This is your typical mutex with signalling implemented via pthreads. | |
82 // Lock() will return true if and only if the guard is locked on that call. | |
83 // A thread that already has the guard will receive 'false' if it locks it | |
84 // again. Use of the stack-based CAGuard::Locker class is highly recommended | |
85 // to properly manage the recursive nesting. The Wait calls with timeouts | |
86 // will return true if and only if the timeout period expired. They will | |
87 // return false if they receive notification any other way. | |
88 //============================================================================= | |
89 | |
90 class CAGuard | |
91 { | |
92 | |
93 // Construction/Destruction | |
94 public: | |
95 CAGuard(); | |
96 virtual ~CAGuard(); | |
97 | |
98 // Actions | |
99 public: | |
100 virtual bool Lock(); | |
101 virtual void Unlock(); | |
102 virtual bool Try(bool& outWasLocked); // returns true if lock is free, false if not | |
103 | |
104 virtual void Wait(); | |
105 | |
106 virtual void Notify(); | |
107 | |
108 // Implementation | |
109 protected: | |
110 pthread_mutex_t mMutex; | |
111 pthread_cond_t mCondVar; | |
112 pthread_t mOwner; | |
113 | |
114 // Helper class to manage taking and releasing recursively | |
115 public: | |
116 class Locker | |
117 { | |
118 | |
119 // Construction/Destruction | |
120 public: | |
121 Locker(CAGuard& inGuard) : mGuard(inGuard), mNeedsRelease(false) { mNeedsRelease = mGuard.Lock(); } | |
122 ~Locker() { if(mNeedsRelease) { mGuard.Unlock(); } } | |
123 | |
124 private: | |
125 Locker(const Locker&); | |
126 Locker& operator=(const Locker&); | |
127 | |
128 // Actions | |
129 public: | |
130 void Wait() { mGuard.Wait(); } | |
131 | |
132 void Notify() { mGuard.Notify(); } | |
133 | |
134 // Implementation | |
135 private: | |
136 CAGuard& mGuard; | |
137 bool mNeedsRelease; | |
138 | |
139 }; | |
140 | |
141 }; | |
142 | |
143 #endif |