3 |
* LinuxSampler - modular, streaming capable sampler * |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
* * |
5 |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
6 |
* Copyright (C) 2005 - 2014 Christian Schoenebeck * |
* Copyright (C) 2005 - 2020 Christian Schoenebeck * |
7 |
* * |
* * |
8 |
* This program is free software; you can redistribute it and/or modify * |
* This program is free software; you can redistribute it and/or modify * |
9 |
* it under the terms of the GNU General Public License as published by * |
* it under the terms of the GNU General Public License as published by * |
291 |
} |
} |
292 |
|
|
293 |
int MidiInputDeviceAlsa::Main() { |
int MidiInputDeviceAlsa::Main() { |
294 |
|
|
295 |
|
#if DEBUG |
296 |
|
Thread::setNameOfCaller("AlsaMidi"); |
297 |
|
#endif |
298 |
|
|
299 |
int npfd; |
int npfd; |
300 |
struct pollfd* pfd; |
struct pollfd* pfd; |
301 |
snd_seq_event_t* ev; |
snd_seq_event_t* ev; |
304 |
pfd = (struct pollfd*) alloca(npfd * sizeof(struct pollfd)); |
pfd = (struct pollfd*) alloca(npfd * sizeof(struct pollfd)); |
305 |
snd_seq_poll_descriptors(hAlsaSeq, pfd, npfd, POLLIN); |
snd_seq_poll_descriptors(hAlsaSeq, pfd, npfd, POLLIN); |
306 |
while (true) { |
while (true) { |
307 |
|
// poll() is defined as thread cancelation point by POSIX |
308 |
if (poll(pfd, npfd, 100000) > 0) { |
if (poll(pfd, npfd, 100000) > 0) { |
309 |
do { |
do { |
310 |
|
TestCancel(); |
311 |
|
|
312 |
|
// prevent thread from being cancelled |
313 |
|
// (e.g. to prevent deadlocks while holding mutex lock(s)) |
314 |
|
pushCancelable(false); |
315 |
|
|
316 |
snd_seq_event_input(hAlsaSeq, &ev); |
snd_seq_event_input(hAlsaSeq, &ev); |
317 |
int port = (int) ev->dest.port; |
int port = (int) ev->dest.port; |
318 |
MidiInputPort* pMidiInputPort = Ports[port]; |
MidiInputPort* pMidiInputPort = Ports[port]; |
360 |
break; |
break; |
361 |
} |
} |
362 |
snd_seq_free_event(ev); |
snd_seq_free_event(ev); |
363 |
|
|
364 |
|
// now allow thread being cancelled again |
365 |
|
// (since all mutexes are now unlocked) |
366 |
|
popCancelable(); |
367 |
|
|
368 |
} while (snd_seq_event_input_pending(hAlsaSeq, 0) > 0); |
} while (snd_seq_event_input_pending(hAlsaSeq, 0) > 0); |
369 |
} |
} |
370 |
} |
} |