#ifndef CONTEXT_SWITCHER_FCONTEXT_H_
#define CONTEXT_SWITCHER_FCONTEXT_H_

#include <cstdint>
#include <cstddef>

/**
 * Low level bindings to the two assembly functions used to switch context.
 * Can be used standalone to build new control structures, but should be handled with care.
 * This is the API to the fcontext (boost.context assembly).
 */

namespace context_switcher {
namespace fcontext {

using continuation_t = void *;
using stack_pointer_t = char *;

struct transfer_t {
  continuation_t continuation;
  void *data;
};

#ifdef THREAD_SANITIZER
struct fiber_data {
  void *old_fiber;
  void *data;
  bool finished;
};
#endif

using callback_t = void (*)(transfer_t);

extern "C" {
transfer_t jump_fcontext(continuation_t cont, void *data);
continuation_t make_fcontext(stack_pointer_t sp, size_t size, callback_t corofn);

transfer_t ontop_fcontext(continuation_t cont, void *data, transfer_t(*fn)(transfer_t));
}

}
}

#endif //CONTEXT_SWITCHER_FCONTEXT_H_
