The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
semaphore.h
Go to the documentation of this file.
1#pragma once
2
3/*
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or (at
7 * your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 */
18
19/** API for POSIX semaphores in mmapped memory.
20 *
21 * @file src/lib/util/semaphore.h
22 *
23 * @copyright 2025 Network RADIUS SAS (legal@networkradius.com)
24 */
25RCSIDH(semaphore_h, "$Id: 64ef3099e093d7e1589061a68b1e9bb3e27bb2f1 $")
26
27#include <freeradius-devel/util/talloc.h>
28
29/*
30 * Other OS's have sem_init, OS X doesn't.
31 */
32#ifdef HAVE_SEMAPHORE_H
33#include <semaphore.h>
34#endif
35
36#define SEMAPHORE_LOCKED (0)
37
38#ifdef __APPLE__
39#include <mach/task.h>
40#include <mach/mach_init.h>
41#include <mach/semaphore.h>
42
43typedef semaphore_t fr_sem_t;
44#undef sem_init
45#define sem_init(s,p,c) semaphore_create(mach_task_self(),s,SYNC_POLICY_FIFO,c)
46#undef sem_wait
47#define sem_wait(s) semaphore_wait(*s)
48#undef sem_post
49#define sem_post(s) semaphore_signal(*s)
50#undef sem_destroy
51#define sem_destroy(s) semaphore_destroy(mach_task_self(),*s)
52#else
53typedef sem_t fr_sem_t;
54#endif /* __APPLE__ */
55
56#define SEM_WAIT_INTR(_x) do {if (sem_wait(_x) == 0) break;} while (errno == EINTR)
57
59
60void fr_sem_free(fr_sem_t *sem);
#define RCSIDH(h, id)
Definition build.h:489
API for POSIX semaphores in mmapped memory.
void fr_sem_free(fr_sem_t *sem)
Definition semaphore.c:50
fr_sem_t * fr_sem_alloc(void)
Definition semaphore.c:30
sem_t fr_sem_t
Definition semaphore.h:53