1 /*****************************************************************************
2 * thread.c : pthread back-end for LibVLC
3 *****************************************************************************
4 * Copyright (C) 1999-2013 VLC authors and VideoLAN
6 * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
7 * Samuel Hocevar <sam@zoy.org>
8 * Gildas Bazin <gbazin@netcourrier.com>
11 * Felix Paul Kühne <fkuehne # videolan.org>
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU Lesser General Public License as published by
15 * the Free Software Foundation; either version 2.1 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License for more details.
23 * You should have received a copy of the GNU Lesser General Public License
24 * along with this program; if not, write to the Free Software Foundation,
25 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
26 *****************************************************************************/
32 #include <vlc_common.h>
33 #include <vlc_atomic.h>
41 #include <mach/mach_init.h> /* mach_task_self in semaphores */
42 #include <mach/mach_time.h>
45 static mach_timebase_info_data_t vlc_clock_conversion_factor;
47 static void vlc_clock_setup_once (void)
49 if (unlikely(mach_timebase_info (&vlc_clock_conversion_factor) != 0))
53 static pthread_once_t vlc_clock_once = PTHREAD_ONCE_INIT;
55 #define vlc_clock_setup() \
56 pthread_once(&vlc_clock_once, vlc_clock_setup_once)
58 static struct timespec mtime_to_ts (mtime_t date)
60 lldiv_t d = lldiv (date, CLOCK_FREQ);
61 struct timespec ts = { d.quot, d.rem * (1000000000 / CLOCK_FREQ) };
66 /* Print a backtrace to the standard error for debugging purpose. */
67 void vlc_trace (const char *fn, const char *file, unsigned line)
69 fprintf (stderr, "at %s:%u in %s\n", file, line, fn);
70 fflush (stderr); /* needed before switch to low-level I/O */
72 int len = backtrace (stack, sizeof (stack) / sizeof (stack[0]));
73 backtrace_symbols_fd (stack, len, 2);
77 static inline unsigned long vlc_threadid (void)
79 union { pthread_t th; unsigned long int i; } v = { };
80 v.th = pthread_self ();
85 /* Reports a fatal error from the threading layer, for debugging purposes. */
87 vlc_thread_fatal (const char *action, int error,
88 const char *function, const char *file, unsigned line)
90 int canc = vlc_savecancel ();
91 fprintf (stderr, "LibVLC fatal error %s (%d) in thread %lu ",
92 action, error, vlc_threadid ());
93 vlc_trace (function, file, line);
98 switch (strerror_r (error, buf, sizeof (buf)))
103 case ERANGE: /* should never happen */
104 msg = "unknown (too big to display)";
107 msg = "unknown (invalid error number)";
110 fprintf (stderr, " Error message: %s\n", msg);
113 vlc_restorecancel (canc);
117 # define VLC_THREAD_ASSERT( action ) \
119 vlc_thread_fatal (action, val, __func__, __FILE__, __LINE__)
121 # define VLC_THREAD_ASSERT( action ) ((void)val)
124 /* Initializes a fast mutex. */
125 void vlc_mutex_init( vlc_mutex_t *p_mutex )
127 pthread_mutexattr_t attr;
129 if (unlikely(pthread_mutexattr_init (&attr)))
132 pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_DEFAULT);
134 pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_ERRORCHECK);
136 if (unlikely(pthread_mutex_init (p_mutex, &attr)))
138 pthread_mutexattr_destroy( &attr );
141 /* Initializes a recursive mutex.
142 * warning: This is strongly discouraged. Please use normal mutexes. */
143 void vlc_mutex_init_recursive( vlc_mutex_t *p_mutex )
145 pthread_mutexattr_t attr;
147 if (unlikely(pthread_mutexattr_init (&attr)))
149 pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE);
150 if (unlikely(pthread_mutex_init (p_mutex, &attr)))
152 pthread_mutexattr_destroy( &attr );
156 /* Destroys a mutex. The mutex must not be locked.
158 * parameter: p_mutex mutex to destroy
159 * returns: always succeeds */
160 void vlc_mutex_destroy (vlc_mutex_t *p_mutex)
162 int val = pthread_mutex_destroy( p_mutex );
163 VLC_THREAD_ASSERT ("destroying mutex");
167 # ifdef HAVE_VALGRIND_VALGRIND_H
168 # include <valgrind/valgrind.h>
170 # define RUNNING_ON_VALGRIND (0)
173 /* Asserts that a mutex is locked by the calling thread. */
174 void vlc_assert_locked (vlc_mutex_t *p_mutex)
176 if (RUNNING_ON_VALGRIND > 0)
178 assert (pthread_mutex_lock (p_mutex) == EDEADLK);
182 /* Acquires a mutex. If needed, waits for any other thread to release it.
183 * Beware of deadlocks when locking multiple mutexes at the same time,
184 * or when using mutexes from callbacks.
185 * This function is not a cancellation-point.
187 * parameter: p_mutex mutex initialized with vlc_mutex_init() or
188 * vlc_mutex_init_recursive()
190 void vlc_mutex_lock (vlc_mutex_t *p_mutex)
192 int val = pthread_mutex_lock( p_mutex );
193 VLC_THREAD_ASSERT ("locking mutex");
196 /* Acquires a mutex if and only if it is not currently held by another thread.
197 * This function never sleeps and can be used in delay-critical code paths.
198 * This function is not a cancellation-point.
200 * BEWARE: If this function fails, then the mutex is held... by another
201 * thread. The calling thread must deal with the error appropriately. That
202 * typically implies postponing the operations that would have required the
203 * mutex. If the thread cannot defer those operations, then it must use
204 * vlc_mutex_lock(). If in doubt, use vlc_mutex_lock() instead.
206 * parameter: p_mutex mutex initialized with vlc_mutex_init() or
207 * vlc_mutex_init_recursive()
208 * returns: 0 if the mutex could be acquired, an error code otherwise. */
209 int vlc_mutex_trylock (vlc_mutex_t *p_mutex)
211 int val = pthread_mutex_trylock( p_mutex );
214 VLC_THREAD_ASSERT ("locking mutex");
218 /* Release a mutex (or crashes if the mutex is not locked by the caller).
219 * parameter p_mutex mutex locked with vlc_mutex_lock(). */
220 void vlc_mutex_unlock (vlc_mutex_t *p_mutex)
222 int val = pthread_mutex_unlock( p_mutex );
223 VLC_THREAD_ASSERT ("unlocking mutex");
228 VLC_CLOCK_MONOTONIC = 0,
232 /* Initialize a condition variable. */
233 void vlc_cond_init (vlc_cond_t *p_condvar)
235 if (unlikely(pthread_cond_init (&p_condvar->cond, NULL)))
237 p_condvar->clock = VLC_CLOCK_MONOTONIC;
240 /* Initialize a condition variable.
241 * Contrary to vlc_cond_init(), the wall clock will be used as a reference for
242 * the vlc_cond_timedwait() time-out parameter. */
243 void vlc_cond_init_daytime (vlc_cond_t *p_condvar)
245 if (unlikely(pthread_cond_init (&p_condvar->cond, NULL)))
247 p_condvar->clock = VLC_CLOCK_REALTIME;
251 /* Destroys a condition variable. No threads shall be waiting or signaling the
253 * parameter: p_condvar condition variable to destroy */
254 void vlc_cond_destroy (vlc_cond_t *p_condvar)
256 int val = pthread_cond_destroy (&p_condvar->cond);
258 /* due to a faulty pthread implementation within Darwin 11 and
259 * later condition variables cannot be destroyed without
260 * terminating the application immediately.
261 * This Darwin kernel issue is still present in version 13
262 * and might not be resolved prior to Darwin 15.
265 * To work-around this, we are just leaking the condition variable
266 * which is acceptable due to VLC's low number of created variables
267 * and its usually limited runtime.
268 * Ideally, we should implement a re-useable pool.
272 printf("pthread_cond_destroy returned %i\n", val);
279 VLC_THREAD_ASSERT ("destroying condition");
282 /* Wake up one thread waiting on a condition variable, if any.
283 * parameter: p_condvar condition variable */
284 void vlc_cond_signal (vlc_cond_t *p_condvar)
286 int val = pthread_cond_signal (&p_condvar->cond);
287 VLC_THREAD_ASSERT ("signaling condition variable");
290 /* Wake up all threads (if any) waiting on a condition variable.
291 * parameter: p_cond condition variable */
292 void vlc_cond_broadcast (vlc_cond_t *p_condvar)
294 pthread_cond_broadcast (&p_condvar->cond);
297 /* Wait for a condition variable. The calling thread will be suspended until
298 * another thread calls vlc_cond_signal() or vlc_cond_broadcast() on the same
299 * condition variable, the thread is cancelled with vlc_cancel(), or the
300 * system causes a "spurious" unsolicited wake-up.
302 * A mutex is needed to wait on a condition variable. It must <b>not</b> be
303 * a recursive mutex. Although it is possible to use the same mutex for
304 * multiple condition, it is not valid to use different mutexes for the same
305 * condition variable at the same time from different threads.
307 * In case of thread cancellation, the mutex is always locked before
308 * cancellation proceeds.
310 * The canonical way to use a condition variable to wait for event foobar is:
312 vlc_mutex_lock (&lock);
313 mutex_cleanup_push (&lock); // release the mutex in case of cancellation
316 vlc_cond_wait (&wait, &lock);
318 --- foobar is now true, do something about it here --
320 vlc_cleanup_run (); // release the mutex
322 * 1st parameter: p_condvar condition variable to wait on
323 * 2nd parameter: p_mutex mutex which is unlocked while waiting,
324 * then locked again when waking up. */
325 void vlc_cond_wait (vlc_cond_t *p_condvar, vlc_mutex_t *p_mutex)
327 int val = pthread_cond_wait (&p_condvar->cond, p_mutex);
328 VLC_THREAD_ASSERT ("waiting on condition");
331 /* Wait for a condition variable up to a certain date.
332 * This works like vlc_cond_wait(), except for the additional time-out.
334 * If the variable was initialized with vlc_cond_init(), the timeout has the
335 * same arbitrary origin as mdate(). If the variable was initialized with
336 * vlc_cond_init_daytime(), the timeout is expressed from the Unix epoch.
338 * 1st parameter: p_condvar condition variable to wait on
339 * 2nd parameter: p_mutex mutex which is unlocked while waiting,
340 * then locked again when waking up.
341 * 3rd parameter: deadline <b>absolute</b> timeout
343 * returns 0 if the condition was signaled, an error code in case of timeout.
345 int vlc_cond_timedwait (vlc_cond_t *p_condvar, vlc_mutex_t *p_mutex,
351 * Note that both pthread_cond_timedwait_relative_np and pthread_cond_timedwait
352 * convert the given timeout to a mach absolute deadline, with system startup
353 * as the time origin. There is no way you can change this behaviour.
355 * For more details, see: https://devforums.apple.com/message/931605
358 if (p_condvar->clock == VLC_CLOCK_MONOTONIC) {
361 * mdate() is the monotonic clock, pthread_cond_timedwait expects
362 * origin of gettimeofday(). Use timedwait_relative_np() instead.
364 mtime_t base = mdate();
368 struct timespec ts = mtime_to_ts(deadline);
370 val = pthread_cond_timedwait_relative_np(&p_condvar->cond, p_mutex, &ts);
373 /* variant for vlc_cond_init_daytime */
374 assert (p_condvar->clock == VLC_CLOCK_REALTIME);
377 * FIXME: It is assumed, that in this case the system waits until the real
378 * time deadline is passed, even if the real time is adjusted in between.
379 * This is not fulfilled, as described above.
381 struct timespec ts = mtime_to_ts(deadline);
383 val = pthread_cond_timedwait(&p_condvar->cond, p_mutex, &ts);
386 if (val != ETIMEDOUT)
387 VLC_THREAD_ASSERT ("timed-waiting on condition");
391 /* Initialize a semaphore. */
392 void vlc_sem_init (vlc_sem_t *sem, unsigned value)
394 if (unlikely(semaphore_create(mach_task_self(), sem, SYNC_POLICY_FIFO, value) != KERN_SUCCESS))
398 /* Destroy a semaphore. */
399 void vlc_sem_destroy (vlc_sem_t *sem)
403 if (likely(semaphore_destroy(mach_task_self(), *sem) == KERN_SUCCESS))
408 VLC_THREAD_ASSERT ("destroying semaphore");
411 /* Increment the value of a semaphore.
412 * returns 0 on success, EOVERFLOW in case of integer overflow */
413 int vlc_sem_post (vlc_sem_t *sem)
417 if (likely(semaphore_signal(*sem) == KERN_SUCCESS))
422 if (unlikely(val != EOVERFLOW))
423 VLC_THREAD_ASSERT ("unlocking semaphore");
427 /* Atomically wait for the semaphore to become non-zero (if needed),
428 * then decrements it. */
429 void vlc_sem_wait (vlc_sem_t *sem)
433 if (likely(semaphore_wait(*sem) == KERN_SUCCESS))
438 VLC_THREAD_ASSERT ("locking semaphore");
441 /* Initialize a read/write lock. */
442 void vlc_rwlock_init (vlc_rwlock_t *lock)
444 if (unlikely(pthread_rwlock_init (lock, NULL)))
448 /* Destroy an initialized unused read/write lock. */
449 void vlc_rwlock_destroy (vlc_rwlock_t *lock)
451 int val = pthread_rwlock_destroy (lock);
452 VLC_THREAD_ASSERT ("destroying R/W lock");
455 /* Acquire a read/write lock for reading. Recursion is allowed.
456 * Attention: This function may be a cancellation point. */
457 void vlc_rwlock_rdlock (vlc_rwlock_t *lock)
459 int val = pthread_rwlock_rdlock (lock);
460 VLC_THREAD_ASSERT ("acquiring R/W lock for reading");
463 /* Acquire a read/write lock for writing. Recursion is not allowed.
464 * Attention: This function may be a cancellation point. */
465 void vlc_rwlock_wrlock (vlc_rwlock_t *lock)
467 int val = pthread_rwlock_wrlock (lock);
468 VLC_THREAD_ASSERT ("acquiring R/W lock for writing");
471 /* Release a read/write lock. */
472 void vlc_rwlock_unlock (vlc_rwlock_t *lock)
474 int val = pthread_rwlock_unlock (lock);
475 VLC_THREAD_ASSERT ("releasing R/W lock");
478 /* Allocates a thread-specific variable.
479 * 1st parameter: key where to store the thread-specific variable handle
480 * 2nd parameter: destr a destruction callback. It is called whenever a thread
481 * exits and the thread-specific variable has a non-NULL value.
482 * returns 0 on success, a system error code otherwise.
484 * This function can actually fail because there is a fixed limit on the number
485 * of thread-specific variable in a process on most systems.
487 int vlc_threadvar_create (vlc_threadvar_t *key, void (*destr) (void *))
489 return pthread_key_create (key, destr);
492 void vlc_threadvar_delete (vlc_threadvar_t *p_tls)
494 pthread_key_delete (*p_tls);
497 /* Set a thread-specific variable.
498 * 1st parameter: key thread-local variable key
499 * (created with vlc_threadvar_create())
500 * 2nd parameter: value new value for the variable for the calling thread
501 * returns 0 on success, a system error code otherwise. */
502 int vlc_threadvar_set (vlc_threadvar_t key, void *value)
504 return pthread_setspecific (key, value);
507 /* Get the value of a thread-local variable for the calling thread.
508 * This function cannot fail.
509 * returns the value associated with the given variable for the calling
510 * or NULL if there is no value. */
511 void *vlc_threadvar_get (vlc_threadvar_t key)
513 return pthread_getspecific (key);
516 static bool rt_priorities = false;
517 static int rt_offset;
519 void vlc_threads_setup (libvlc_int_t *p_libvlc)
521 static vlc_mutex_t lock = VLC_STATIC_MUTEX;
522 static bool initialized = false;
524 vlc_mutex_lock (&lock);
525 /* Initializes real-time priorities before any thread is created,
526 * just once per process. */
529 rt_offset = var_InheritInteger (p_libvlc, "rt-offset");
530 rt_priorities = true;
533 vlc_mutex_unlock (&lock);
537 static int vlc_clone_attr (vlc_thread_t *th, pthread_attr_t *attr,
538 void *(*entry) (void *), void *data, int priority)
542 /* Block the signals that signals interface plugin handles.
543 * If the LibVLC caller wants to handle some signals by itself, it should
544 * block these before whenever invoking LibVLC. And it must obviously not
545 * start the VLC signals interface plugin.
547 * LibVLC will normally ignore any interruption caused by an asynchronous
548 * signal during a system call. But there may well be some buggy cases
549 * where it fails to handle EINTR (bug reports welcome). Some underlying
550 * libraries might also not handle EINTR properly.
556 sigdelset (&set, SIGHUP);
557 sigaddset (&set, SIGINT);
558 sigaddset (&set, SIGQUIT);
559 sigaddset (&set, SIGTERM);
561 sigaddset (&set, SIGPIPE); /* We don't want this one, really! */
562 pthread_sigmask (SIG_BLOCK, &set, &oldset);
567 /* The thread stack size.
568 * The lower the value, the less address space per thread, the highest
569 * maximum simultaneous threads per process. Too low values will cause
570 * stack overflows and weird crashes. Set with caution. Also keep in mind
571 * that 64-bits platforms consume more stack than 32-bits one.
573 * Thanks to on-demand paging, thread stack size only affects address space
574 * consumption. In terms of memory, threads only use what they need
575 * (rounded up to the page boundary).
577 * For example, on Linux i386, the default is 2 mega-bytes, which supports
578 * about 320 threads per processes. */
579 #define VLC_STACKSIZE (128 * sizeof (void *) * 1024)
582 ret = pthread_attr_setstacksize (attr, VLC_STACKSIZE);
583 assert (ret == 0); /* fails iif VLC_STACKSIZE is invalid */
586 ret = pthread_create (th, attr, entry, data);
587 pthread_sigmask (SIG_SETMASK, &oldset, NULL);
588 pthread_attr_destroy (attr);
592 /* Create and start a new thread.
594 * The thread must be joined with vlc_join() to reclaim resources when it is
595 * not needed anymore.
597 * 1st parameter: th [OUT] pointer to write the handle of the created thread to
598 * (mandatory, must be non-NULL)
599 * 2nd parameter: entry entry point for the thread
600 * 3rd parameter: data data parameter given to the entry point
601 * 4th parameter: priority thread priority value
602 * returns 0 on success, a standard error code on error. */
603 int vlc_clone (vlc_thread_t *th, void *(*entry) (void *), void *data,
608 pthread_attr_init (&attr);
609 return vlc_clone_attr (th, &attr, entry, data, priority);
612 /* Wait for a thread to complete (if needed), then destroys it.
613 * This is a cancellation point; in case of cancellation, the join does _not_
616 * WARNING: A thread cannot join itself (normally VLC will abort if this is
617 * attempted). Also, a detached thread cannot be joined.
619 * 1st parameter: handle thread handle
620 * 2nd parameter: p_result - pointer to write the thread return value or NULL
622 void vlc_join (vlc_thread_t handle, void **result)
624 int val = pthread_join (handle, result);
625 VLC_THREAD_ASSERT ("joining thread");
628 /* Create and start a new detached thread.
629 * A detached thread cannot be joined. Its resources will be automatically
630 * released whenever the thread exits (in particular, its call stack will be
633 * Detached thread are particularly useful when some work needs to be done
634 * asynchronously, that is likely to be completed much earlier than the thread
635 * can practically be joined. In this case, thread detach can spare memory.
637 * A detached thread may be cancelled, so as to expedite its termination.
638 * Be extremely careful if you do this: while a normal joinable thread can
639 * safely be cancelled after it has already exited, cancelling an already
640 * exited detached thread is undefined: The thread handle would is destroyed
641 * immediately when the detached thread exits. So you need to ensure that the
642 * detached thread is still running before cancellation is attempted.
644 * WARNING: Care must be taken that any resources used by the detached thread
645 * remains valid until the thread completes.
647 * Attention: A detached thread must eventually exit just like another other
648 * thread. In practice, LibVLC will wait for detached threads to exit before
649 * it unloads the plugins.
651 * 1st parameter: th [OUT] pointer to hold the thread handle, or NULL
652 * 2nd parameter: entry entry point for the thread
653 * 3rd parameter: data data parameter given to the entry point
654 * 4th parameter: priority thread priority value
655 * returns 0 on success, a standard error code on error. */
656 int vlc_clone_detach (vlc_thread_t *th, void *(*entry) (void *), void *data,
665 pthread_attr_init (&attr);
666 pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
667 return vlc_clone_attr (th, &attr, entry, data, priority);
670 int vlc_set_priority (vlc_thread_t th, int priority)
672 (void) th; (void) priority;
676 /* Marks a thread as cancelled. Next time the target thread reaches a
677 * cancellation point (while not having disabled cancellation), it will
678 * run its cancellation cleanup handler, the thread variable destructors, and
679 * terminate. vlc_join() must be used afterward regardless of a thread being
680 * cancelled or not. */
681 void vlc_cancel (vlc_thread_t thread_id)
683 pthread_cancel (thread_id);
686 /* Save the current cancellation state (enabled or disabled), then disable
687 * cancellation for the calling thread.
688 * This function must be called before entering a piece of code that is not
689 * cancellation-safe, unless it can be proven that the calling thread will not
691 * returns Previous cancellation state (opaque value for vlc_restorecancel()). */
692 int vlc_savecancel (void)
695 int val = pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, &state);
697 VLC_THREAD_ASSERT ("saving cancellation");
701 /* Restore the cancellation state for the calling thread.
702 * parameter: previous state as returned by vlc_savecancel(). */
703 void vlc_restorecancel (int state)
708 val = pthread_setcancelstate (state, &oldstate);
709 /* This should fail if an invalid value for given for state */
710 VLC_THREAD_ASSERT ("restoring cancellation");
712 if (unlikely(oldstate != PTHREAD_CANCEL_DISABLE))
713 vlc_thread_fatal ("restoring cancellation while not disabled", EINVAL,
714 __func__, __FILE__, __LINE__);
716 pthread_setcancelstate (state, NULL);
720 /* Issues an explicit deferred cancellation point.
721 * This has no effect if thread cancellation is disabled.
722 * This can be called when there is a rather slow non-sleeping operation.
723 * This is also used to force a cancellation point in a function that would
724 * otherwise "not always" be a one (block_FifoGet() is an example). */
725 void vlc_testcancel (void)
727 pthread_testcancel ();
730 void vlc_control_cancel (int cmd, ...)
733 vlc_assert_unreachable ();
736 /* Precision monotonic clock.
738 * In principles, the clock has a precision of 1 MHz. But the actual resolution
739 * may be much lower, especially when it comes to sleeping with mwait() or
740 * msleep(). Most general-purpose operating systems provide a resolution of
741 * only 100 to 1000 Hz.
743 * WARNING: The origin date (time value "zero") is not specified. It is
744 * typically the time the kernel started, but this is platform-dependent.
745 * If you need wall clock time, use gettimeofday() instead.
747 * returns a timestamp in microseconds. */
751 uint64_t date = mach_absolute_time();
753 /* denom is uint32_t, switch to 64 bits to prevent overflow. */
754 uint64_t denom = vlc_clock_conversion_factor.denom;
756 /* Switch to microsecs */
759 /* Split the division to prevent overflow */
760 lldiv_t d = lldiv (vlc_clock_conversion_factor.numer, denom);
762 return (d.quot * date) + ((d.rem * date) / denom);
766 /* Wait until a deadline (possibly later due to OS scheduling).
767 * parameter: deadline timestamp to wait for (see mdate()) */
768 void mwait (mtime_t deadline)
770 deadline -= mdate ();
776 /* Wait for an interval of time.
777 * parameter: delay how long to wait (in microseconds) */
778 void msleep (mtime_t delay)
780 struct timespec ts = mtime_to_ts (delay);
782 /* nanosleep uses mach_absolute_time and mach_wait_until internally,
783 but also handles kernel errors. Thus we use just this. */
784 while (nanosleep (&ts, &ts) == -1)
785 assert (errno == EINTR);
789 * returns the number of available (logical) CPUs. */
790 unsigned vlc_GetCPUCount(void)
792 return sysconf(_SC_NPROCESSORS_CONF);