35 #ifndef LELY_NO_ATOMICS 36 atomic_fetch_add_explicit(
37 &handle->
ref, 1, memory_order_relaxed);
38 #elif !defined(LELY_NO_THREADS) && defined(_WIN32) 39 InterlockedIncrementNoFence(&handle->
ref);
52 #ifndef LELY_NO_ATOMICS 53 if (atomic_fetch_sub_explicit(&handle->
ref, 1, memory_order_release)
55 atomic_thread_fence(memory_order_acquire);
56 #elif !defined(LELY_NO_THREADS) && defined(_WIN32) 57 if (!InterlockedDecrementRelease(&handle->
ref)) {
60 if (handle->
ref-- == 1) {
69 #ifndef LELY_NO_ATOMICS 89 #ifndef LELY_NO_ATOMICS 90 atomic_init(&handle->
ref, 0);
94 handle->
fd = INVALID_HANDLE_VALUE;
96 #ifndef LELY_NO_THREADS 109 assert(handle->
vtab);
119 #ifndef LELY_NO_THREADS 136 #ifndef LELY_NO_THREADS 154 #endif // !LELY_NO_THREADS size_t ref
The reference count.
void io_handle_fini(struct io_handle *handle)
Finalizes an I/O device handle by invoking its fini method, if available.
void mtx_destroy(mtx_t *mtx)
Releases any resources used by the mutex at mtx.
void io_handle_unlock(struct io_handle *handle)
Unlocks a locked I/O device handle.
A mutex type that supports neither timeout nor test and return.
int mtx_unlock(mtx_t *mtx)
Unlocks the mutex at mtx.
void set_errc(int errc)
Sets the current (thread-specific) native error code to errc.
This is the internal header file of the I/O handle declarations.
int mtx_lock(mtx_t *mtx)
Blocks until it locks the mutex at mtx.
This header file is part of the utilities library; it contains the native and platform-independent er...
#define IO_HANDLE_ERROR
The value of an invalid I/O device handle.
const struct io_handle_vtab * vtab
A pointer to the virtual table.
The virtual table of an I/O device handle.
size_t size
The size (in bytes) of the handle struct.
int io_handle_unique(io_handle_t handle)
Returns 1 if there is only a single reference to the specified I/O device handle, and 0 otherwise...
int errno2c(int errnum)
Transforms a standard C error number to a native error code.
void io_handle_release(io_handle_t handle)
Decrements the reference count of an I/O device handle.
This is the internal header file of the I/O library.
int flags
The I/O device flags (any combination of IO_FLAG_NO_CLOSE and IO_FLAG_NONBLOCK).
io_handle_t io_handle_acquire(io_handle_t handle)
Increments the reference count of an I/O device handle.
void io_handle_destroy(struct io_handle *handle)
Destroys an I/O device handle.
mtx_t mtx
The mutex protecting flags (and other device-specific fields).
int fd
The native file descriptor.
This header file is part of the C11 and POSIX compatibility library; it includes <stdlib.h> and defines any missing functionality.
struct io_handle * io_handle_alloc(const struct io_handle_vtab *vtab)
Allocates a new I/O device handle from a virtual table.
void io_handle_lock(struct io_handle *handle)
Locks an unlocked I/O device handle, so the flags (and other device-specific fields) can safely be ac...
void io_handle_free(struct io_handle *handle)
Frees an I/O device handle.
void(* fini)(struct io_handle *handle)
A pointer to the fini method.
int mtx_init(mtx_t *mtx, int type)
Creates a mutex object with properties indicated by type, which must have one of the four values: ...