23#ifndef VLC_CXX_HELPERS_HPP
24#define VLC_CXX_HELPERS_HPP
68template <
typename T,
typename Releaser>
69inline auto wrap_cptr( T* ptr, Releaser&& r )
noexcept
70 -> std::unique_ptr<T,
typename std::decay<
decltype( r )>::type>
72 return std::unique_ptr<T,
typename std::decay<
decltype( r )>::type>{
73 ptr, std::forward<Releaser>( r )
94template <
typename T,
typename Releaser>
95inline auto wrap_carray( T* ptr, Releaser&& r )
noexcept
96 -> std::unique_ptr<T[],
typename std::decay<
decltype( r )>::type>
98 return std::unique_ptr<T[],
typename std::decay<
decltype( r )>::type>{
99 ptr, std::forward<Releaser>( r )
109inline std::unique_ptr<T, void (*)(
void*)> wrap_cptr( T* ptr )
noexcept
111 return wrap_cptr( ptr, &free );
120inline std::unique_ptr<T[], void (*)(
void*)> wrap_carray( T* ptr )
noexcept
122 return wrap_carray( ptr, &free );
148template <
typename T,
typename H,
typename R, H HOLD, R RELEASE>
149class vlc_shared_data_ptr {
154 vlc_shared_data_ptr() =
default;
167 explicit vlc_shared_data_ptr(T *ptr,
bool hold =
true)
174 vlc_shared_data_ptr(std::nullptr_t)
179 vlc_shared_data_ptr(
const vlc_shared_data_ptr &other)
180 : vlc_shared_data_ptr(other.ptr) {}
182 vlc_shared_data_ptr(vlc_shared_data_ptr &&other) noexcept
188 ~vlc_shared_data_ptr()
194 vlc_shared_data_ptr &operator=(
const vlc_shared_data_ptr &other)
196 reset(other.ptr,
true);
200 vlc_shared_data_ptr &operator=(vlc_shared_data_ptr &&other)
noexcept
202 reset(other.ptr,
false);
207 bool operator==(
const vlc_shared_data_ptr &other)
const
209 return ptr == other.ptr;
212 bool operator==(std::nullptr_t)
const noexcept
214 return ptr ==
nullptr;
217 bool operator!=(
const vlc_shared_data_ptr &other)
const
219 return !(*
this == other);
222 bool operator!=(std::nullptr_t)
const noexcept
224 return ptr !=
nullptr;
227 explicit operator bool()
const
237 T *operator->()
const
264 void reset(T *newptr =
nullptr,
bool hold =
true)
275#define vlc_shared_data_ptr_type(type, hold, release) \
276 ::vlc::vlc_shared_data_ptr<type, decltype(&hold), decltype(&release), \
292 mutex(
const mutex& ) =
delete;
293 mutex& operator=(
const mutex& ) =
delete;
294 mutex( mutex&& ) =
delete;
295 mutex& operator=( mutex&& ) =
delete;
301 void unlock() noexcept
308 friend class condition_variable;
309 friend class mutex_locker;
312class condition_variable
315 condition_variable() noexcept
319 void signal() noexcept
323 void broadcast() noexcept
327 void wait( mutex& mutex )
noexcept
331 int timedwait( mutex& mutex,
vlc_tick_t deadline )
noexcept
348 mutex_locker( mutex& m ) noexcept
349 : mutex_locker( &m.m_mutex )
356 mutex_locker(
const mutex_locker& ) =
delete;
357 mutex_locker& operator=(
const mutex_locker& ) =
delete;
358 mutex_locker( mutex_locker&& ) =
delete;
359 mutex_locker& operator=( mutex_locker&& ) =
delete;
372 semaphore(
unsigned int count )
noexcept
380 semaphore(
const semaphore& ) =
delete;
381 semaphore& operator=(
const semaphore& ) =
delete;
382 semaphore( semaphore&& ) =
delete;
383 semaphore& operator=( semaphore&& ) =
delete;
394 int wait_i11e() noexcept
412 class invalid :
public std::runtime_error
415 explicit invalid(
const char* url )
416 : std::runtime_error( std::string{
"Invalid url: " } + url )
423 psz_buffer =
nullptr;
424 psz_pathbuffer =
nullptr;
428 explicit url(
const char* str )
433 throw invalid( str );
437 explicit url(
const std::string& str )
447 url(
const url& ) =
delete;
448 url& operator=(
const url& ) =
delete;
450 url( url&& u ) noexcept
454 u.psz_pathbuffer =
nullptr;
455 u.psz_host =
nullptr;
458 url& operator=( url&& u )
noexcept
462 u.psz_buffer =
nullptr;
463 u.psz_pathbuffer =
nullptr;
464 u.psz_host =
nullptr;
size_t count
Definition: core.c:403
void vlc_cond_signal(vlc_cond_t *cond)
Wakes up one thread waiting on a condition variable.
Definition: threads.c:204
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:303
void vlc_cond_broadcast(vlc_cond_t *cond)
Wakes up all threads waiting on a condition variable.
Definition: threads.c:231
void vlc_cond_wait(vlc_cond_t *cond, vlc_mutex_t *mutex)
Waits on a condition variable.
Definition: threads.c:291
void vlc_cond_init(vlc_cond_t *cond)
Initializes a condition variable.
Definition: threads.c:185
int vlc_sem_wait_i11e(vlc_sem_t *sem)
Interruptible variant of vlc_sem_wait().
Definition: interrupt.c:198
void vlc_mutex_unlock(vlc_mutex_t *mtx)
Releases a mutex.
Definition: threads.c:160
void vlc_mutex_init(vlc_mutex_t *mtx)
Initializes a fast mutex.
Definition: threads.c:74
void vlc_mutex_lock(vlc_mutex_t *mtx)
Acquires a mutex.
Definition: threads.c:106
void vlc_sem_wait(vlc_sem_t *sem)
Waits on a semaphore.
Definition: threads.c:355
int vlc_sem_post(vlc_sem_t *sem)
Increments the value of a semaphore.
Definition: threads.c:339
void vlc_sem_init(vlc_sem_t *sem, unsigned value)
Initializes a semaphore.
Definition: threads.c:334
int vlc_UrlParse(vlc_url_t *url, const char *str)
Parses an URI or IRI.
Definition: url.c:581
vlc_mutex_t lock
Definition: rand.c:33
Condition variable.
Definition: vlc_threads.h:322
Mutex.
Definition: vlc_threads.h:195
Semaphore.
Definition: vlc_threads.h:422
Definition: vlc_url.h:146
char * psz_buffer
Definition: vlc_url.h:156
void vlc_UrlClean(vlc_url_t *restrict url)
Definition: url.c:621
struct vlc_url_t vlc_url_t
Definition: vlc_common.h:450
This file declares interruptible sleep functions.
int64_t vlc_tick_t
High precision date or time interval.
Definition: vlc_tick.h:45