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_ 289 mutex(
const mutex& ) =
delete;
290 mutex& operator=(
const mutex& ) =
delete;
291 mutex( mutex&& ) =
delete;
292 mutex& operator=( mutex&& ) =
delete;
298 void unlock() noexcept
305 friend class condition_variable;
306 friend class mutex_locker;
309 class condition_variable
312 condition_variable() noexcept
316 ~condition_variable()
320 void signal() noexcept
324 void broadcast() noexcept
328 void wait( mutex& mutex ) noexcept
332 int timedwait( mutex& mutex,
vlc_tick_t deadline ) noexcept
349 mutex_locker( mutex& m ) noexcept
350 : mutex_locker( &m.m_mutex )
357 mutex_locker(
const mutex_locker& ) =
delete;
358 mutex_locker& operator=(
const mutex_locker& ) =
delete;
359 mutex_locker( mutex_locker&& ) =
delete;
360 mutex_locker& operator=( mutex_locker&& ) =
delete;
373 semaphore(
unsigned int count ) noexcept
382 semaphore(
const semaphore& ) =
delete;
383 semaphore& operator=(
const semaphore& ) =
delete;
384 semaphore( semaphore&& ) =
delete;
385 semaphore& operator=( semaphore&& ) =
delete;
396 int wait_i11e() noexcept
407 #endif // VLC_THREADS_H_ 413 #endif // VLC_CXX_HELPERS_HPP void vlc_cond_signal(vlc_cond_t *p_condvar)
Wakes up one thread waiting on a condition variable.
Definition: thread.c:219
int vlc_cond_timedwait(vlc_cond_t *p_condvar, vlc_mutex_t *p_mutex, vlc_tick_t deadline)
Waits on a condition variable up to a certain date.
Definition: thread.c:236
void vlc_sem_destroy(vlc_sem_t *sem)
Deinitializes a semaphore.
Definition: thread.c:294
pthread_mutex_t vlc_mutex_t
Mutex.
Definition: vlc_threads.h:278
vlc_mutex_t lock
Definition: rand.c:32
void vlc_mutex_unlock(vlc_mutex_t *p_mutex)
Releases a mutex.
Definition: thread.c:134
void vlc_cond_wait(vlc_cond_t *p_condvar, vlc_mutex_t *p_mutex)
Waits on a condition variable.
Definition: thread.c:230
void vlc_sem_init(vlc_sem_t *sem, unsigned value)
Initializes a semaphore.
Definition: thread.c:288
int64_t vlc_tick_t
High precision date or time interval.
Definition: vlc_tick.h:45
void vlc_cond_broadcast(vlc_cond_t *p_condvar)
Wakes up all threads waiting on a condition variable.
Definition: thread.c:225
void vlc_cond_init(vlc_cond_t *p_condvar)
Initializes a condition variable.
Definition: thread.c:179
int vlc_sem_post(vlc_sem_t *sem)
Increments the value of a semaphore.
Definition: thread.c:306
size_t count
Definition: core.c:402
pthread_cond_t vlc_cond_t
Condition variable.
Definition: vlc_threads.h:290
sem_t vlc_sem_t
Semaphore.
Definition: vlc_threads.h:308
void vlc_cond_destroy(vlc_cond_t *p_condvar)
Deinitializes a condition variable.
Definition: thread.c:191
int vlc_sem_wait_i11e(vlc_sem_t *sem)
Interruptible variant of vlc_sem_wait().
Definition: interrupt.c:198
void vlc_mutex_lock(vlc_mutex_t *p_mutex)
Acquires a mutex.
Definition: thread.c:116
void vlc_sem_wait(vlc_sem_t *sem)
Waits on a semaphore.
Definition: thread.c:320
void vlc_mutex_init(vlc_mutex_t *p_mutex)
Initializes a fast mutex.
Definition: thread.c:85
This file declares interruptible sleep functions.
void vlc_mutex_destroy(vlc_mutex_t *p_mutex)
Deinitializes a mutex.
Definition: thread.c:110