acl/lib_fiber/cpp/include/fiber/fiber.hpp

99 lines
1.8 KiB
C++
Raw Normal View History

2016-06-24 10:39:05 +08:00
#pragma once
struct FIBER;
namespace acl {
/**
*
*/
class fiber
{
public:
fiber(void);
virtual ~fiber(void);
/**
*
* @param stack_size {size_t}
*/
void start(size_t stack_size = 64000);
/**
* ID
* @return {int}
*/
int get_id(void) const;
/**
* ID
*/
static int self(void);
2016-06-30 22:20:30 +08:00
/**
* API
* return {int}
*/
int get_errno(void) const;
/**
*
* @param errnum {int}
*/
void set_errno(int errnum);
2016-06-24 10:39:05 +08:00
/**
*
*/
2016-06-30 22:20:30 +08:00
static void schedule(void);
/**
*
*/
static void stop(void);
public:
/**
* ()
*/
void yield(void);
/**
*
*/
void switch_to_next(void);
/**
*
* @param f {fiber&}
*/
static void ready(fiber& f);
/**
* C
* @return {FIBER *}
*/
FIBER *get_fiber(void) const;
/**
* 线线 hook API
* hook API
* @param on {bool}
*/
static void hook_api(bool on);
2016-06-24 10:39:05 +08:00
protected:
/**
* start
*
*/
virtual void run(void) = 0;
private:
FIBER *f_;
static void fiber_callback(FIBER *f, void *ctx);
};
} // namespace acl