UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
platform_semaphore.c
Go to the documentation of this file.
1/*
2 * FILE: platform_semaphore.c
3 * AUTHORS: Martin Benes <martinbenesh@gmail.com>
4 * Lukas Hejtmanek <xhejtman@ics.muni.cz>
5 * Petr Holub <hopet@ics.muni.cz>
6 * Milos Liska <xliska@fi.muni.cz>
7 * Jiri Matela <matela@ics.muni.cz>
8 * Dalibor Matura <255899@mail.muni.cz>
9 * Ian Wesley-Smith <iwsmith@cct.lsu.edu>
10 *
11 * Copyright (c) 2005-2012 CESNET z.s.p.o.
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, is permitted provided that the following conditions
15 * are met:
16 *
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 *
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
23 *
24 * 3. All advertising materials mentioning features or use of this software
25 * must display the following acknowledgement:
26 *
27 * This product includes software developed by CESNET z.s.p.o.
28 *
29 * 4. Neither the name of CESNET nor the names of its contributors may be used
30 * to endorse or promote products derived from this software without specific
31 * prior written permission.
32 *
33 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS
34 * "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
35 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
36 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
37 * EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
38 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
39 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
40 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
41 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
42 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
43 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
44 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45 *
46 *
47 */
48
49#ifdef HAVE_CONFIG_H
50#include "config.h"
51#include "config_unix.h"
52#include "config_win32.h"
53#endif // HAVE_CONFIG_H
54
55#include "debug.h"
56
57#ifdef __APPLE__
58#include <mach/semaphore.h>
59#include <mach/task.h>
60#include <mach/mach.h>
61#else
62#include <semaphore.h>
63#endif /* __APPLE__ */
64
66
67void platform_sem_init(void *semStructure, int pshared, int initialValue)
68{
69#ifdef __APPLE__
70 UNUSED(pshared);
71 semaphore_create(mach_task_self(), (semaphore_t *) semStructure,
72 SYNC_POLICY_FIFO, initialValue);
73#else
74 if (sem_init((sem_t *) semStructure, pshared, initialValue) != 0) {
75 perror("sem_init");
76 abort();
77 }
78#endif /* __APPLE__ */
79}
80
81void platform_sem_post(void *semStructure)
82{
83#ifdef __APPLE__
84 semaphore_signal(*((semaphore_t *) semStructure));
85#else
86 sem_post((sem_t *) semStructure);
87#endif /* __APPLE__ */
88}
89
90void platform_sem_wait(void *semStructure)
91{
92#ifdef __APPLE__
93 semaphore_wait(*((semaphore_t *) semStructure));
94#else
95 int ret = 0;
96 while ((ret = sem_wait((sem_t *) semStructure)) == -1 && errno == EINTR) { }
97 if (ret == -1) {
98 perror("sem_wait");
99 }
100#endif /* __APPLE__ */
101}
102
103void platform_sem_destroy(void *semStructure)
104{
105#ifdef __APPLE__
106 semaphore_destroy(mach_task_self(), *(semaphore_t *) semStructure);
107#else
108 sem_destroy((sem_t *) semStructure);
109#endif /* __APPLE__ */
110}
111
#define UNUSED(x)
void platform_sem_post(void *semStructure)
void platform_sem_wait(void *semStructure)
void platform_sem_init(void *semStructure, int pshared, int initialValue)
void platform_sem_destroy(void *semStructure)