#ifndef SWIFT_THREAD_SEM_H
#define SWIFT_THREAD_SEM_H

#include <swift/atomic.h>
#include <swift/stdlib.h>
#include <swift/time.h>

#include <swift/thread/api.h>

typedef struct swift_sem_t swift_sem_t;

struct swift_sem_t {
	swift_ref_t ref;
	swift_atomic_t count;
	void *data;
	bool on_heap;
};

SWIFT_THREAD_API bool swift_init_sem(swift_sem_t *sem, int count);
SWIFT_THREAD_API void swift_term_sem(swift_sem_t *sem);
SWIFT_THREAD_API swift_sem_t *swift_new_sem(int count);
SWIFT_THREAD_API void swift_del_sem(swift_sem_t *sem);
SWIFT_THREAD_API swift_sem_t *swift_copy_sem(swift_sem_t *sem);
SWIFT_THREAD_API bool swift_sem_wait(swift_sem_t *sem);
SWIFT_THREAD_API bool swift_sem_try_wait(swift_sem_t *sem);
SWIFT_THREAD_API bool swift_sem_timed_wait(swift_sem_t *sem, swift_time_t time);
SWIFT_THREAD_API bool swift_sem_signal(swift_sem_t *sem);
SWIFT_THREAD_API bool swift_sem_get_count(swift_sem_t *sem, int *count);

#endif /* SWIFT_THREAD_SEM_H */
