]>
git.proxmox.com Git - ceph.git/blob - ceph/src/pmdk/src/core/os_thread.h
1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /* Copyright 2015-2020, Intel Corporation */
4 * Copyright (c) 2016, Microsoft Corporation. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
18 * * Neither the name of the copyright holder nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 * os_thread.h -- os thread abstraction layer
51 char padding
[44]; /* linux: 40 windows: 44 */
56 char padding
[56]; /* linux: 56 windows: 13 */
61 char padding
[48]; /* linux: 48 windows: 12 */
66 char padding
[32]; /* linux: 8 windows: 32 */
70 long long align
; /* linux: long windows: 8 FreeBSD: 12 */
71 char padding
[16]; /* 16 to be safe */
74 #define OS_ONCE_INIT { .padding = {0} }
76 typedef unsigned os_tls_key_t
;
80 char padding
[56]; /* linux: 56 windows: 8 */
85 char padding
[56]; /* linux: 56 windows: 8 */
94 #define cpu_set_t cpuset_t
95 typedef uintptr_t os_spinlock_t
;
97 typedef volatile int os_spinlock_t
; /* XXX: not implemented on windows */
100 void os_cpu_zero(os_cpu_set_t
*set
);
101 void os_cpu_set(size_t cpu
, os_cpu_set_t
*set
);
106 int os_once(os_once_t
*o
, void (*func
)(void));
108 int os_tls_key_create(os_tls_key_t
*key
, void (*destructor
)(void *));
109 int os_tls_key_delete(os_tls_key_t key
);
110 int os_tls_set(os_tls_key_t key
, const void *value
);
111 void *os_tls_get(os_tls_key_t key
);
113 int os_mutex_init(os_mutex_t
*__restrict mutex
);
114 int os_mutex_destroy(os_mutex_t
*__restrict mutex
);
115 _When_(return == 0, _Acquires_lock_(mutex
->lock
))
116 int os_mutex_lock(os_mutex_t
*__restrict mutex
);
117 _When_(return == 0, _Acquires_lock_(mutex
->lock
))
118 int os_mutex_trylock(os_mutex_t
*__restrict mutex
);
119 int os_mutex_unlock(os_mutex_t
*__restrict mutex
);
121 /* XXX - non POSIX */
122 int os_mutex_timedlock(os_mutex_t
*__restrict mutex
,
123 const struct timespec
*abstime
);
125 int os_rwlock_init(os_rwlock_t
*__restrict rwlock
);
126 int os_rwlock_destroy(os_rwlock_t
*__restrict rwlock
);
127 int os_rwlock_rdlock(os_rwlock_t
*__restrict rwlock
);
128 int os_rwlock_wrlock(os_rwlock_t
*__restrict rwlock
);
129 int os_rwlock_tryrdlock(os_rwlock_t
*__restrict rwlock
);
130 _When_(return == 0, _Acquires_exclusive_lock_(rwlock
->lock
))
131 int os_rwlock_trywrlock(os_rwlock_t
*__restrict rwlock
);
132 _When_(rwlock
->is_write
!= 0, _Requires_exclusive_lock_held_(rwlock
->lock
))
133 _When_(rwlock
->is_write
== 0, _Requires_shared_lock_held_(rwlock
->lock
))
134 int os_rwlock_unlock(os_rwlock_t
*__restrict rwlock
);
135 int os_rwlock_timedrdlock(os_rwlock_t
*__restrict rwlock
,
136 const struct timespec
*abstime
);
137 int os_rwlock_timedwrlock(os_rwlock_t
*__restrict rwlock
,
138 const struct timespec
*abstime
);
140 int os_spin_init(os_spinlock_t
*lock
, int pshared
);
141 int os_spin_destroy(os_spinlock_t
*lock
);
142 int os_spin_lock(os_spinlock_t
*lock
);
143 int os_spin_unlock(os_spinlock_t
*lock
);
144 int os_spin_trylock(os_spinlock_t
*lock
);
146 int os_cond_init(os_cond_t
*__restrict cond
);
147 int os_cond_destroy(os_cond_t
*__restrict cond
);
148 int os_cond_broadcast(os_cond_t
*__restrict cond
);
149 int os_cond_signal(os_cond_t
*__restrict cond
);
150 int os_cond_timedwait(os_cond_t
*__restrict cond
,
151 os_mutex_t
*__restrict mutex
, const struct timespec
*abstime
);
152 int os_cond_wait(os_cond_t
*__restrict cond
,
153 os_mutex_t
*__restrict mutex
);
157 int os_thread_create(os_thread_t
*thread
, const os_thread_attr_t
*attr
,
158 void *(*start_routine
)(void *), void *arg
);
160 int os_thread_join(os_thread_t
*thread
, void **result
);
162 void os_thread_self(os_thread_t
*thread
);
164 /* thread affinity */
166 int os_thread_setaffinity_np(os_thread_t
*thread
, size_t set_size
,
167 const os_cpu_set_t
*set
);
169 int os_thread_atfork(void (*prepare
)(void), void (*parent
)(void),
170 void (*child
)(void));
172 int os_semaphore_init(os_semaphore_t
*sem
, unsigned value
);
173 int os_semaphore_destroy(os_semaphore_t
*sem
);
174 int os_semaphore_wait(os_semaphore_t
*sem
);
175 int os_semaphore_trywait(os_semaphore_t
*sem
);
176 int os_semaphore_post(os_semaphore_t
*sem
);
181 #endif /* OS_THREAD_H */