/**
 * @file ntsync.h
 * @brief NTSync userspace library header
 *
 * MVGAL - Multi-Vendor GPU Aggregation Layer for Linux
 *
 * SPDX-License-Identifier: MIT
 */

#ifndef MVGAL_NTSYNC_H
#define MVGAL_NTSYNC_H

#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

/**
 * @brief Initialize NTSync library
 * @return 0 on success, -1 on failure
 */
int ntsync_init(void);

/**
 * @brief Cleanup NTSync library
 */
void ntsync_fini(void);

/**
 * @brief Create an event object
 * @param handle Output handle
 * @param initial_state Non-zero for initially signaled
 * @param auto_reset Non-zero for auto-reset event
 * @return 0 on success, -1 on failure
 */
int ntsync_create_event(int *handle, int initial_state, int auto_reset);

/**
 * @brief Create a semaphore object
 * @param handle Output handle
 * @param initial_count Initial count
 * @param max_count Maximum count
 * @return 0 on success, -1 on failure
 */
int ntsync_create_semaphore(int *handle, int initial_count, int max_count);

/**
 * @brief Create a mutex object
 * @param handle Output handle
 * @return 0 on success, -1 on failure
 */
int ntsync_create_mutex(int *handle);

/**
 * @brief Wait on an object
 * @param handle Object handle
 * @param timeout_ns Timeout in nanoseconds (0 = wait forever)
 * @return 0 on success, -1 on timeout/error
 */
int ntsync_wait(int handle, uint64_t timeout_ns);

/**
 * @brief Signal an event
 * @param handle Object handle
 * @return 0 on success, -1 on failure
 */
int ntsync_signal(int handle);

/**
 * @brief Release semaphore count
 * @param handle Object handle
 * @param count Count to release
 * @return 0 on success, -1 on failure
 */
int ntsync_release_semaphore(int handle, int count);

/**
 * @brief Release mutex (unlock)
 * @param handle Object handle
 * @return 0 on success, -1 on failure
 */
int ntsync_release_mutex(int handle);

/**
 * @brief Create a cross-GPU fence
 * @param handle Output handle
 * @param gpu_index GPU index for the fence
 * @return 0 on success, -1 on failure
 */
int ntsync_create_fence(int *handle, uint32_t gpu_index);

/**
 * @brief Close an object handle
 * @param handle Object handle
 * @return 0 on success, -1 on failure
 */
int ntsync_close(int handle);

#ifdef __cplusplus
}
#endif

#endif /* MVGAL_NTSYNC_H */