~ubuntu-branches/ubuntu/vivid/basilisk2/vivid

« back to all changes in this revision

Viewing changes to src/MacOSX/sys_darwin.cpp

  • Committer: Package Import Robot
  • Author(s): Jonas Smedegaard, Jonas Smedegaard, Jérémy Lal, Giulio Paci
  • Date: 2012-05-19 02:08:30 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20120519020830-o59ui1wsfftg55m6
Tags: 0.9.20120331-1
* Upstream update

[ Jonas Smedegaard ]
* Drop local CDBS snippets: All included in main cdbs now.
* Use source format 3.0 (quilt), and stop including patchsys-quilt.mk.
  Stop build-depending on quilt, patchutils.
* Add full licensing header to debian/rules, and update copyright
  years.
* Add README.source (and drop outdated README.cdbs-tweaks).
* Refresh patches with shortening quilt options --no-index
  --no-timestamps -pab, and fix their path prefix.
* Rewrite copyright file using draft DEP-5 format.
* Update control file Vcs-* fields: Packaging moved to Git.
* Ease building with git-buildpackage:
  + Add gbp.conf, enabling pristine-tar and tag signing.
  + Git-ignore quilt .pc dir.
* Bump debhelper compat level to 7.
* Update Vcs-Browser field to use anonscm.debian.org.
* Add Giulio Paci and Jérémy Lal as uploaders, and permit Debian
  Maintainers to upload.

[ Jérémy Lal ]
* Drop patch 1002 to fix capitalized flag: corrected upstream.

[ Giulio Paci ]
* Restart package development.
  Closes: #662175.
* Add patches to fix compilation and documentation.
* Provide JIT flavor on supported architectures (i386 and amd64).
* Bump standards-version to 3.9.3.
* Update copyright file:
  + Adjust licenses now clarified/improved upstream.
* Update ChangeLog.cvs.
* Enable CDBS autogeneration of autotools files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 *      $Id: sys_darwin.cpp,v 1.12 2007/01/22 14:58:33 asvitkine Exp $
 
2
 *      $Id: sys_darwin.cpp,v 1.15 2008/07/20 07:38:27 asvitkine Exp $
3
3
 *
4
4
 *      sys_darwin.cpp - Extra Darwin system dependant routines. Called by:
5
5
 *
7
7
 *
8
8
 *      Based on Apple's CDROMSample.c and Evan Jones' cd-discid.c patches
9
9
 *
10
 
 *  Basilisk II (C) 1997-2005 Christian Bauer
 
10
 *  Basilisk II (C) 1997-2008 Christian Bauer
11
11
 *
12
12
 *  This program is free software; you can redistribute it and/or modify
13
13
 *  it under the terms of the GNU General Public License as published by
48
48
 
49
49
 
50
50
// Global variables
51
 
static CFRunLoopRef media_poll_loop = NULL;
 
51
static volatile CFRunLoopRef media_poll_loop = NULL;
52
52
static bool media_thread_active = false;
53
53
static pthread_t media_thread;
54
54
 
78
78
void DarwinSysExit(void)
79
79
{
80
80
        // Stop media poll thread
81
 
        if (media_poll_loop)
 
81
        if (media_thread_active) {
 
82
                while (media_poll_loop == NULL || !CFRunLoopIsWaiting(media_poll_loop))
 
83
                        usleep(0);
82
84
                CFRunLoopStop(media_poll_loop);
83
 
        if (media_thread_active)
84
85
                pthread_join(media_thread, NULL);
 
86
                media_poll_loop = NULL;
 
87
                media_thread_active = false;
 
88
        }
85
89
}
86
90
 
87
91
 
