23 #ifndef VLC_CXX_HELPERS_HPP 24 #define VLC_CXX_HELPERS_HPP 34 #include <type_traits> 66 template <
typename T,
typename Releaser>
67 inline auto wrap_cptr( T* ptr, Releaser&& r ) noexcept
68 -> std::unique_ptr<T, typename std::decay<decltype( r )>::type>
70 return std::unique_ptr<T, typename std::decay<decltype( r )>::type>{
71 ptr, std::forward<Releaser>( r )
92 template <
typename T,
typename Releaser>
93 inline auto wrap_carray( T* ptr, Releaser&& r ) noexcept
94 -> std::unique_ptr<T[], typename std::decay<decltype( r )>::type>
96 return std::unique_ptr<T[], typename std::decay<decltype( r )>::type>{
97 ptr, std::forward<Releaser>( r )
106 template <
typename T>
107 inline std::unique_ptr<T, void (*)(void*)> wrap_cptr( T* ptr ) noexcept
109 return wrap_cptr( ptr, &free );
117 template <
typename T>
118 inline std::unique_ptr<T[], void (*)(void*)> wrap_carray( T* ptr ) noexcept
120 return wrap_carray( ptr, &free );
146 template <
typename T,
typename H,
typename R, H HOLD, R RELEASE>
147 class vlc_shared_data_ptr {
152 vlc_shared_data_ptr() =
default;
165 explicit vlc_shared_data_ptr(T *ptr,
bool hold =
true)
172 vlc_shared_data_ptr(
const vlc_shared_data_ptr &other)
173 : vlc_shared_data_ptr(other.ptr) {}
175 vlc_shared_data_ptr(vlc_shared_data_ptr &&other) noexcept
181 ~vlc_shared_data_ptr()
187 vlc_shared_data_ptr &operator=(
const vlc_shared_data_ptr &other)
189 reset(other.ptr,
true);
193 vlc_shared_data_ptr &operator=(vlc_shared_data_ptr &&other) noexcept
195 reset(other.ptr,
false);
200 bool operator==(
const vlc_shared_data_ptr &other)
const 202 return ptr == other.ptr;
205 bool operator==(std::nullptr_t)
const noexcept
207 return ptr ==
nullptr;
210 bool operator!=(
const vlc_shared_data_ptr &other)
const 212 return !(*
this == other);
215 bool operator!=(std::nullptr_t)
const noexcept
217 return ptr !=
nullptr;
220 explicit operator bool()
const 230 T *operator->()
const 257 void reset(T *newptr =
nullptr,
bool hold =
true)
268 #define vlc_shared_data_ptr_type(type, hold, release) \ 269 ::vlc::vlc_shared_data_ptr<type, decltype(&hold), decltype(&release), \ 272 #ifdef VLC_THREADS_H_ 285 mutex(
const mutex& ) =
delete;
286 mutex& operator=(
const mutex& ) =
delete;
287 mutex( mutex&& ) =
delete;
288 mutex& operator=( mutex&& ) =
delete;
294 void unlock() noexcept
301 friend class condition_variable;
302 friend class mutex_locker;
305 class condition_variable
308 condition_variable() noexcept
312 void signal() noexcept
316 void broadcast() noexcept
320 void wait( mutex& mutex ) noexcept
324 int timedwait( mutex& mutex,
vlc_tick_t deadline ) noexcept
341 mutex_locker( mutex& m ) noexcept
342 : mutex_locker( &m.m_mutex )
349 mutex_locker(
const mutex_locker& ) =
delete;
350 mutex_locker& operator=(
const mutex_locker& ) =
delete;
351 mutex_locker( mutex_locker&& ) =
delete;
352 mutex_locker& operator=( mutex_locker&& ) =
delete;
365 semaphore(
unsigned int count ) noexcept
373 semaphore(
const semaphore& ) =
delete;
374 semaphore& operator=(
const semaphore& ) =
delete;
375 semaphore( semaphore&& ) =
delete;
376 semaphore& operator=( semaphore&& ) =
delete;
387 int wait_i11e() noexcept
398 #endif // VLC_THREADS_H_ 404 #endif // VLC_CXX_HELPERS_HPP Semaphore.
Definition: vlc_threads.h:498
vlc_mutex_t lock
Definition: rand.c:32
int64_t vlc_tick_t
High precision date or time interval.
Definition: vlc_tick.h:45
void vlc_mutex_unlock(vlc_mutex_t *mtx)
Releases a mutex.
Definition: threads.c:212
size_t count
Definition: core.c:402
int vlc_cond_timedwait(vlc_cond_t *cond, vlc_mutex_t *mutex, vlc_tick_t deadline)
Waits on a condition variable up to a certain date.
Definition: threads.c:367
Mutex.
Definition: vlc_threads.h:266
void vlc_cond_broadcast(vlc_cond_t *cond)
Wakes up all threads waiting on a condition variable.
Definition: threads.c:285
int vlc_sem_post(vlc_sem_t *sem)
Increments the value of a semaphore.
Definition: threads.c:484
Condition variable.
Definition: vlc_threads.h:390
void vlc_sem_wait(vlc_sem_t *sem)
Waits on a semaphore.
Definition: threads.c:500
int vlc_sem_wait_i11e(vlc_sem_t *sem)
Interruptible variant of vlc_sem_wait().
Definition: interrupt.c:197
void vlc_cond_signal(vlc_cond_t *cond)
Wakes up one thread waiting on a condition variable.
Definition: threads.c:258
void vlc_cond_wait(vlc_cond_t *cond, vlc_mutex_t *mutex)
Waits on a condition variable.
Definition: threads.c:356
This file declares interruptible sleep functions.
void vlc_sem_init(vlc_sem_t *sem, unsigned value)
Initializes a semaphore.
Definition: threads.c:479
void vlc_cond_init(vlc_cond_t *cond)
Initializes a condition variable.
Definition: threads.c:237
void vlc_mutex_init(vlc_mutex_t *mtx)
Initializes a fast mutex.
Definition: threads.c:123
void vlc_mutex_lock(vlc_mutex_t *mtx)
Acquires a mutex.
Definition: threads.c:158