summaryrefslogtreecommitdiffstats
path: root/osdep/semaphore_osx.c
diff options
context:
space:
mode:
authorder richter <der.richter@gmx.de>2024-02-27 16:55:29 +0100
committerder richter <der.richter@gmx.de>2024-02-28 15:52:47 +0100
commit86fa9b18a3619a379a597ca0902c23dc053cafc0 (patch)
treef187f85a97744bd0468290975e5ec4d10054b25b /osdep/semaphore_osx.c
parent661f45377a17635125ae36f0b8a3487ae13cf606 (diff)
downloadmpv-86fa9b18a3619a379a597ca0902c23dc053cafc0.tar.bz2
mpv-86fa9b18a3619a379a597ca0902c23dc053cafc0.tar.xz
osdep/mac: make mac naming of files, folders and function consistent
rename all macOS namings (osx, macosx, macOS, macos, apple) to mac, to make naming consistent.
Diffstat (limited to 'osdep/semaphore_osx.c')
-rw-r--r--osdep/semaphore_osx.c117
1 files changed, 0 insertions, 117 deletions
diff --git a/osdep/semaphore_osx.c b/osdep/semaphore_osx.c
deleted file mode 100644
index bfb4d571f0..0000000000
--- a/osdep/semaphore_osx.c
+++ /dev/null
@@ -1,117 +0,0 @@
-/* Copyright (C) 2017 the mpv developers
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-#include "osdep/semaphore.h"
-
-#ifdef MP_SEMAPHORE_EMULATION
-
-#include <unistd.h>
-#include <poll.h>
-#include <limits.h>
-#include <sys/time.h>
-#include <errno.h>
-
-#include <common/common.h>
-#include "io.h"
-#include "timer.h"
-
-int mp_sem_init(mp_sem_t *sem, int pshared, unsigned int value)
-{
- if (pshared) {
- errno = ENOSYS;
- return -1;
- }
- if (value > INT_MAX) {
- errno = EINVAL;
- return -1;
- }
- if (mp_make_wakeup_pipe(sem->wakeup_pipe) < 0)
- return -1;
- sem->count = 0;
- mp_mutex_init(&sem->lock);
- return 0;
-}
-
-int mp_sem_wait(mp_sem_t *sem)
-{
- return mp_sem_timedwait(sem, -1);
-}
-
-int mp_sem_trywait(mp_sem_t *sem)
-{
- int r = -1;
- mp_mutex_lock(&sem->lock);
- if (sem->count == 0) {
- char buf[1024];
- ssize_t s = read(sem->wakeup_pipe[0], buf, sizeof(buf));
- if (s > 0 && s <= INT_MAX - sem->count) // can't handle overflows correctly
- sem->count += s;
- }
- if (sem->count > 0) {
- sem->count -= 1;
- r = 0;
- }
- mp_mutex_unlock(&sem->lock);
- if (r < 0)
- errno = EAGAIN;
- return r;
-}
-
-int mp_sem_timedwait(mp_sem_t *sem, int64_t until)
-{
- while (1) {
- if (!mp_sem_trywait(sem))
- return 0;
-
- int timeout = 0;
- if (until == -1) {
- timeout = -1;
- } else if (until >= 0) {
- timeout = (until - mp_time_ns()) / MP_TIME_MS_TO_NS(1);
- timeout = MPCLAMP(timeout, 0, INT_MAX);
- } else {
- assert(false && "Invalid mp_time value!");
- }
-
- struct pollfd fd = {.fd = sem->wakeup_pipe[0], .events = POLLIN};
- int r = poll(&fd, 1, timeout);
- if (r < 0)
- return -1;
- if (r == 0) {
- errno = ETIMEDOUT;
- return -1;
- }
- }
-}
-
-int mp_sem_post(mp_sem_t *sem)
-{
- if (write(sem->wakeup_pipe[1], &(char){0}, 1) == 1)
- return 0;
- // Actually we can't handle overflow fully correctly, because we can't
- // check sem->count atomically, while still being AS-safe.
- errno = EOVERFLOW;
- return -1;
-}
-
-int mp_sem_destroy(mp_sem_t *sem)
-{
- close(sem->wakeup_pipe[0]);
- close(sem->wakeup_pipe[1]);
- mp_mutex_destroy(&sem->lock);
- return 0;
-}
-
-#endif