115
119
static void media_arrived(int type, io_iterator_t iterator)
116
120
{
117
121
        io_object_t obj;
118
 
        while ((obj = IOIteratorNext(iterator)) != NULL) {
 
122
        while ((obj = IOIteratorNext(iterator))) {
119
123
                char path[MAXPATHLEN];
120
124
                kern_return_t kernResult = get_device_path(obj, path, sizeof(path));
121
125
                if (kernResult == KERN_SUCCESS) {
137
141
static void media_removed(int type, io_iterator_t iterator)
138
142
{
139
143
        io_object_t obj;
140
 
        while ((obj = IOIteratorNext(iterator)) != NULL) {
 
144
        while ((obj = IOIteratorNext(iterator))) {
141
145
                char path[MAXPATHLEN];
142
146
                kern_return_t kernResult = get_device_path(obj, path, sizeof(path));
143
147
                if (kernResult == KERN_SUCCESS) {
154
158
 
155
159
/*
156
160
 *  Media poll function
 
161
 *
 
162
 *  NOTE: to facilitate orderly thread termination, media_poll_func MUST end up waiting in CFRunLoopRun.
 
163
 *  Early returns must be avoided, even if there is nothing useful to be done here. See DarwinSysExit.
157
164
 */
158
165
 
 
166
static void dummy(void *) { };  // stub for dummy runloop source
 
167
 
159
168
static void *media_poll_func(void *)
160
169
{
161
170
        media_poll_loop = CFRunLoopGetCurrent();
162
171
 
163
172
        mach_port_t masterPort;
164
 
        kern_return_t kernResult = IOMasterPort(bootstrap_port, &masterPort);
165
 
        if (kernResult != KERN_SUCCESS) {
 
173
        kern_return_t kernResult;
 
174
        CFMutableDictionaryRef matchingDictionary;
 
175
        CFRunLoopSourceRef loopSource = NULL;
 
176
        CFRunLoopSourceRef dummySource = NULL;
 
177
 
 
178
        if ((kernResult = IOMasterPort(bootstrap_port, &masterPort)) != KERN_SUCCESS)
166
179
                fprintf(stderr, "IOMasterPort() returned %d\n", kernResult);
167
 
                return NULL;
168
 
        }
169
 
 
170
 
        CFMutableDictionaryRef matchingDictionary = IOServiceMatching(kIOCDMediaClass);
171
 
        if (matchingDictionary == NULL) {
 
180
        else if ((matchingDictionary = IOServiceMatching(kIOCDMediaClass)) == NULL)
172
181
                fprintf(stderr, "IOServiceMatching() returned a NULL dictionary\n");
173
 
                return NULL;
174
 
        }
175
 
        matchingDictionary = (CFMutableDictionaryRef)CFRetain(matchingDictionary);
176
 
 
177
 
        IONotificationPortRef notificationPort = IONotificationPortCreate(kIOMasterPortDefault);
178
 
        CFRunLoopAddSource(media_poll_loop,
179
 
                                           IONotificationPortGetRunLoopSource(notificationPort),
180
 
                                           kCFRunLoopDefaultMode);
181
 
 
182
 
        io_iterator_t mediaArrivedIterator;
183
 
        kernResult = IOServiceAddMatchingNotification(notificationPort,
184
 
                                                                                                  kIOMatchedNotification,
185
 
                                                                                                  matchingDictionary,
186
 
                                                                                                  (IOServiceMatchingCallback)media_arrived,
187
 
                                                                                                  (void *)MEDIA_CD, &mediaArrivedIterator);
188
 
        if (kernResult != KERN_SUCCESS)
189
 
                fprintf(stderr, "IOServiceAddMatchingNotification() returned %d\n", kernResult);
190
 
        media_arrived(MEDIA_CD, mediaArrivedIterator);
191
 
 
192
 
        io_iterator_t mediaRemovedIterator;
193
 
        kernResult = IOServiceAddMatchingNotification(notificationPort,
194
 
                                                                                                  kIOTerminatedNotification,
195
 
                                                                                                  matchingDictionary,
196
 
                                                                                                  (IOServiceMatchingCallback)media_removed,
197
 
                                                                                                  (void *)MEDIA_CD, &mediaRemovedIterator);
198
 
        if (kernResult != KERN_SUCCESS)
199
 
                fprintf(stderr, "IOServiceAddMatchingNotification() returned %d\n", kernResult);
200
 
        media_removed(MEDIA_CD, mediaRemovedIterator);
 
182
        else {
 
183
                matchingDictionary = (CFMutableDictionaryRef)CFRetain(matchingDictionary);
 
184
                IONotificationPortRef notificationPort = IONotificationPortCreate(kIOMasterPortDefault);
 
185
                loopSource = IONotificationPortGetRunLoopSource(notificationPort);
 
186
                CFRunLoopAddSource(media_poll_loop, loopSource, kCFRunLoopDefaultMode);
 
187
 
 
188
                io_iterator_t mediaArrivedIterator;
 
189
                kernResult = IOServiceAddMatchingNotification(notificationPort,
 
190
                        kIOMatchedNotification,
 
191
                        matchingDictionary,
 
192
                        (IOServiceMatchingCallback)media_arrived,
 
193
                        (void *)MEDIA_CD, &mediaArrivedIterator);
 
194
                if (kernResult != KERN_SUCCESS)
 
195
                        fprintf(stderr, "IOServiceAddMatchingNotification() returned %d\n", kernResult);
 
196
                media_arrived(MEDIA_CD, mediaArrivedIterator);
 
197
 
 
198
                io_iterator_t mediaRemovedIterator;
 
199
                kernResult = IOServiceAddMatchingNotification(notificationPort,
 
200
                        kIOTerminatedNotification,
 
201
                        matchingDictionary,
 
202
                        (IOServiceMatchingCallback)media_removed,
 
203
                        (void *)MEDIA_CD, &mediaRemovedIterator);
 
204
                if (kernResult != KERN_SUCCESS)
 
205
                        fprintf(stderr, "IOServiceAddMatchingNotification() returned %d\n", kernResult);
 
206
                media_removed(MEDIA_CD, mediaRemovedIterator);
 
207
        }
 
208
 
 
209
        if (loopSource == NULL) {
 
210
                // add a dummy runloop source to prevent premature return from CFRunLoopRun
 
211
                CFRunLoopSourceContext context = { 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, dummy };
 
212
                dummySource = CFRunLoopSourceCreate(NULL, 0, &context);
 
213
                CFRunLoopAddSource(media_poll_loop, dummySource, kCFRunLoopDefaultMode);
 
214
        }
201
215
 
202
216
        CFRunLoopRun();
 
217
 
 
218
        if (dummySource != NULL)
 
219
                CFRelease(dummySource);
203
220
        return NULL;
204
221
}
205
222