#ifndef SWIFT_THREAD_MUTEX_H
#define SWIFT_THREAD_MUTEX_H

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

#include <swift/thread/api.h>

typedef unsigned long swift_thread_id_t;
typedef struct swift_mutex_t swift_mutex_t;

enum swift_mutex_flags_t {
	SWIFT_MUTEX_RECURSIVE = (1 << 0),
};

struct swift_mutex_t {
	swift_ref_t ref;
	void *data;
	swift_thread_id_t owner_id;
	unsigned int flags, count;
	bool on_heap;
};

SWIFT_THREAD_API bool swift_init_mutex(swift_mutex_t *mutex,
	unsigned int flags);
SWIFT_THREAD_API void swift_term_mutex(swift_mutex_t *mutex);
SWIFT_THREAD_API swift_mutex_t *swift_new_mutex(unsigned int flags);
SWIFT_THREAD_API void swift_del_mutex(swift_mutex_t *mutex);
SWIFT_THREAD_API swift_mutex_t *swift_copy_mutex(swift_mutex_t *mutex);
SWIFT_THREAD_API bool swift_mutex_lock(swift_mutex_t *mutex);
SWIFT_THREAD_API bool swift_mutex_try_lock(swift_mutex_t *mutex);
SWIFT_THREAD_API bool swift_mutex_timed_lock(swift_mutex_t *mutex,
	swift_time_t time);
SWIFT_THREAD_API bool swift_mutex_unlock(swift_mutex_t *mutex);

#endif /* SWIFT_THREAD_MUTEX_H */
