Permalink
Browse files

Fiber, feat: support Fiber.id.

  • Loading branch information...
xicilion committed Oct 14, 2017
1 parent 41e402b commit c3092d04761c0094193c60fa6bcc45080deace99
View
@@ -41,6 +41,7 @@ class JSFiber : public Fiber_base,
, m_c_entry_fp_(NULL)
, m_handler_(NULL)
{
m_id = holder()->m_fid++;
}
~JSFiber()
@@ -53,6 +54,7 @@ class JSFiber : public Fiber_base,
public:
// Fiber_base
virtual result_t join();
virtual result_t get_id(int64_t& retVal);
virtual result_t get_stack(exlib::string& retVal);
virtual result_t get_caller(obj_ptr<Fiber_base>& retVal);
@@ -137,6 +139,7 @@ class JSFiber : public Fiber_base,
void* m_handler_;
private:
int64_t m_id;
v8::Global<v8::Function> m_func;
QuickArray<v8::Global<v8::Value>> m_argv;
v8::Global<v8::Value> m_result;
View
@@ -112,15 +112,15 @@ class Isolate : public exlib::linkitem {
exlib::atomic m_pendding;
int64_t m_fid;
int64_t m_flake_tm;
int32_t m_flake_host;
int32_t m_flake_count;
int32_t m_loglevel;
int32_t m_defaultMaxListeners;
bool m_interrupt;
};
} /* namespace fibjs */
View
@@ -22,6 +22,7 @@ class Fiber_base : public object_base {
public:
// Fiber_base
virtual result_t join() = 0;
virtual result_t get_id(int64_t& retVal) = 0;
virtual result_t get_caller(obj_ptr<Fiber_base>& retVal) = 0;
virtual result_t get_stack(exlib::string& retVal) = 0;
@@ -38,6 +39,7 @@ class Fiber_base : public object_base {
public:
static void s_join(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_get_id(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& args);
static void s_get_caller(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& args);
static void s_get_stack(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& args);
};
@@ -51,6 +53,7 @@ inline ClassInfo& Fiber_base::class_info()
};
static ClassData::ClassProperty s_property[] = {
{ "id", s_get_id, block_set, false },
{ "caller", s_get_caller, block_set, false },
{ "stack", s_get_stack, block_set, false }
};
@@ -78,6 +81,19 @@ inline void Fiber_base::s_join(const v8::FunctionCallbackInfo<v8::Value>& args)
METHOD_VOID();
}
inline void Fiber_base::s_get_id(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& args)
{
int64_t vr;
METHOD_NAME("Fiber.id");
METHOD_INSTANCE(Fiber_base);
PROPERTY_ENTER();
hr = pInst->get_id(vr);
METHOD_RETURN();
}
inline void Fiber_base::s_get_caller(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& args)
{
obj_ptr<Fiber_base> vr;
@@ -101,12 +101,12 @@ Isolate::Isolate(exlib::string fname)
, m_test(NULL)
, m_currentFibers(0)
, m_idleFibers(0)
, m_fid(1)
, m_flake_tm(0)
, m_flake_host(0)
, m_flake_count(0)
, m_loglevel(console_base::_NOTSET)
, m_defaultMaxListeners(10)
, m_interrupt(false)
{
m_fname = fname;
@@ -139,6 +139,12 @@ save_method_name::~save_method_name()
m_fb->m_native_name = m_name;
}
result_t JSFiber::get_id(int64_t& retVal)
{
retVal = m_id;
return 0;
}
result_t JSFiber::get_stack(exlib::string& retVal)
{
if (JSFiber::current() == this)
View
@@ -51,6 +51,9 @@ interface Fiber : object
/*! @brief 等待纤程结束 */
join();
/*! @brief 查询纤程的唯一 id */
readonly Long id;
/*! @brief 查询纤程的调用纤程 */
readonly Fiber caller;

0 comments on commit c3092d0

Please sign in to comment.