修改future-promise接口,准备增加性能调试功能。
This commit is contained in:
@@ -4,10 +4,15 @@
|
||||
|
||||
#include <tfe_future.h>
|
||||
#include <tfe_utils.h>
|
||||
|
||||
struct _future_promise_debug
|
||||
{
|
||||
struct timeval create_time;
|
||||
};
|
||||
struct future
|
||||
{
|
||||
void * user;
|
||||
char symbol[TFE_SYMBOL_MAX];
|
||||
struct timeval timeout;
|
||||
future_success_cb * cb_success;
|
||||
future_failed_cb * cb_failed;
|
||||
};
|
||||
@@ -16,28 +21,37 @@ struct promise
|
||||
{
|
||||
struct future f;
|
||||
void * ctx;
|
||||
int has_timeout;
|
||||
promise_ctx_destroy_cb * cb_ctx_destroy;
|
||||
struct _future_promise_debug __debug;
|
||||
};
|
||||
|
||||
struct future * promise_to_future(struct promise * p)
|
||||
void future_promise_library_init(void)
|
||||
{
|
||||
return &p->f;
|
||||
return;
|
||||
}
|
||||
|
||||
struct promise * future_to_promise(struct future * f)
|
||||
{
|
||||
{
|
||||
return (struct promise *) f;
|
||||
}
|
||||
|
||||
struct future * future_create(future_success_cb * cb_success, future_failed_cb * cb_failed, void * user)
|
||||
struct future * future_create(const char* symbol, future_success_cb * cb_success, future_failed_cb * cb_failed, void * user)
|
||||
{
|
||||
struct promise * p = ALLOC(struct promise, 1);
|
||||
p->f.user = user;
|
||||
p->f.cb_success = cb_success;
|
||||
p->f.cb_failed = cb_failed;
|
||||
strncpy(p->f.symbol,symbol,sizeof(p->f.symbol));
|
||||
gettimeofday(&p->__debug.create_time, NULL);
|
||||
return &p->f;
|
||||
}
|
||||
|
||||
void future_set_timeout(struct future * f, struct timeval timeout)
|
||||
{
|
||||
struct promise * p=(struct promise *) f;
|
||||
f->timeout=timeout;
|
||||
p->has_timeout=1;
|
||||
return;
|
||||
}
|
||||
void future_destroy(struct future * f)
|
||||
{
|
||||
struct promise * promise = future_to_promise(f);
|
||||
@@ -81,3 +95,18 @@ void * promise_dettach_ctx(struct promise * p)
|
||||
p->cb_ctx_destroy = NULL;
|
||||
return ctx;
|
||||
}
|
||||
/**
|
||||
Get timeout from a promise which is set in future.
|
||||
|
||||
@param timeout Output.
|
||||
@return 1 on a meaningful timeout, or 0 on no timeout.
|
||||
*/
|
||||
int promise_get_timeout(struct promise * p, struct timeval * timeout)
|
||||
{
|
||||
if(p->has_timeout)
|
||||
{
|
||||
*timeout=p->f.timeout;
|
||||
}
|
||||
return p->has_timeout;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user