当前位置: 首页>>代码示例>>C++>>正文


C++ Task::DebugInfo方法代码示例

本文整理汇总了C++中Task::DebugInfo方法的典型用法代码示例。如果您正苦于以下问题:C++ Task::DebugInfo方法的具体用法?C++ Task::DebugInfo怎么用?C++ Task::DebugInfo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Task的用法示例。


在下文中一共展示了Task::DebugInfo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: DebugPrint

struct hostent *gethostbyaddr(const void *addr, socklen_t len, int type)
{
    Task* tk = g_Scheduler.GetCurrentTask();
    DebugPrint(dbg_hook, "task(%s) hook gethostbyaddr_r(ip=%s, type=%d). %s coroutine.",
            tk ? tk->DebugInfo() : "nil",
            inet_ntoa(*(in_addr*)addr), type,
            g_Scheduler.IsCoroutine() ? "In" : "Not in");

    static size_t s_buflen = 8192;
    static char *s_buffer = (char*)malloc(s_buflen);
    static hostent h;
    hostent *p = &h;

    int err = 0;
    size_t buflen = s_buflen;
    int res = co::gethostbyaddr_with_ares(addr, len, type, p, s_buffer, buflen,
            &p, &err);
    if (res == -1 && buflen > s_buflen) {
        s_buflen = buflen;
        s_buffer = (char*)realloc(s_buffer, s_buflen);
        res = co::gethostbyaddr_with_ares(addr, len, type, p, s_buffer, buflen,
                &p, &err);
    }

    if (res == 0) {
        return p;
    }

    h_errno = err;
    return nullptr;
}
开发者ID:HunterChen,项目名称:libgo,代码行数:31,代码来源:linux_glibc_hook.cpp

示例2: CoBlockWaitTimed

bool BlockObject::CoBlockWaitTimed(MininumTimeDurationType timeo)
{
    auto begin = std::chrono::high_resolution_clock::now();
    if (!g_Scheduler.IsCoroutine()) {
        while (!TryBlockWait() &&
				std::chrono::duration_cast<MininumTimeDurationType>
                (std::chrono::high_resolution_clock::now() - begin) < timeo)
            usleep(10 * 1000);
        return false;
    }

    std::unique_lock<LFLock> lock(lock_);
    if (wakeup_ > 0) {
        DebugPrint(dbg_syncblock, "wait immedaitely done.");
        --wakeup_;
        return true;
    }
    lock.unlock();

    Task* tk = g_Scheduler.GetLocalInfo().current_task;
    tk->block_ = this;
    tk->state_ = TaskState::sys_block;
    ++tk->block_sequence_;
    tk->block_timeout_ = timeo;
    tk->is_block_timeout_ = false;
    DebugPrint(dbg_syncblock, "wait to switch. task(%s)", tk->DebugInfo());
    g_Scheduler.CoYield();

    return !tk->is_block_timeout_;
}
开发者ID:HyEvil,项目名称:libgo,代码行数:30,代码来源:block_object.cpp

示例3: read_write_mode

static ssize_t read_write_mode(int fd, OriginF fn, const char* hook_fn_name, uint32_t event, int timeout_so, Args && ... args)
{
    Task* tk = g_Scheduler.GetCurrentTask();
    DebugPrint(dbg_hook, "task(%s) hook %s. %s coroutine.",
            tk ? tk->DebugInfo() : "nil", hook_fn_name, g_Scheduler.IsCoroutine() ? "In" : "Not in");

    FdCtxPtr fd_ctx = FdManager::getInstance().get_fd_ctx(fd);
    if (!fd_ctx || fd_ctx->closed()) {
        errno = EBADF;  // 已被close或无效的fd
        return -1;
    }

    if (!fd_ctx->is_socket())   // 非socket, 暂不HOOK. 以保障文件fd读写正常
        return fn(fd, std::forward<Args>(args)...);

    if (fd_ctx->user_nonblock())
        return fn(fd, std::forward<Args>(args)...);

    timeval tv;
    fd_ctx->get_time_o(timeout_so, &tv);
    int timeout_ms = tv.tv_sec * 1000 + tv.tv_usec / 1000;
    auto start = std::chrono::system_clock::now();

retry:
    ssize_t n = fn(fd, std::forward<Args>(args)...);
    if (n == -1 && (errno == EAGAIN || errno == EWOULDBLOCK)) {
        int poll_timeout = 0;
        if (!timeout_ms)
            poll_timeout = -1;
        else {
            int expired = std::chrono::duration_cast<std::chrono::milliseconds>(
                    std::chrono::system_clock::now() - start).count();
            if (expired > timeout_ms) {
                errno = EAGAIN;
                return -1;  // 已超时
            }

            // 剩余的等待时间
            poll_timeout = timeout_ms - expired;
        }

        pollfd pfd;
        pfd.fd = fd;
        pfd.events = event;
eintr:
        int triggers = poll(&pfd, 1, poll_timeout);
        if (-1 == triggers) {
            if (errno == EINTR) goto eintr;
            return -1;
        } else if (0 == triggers) {  // poll等待超时
            errno = EAGAIN;
            return -1;
        }

        goto retry;     // 事件触发 OR epoll惊群效应
    }

    return n;
}
开发者ID:glen-dai,项目名称:libgo,代码行数:59,代码来源:linux_glibc_hook.cpp

示例4: gethostbyname_r

int gethostbyname_r(const char *name, struct hostent *ret_h, char *buf,
        size_t buflen, struct hostent **result, int *h_errnop)
{
    Task* tk = g_Scheduler.GetCurrentTask();
    DebugPrint(dbg_hook, "task(%s) hook gethostbyname_r(name=%s, buflen=%d). %s coroutine.",
            tk ? tk->DebugInfo() : "nil", name ? name : "nil", (int)buflen,
            g_Scheduler.IsCoroutine() ? "In" : "Not in");

    return co::gethostbyname_with_ares(name, AF_INET, ret_h, buf, buflen, result, h_errnop);
}
开发者ID:HunterChen,项目名称:libgo,代码行数:10,代码来源:linux_glibc_hook.cpp

示例5: CoSwitch

void SleepWait::CoSwitch(int timeout_ms)
{
    Task *tk = g_Scheduler.GetCurrentTask();
    if (!tk) return ;

    tk->sleep_ms_ = timeout_ms;
    tk->state_ = TaskState::sleep;

    DebugPrint(dbg_sleepblock, "task(%s) will sleep %d ms", tk->DebugInfo(), tk->sleep_ms_);
    g_Scheduler.CoYield();
}
开发者ID:StarXing,项目名称:libgo,代码行数:11,代码来源:sleep_wait.cpp

示例6: gethostbyaddr_r

int gethostbyaddr_r(const void *addr, socklen_t len, int type,
        struct hostent *ret, char *buf, size_t buflen,
        struct hostent **result, int *h_errnop)
{
    Task* tk = g_Scheduler.GetCurrentTask();
    DebugPrint(dbg_hook, "task(%s) hook gethostbyaddr_r(ip=%s, type=%d, buflen=%d). %s coroutine.",
            tk ? tk->DebugInfo() : "nil",
            inet_ntoa(*(in_addr*)addr), type, (int)buflen,
            g_Scheduler.IsCoroutine() ? "In" : "Not in");

    return co::gethostbyaddr_with_ares(addr, len, type, ret, buf, buflen, result, h_errnop);
}
开发者ID:HunterChen,项目名称:libgo,代码行数:12,代码来源:linux_glibc_hook.cpp

示例7: CoYield

void Processer::CoYield()
{
    Task *tk = GetCurrentTask();
    assert(tk);
    tk->proc_ = this;

    DebugPrint(dbg_yield, "yield task(%s) state=%d", tk->DebugInfo(), (int)tk->state_);
    ++tk->yield_count_;
    if (!tk->SwapOut()) {
        fprintf(stderr, "swapcontext error:%s\n", strerror(errno));
        ThrowError(eCoErrorCode::ec_yield_failed);
    }
}
开发者ID:HunterChen,项目名称:libgo,代码行数:13,代码来源:processer.cpp

示例8: Yield

void Processer::Yield(ThreadLocalInfo &info)
{
    Task *tk = info.current_task;
    if (!tk) return ;

    DebugPrint(dbg_yield, "yield task(%s) state=%d", tk->DebugInfo(), tk->state_);
    ++tk->yield_count_;
    SaveStack(tk);
    int ret = swapcontext(&tk->ctx_, &info.scheduler);
    if (ret) {
        fprintf(stderr, "swapcontext error:%s\n", strerror(errno));
        ThrowError(eCoErrorCode::ec_yield_failed);
    }
}
开发者ID:Gd58,项目名称:cpp_features,代码行数:14,代码来源:processer.cpp

示例9: connect

int connect(int fd, const struct sockaddr *addr, socklen_t addrlen)
{
    Task* tk = g_Scheduler.GetCurrentTask();
    DebugPrint(dbg_hook, "task(%s) hook connect. %s coroutine.",
            tk ? tk->DebugInfo() : "nil", g_Scheduler.IsCoroutine() ? "In" : "Not in");

    if (!tk)
        return connect_f(fd, addr, addrlen);

    FdCtxPtr fd_ctx = FdManager::getInstance().get_fd_ctx(fd);
    if (!fd_ctx || fd_ctx->closed()) {
        errno = EBADF;
        return -1;
    }

    if (fd_ctx->user_nonblock())
        return connect_f(fd, addr, addrlen);

    int n = connect_f(fd, addr, addrlen);
    if (n == 0) {
        DebugPrint(dbg_hook, "continue task(%s) connect completed immediately. fd=%d",
                g_Scheduler.GetCurrentTaskDebugInfo(), fd);
        return 0;
    } else if (n != -1 || errno != EINPROGRESS) {
        return n;
    }

    // EINPROGRESS. use poll for wait connect complete.
    pollfd pfd;
    pfd.fd = fd;
    pfd.events = POLLOUT;
    int poll_res = poll(&pfd, 1, s_connect_timeout);
    if (poll_res <= 0 || pfd.revents != POLLOUT) {
        errno = ETIMEDOUT;
        return -1;
    }

    int error = 0;
    socklen_t len = sizeof(int);
    if (-1 == getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len))
        return -1;

    if (!error)
        return 0;
    else {
        errno = error;
        return -1;
    }
}
开发者ID:HunterChen,项目名称:libgo,代码行数:49,代码来源:linux_glibc_hook.cpp

示例10: sleep

unsigned int sleep(unsigned int seconds)
{
    if (!sleep_f) coroutine_hook_init();

    Task* tk = g_Scheduler.GetCurrentTask();
    DebugPrint(dbg_hook, "task(%s) hook sleep(seconds=%u). %s coroutine.",
            tk ? tk->DebugInfo() : "nil", seconds,
            g_Scheduler.IsCoroutine() ? "In" : "Not in");

    if (!tk)
        return sleep_f(seconds);

    int timeout_ms = seconds * 1000;
    g_Scheduler.SleepSwitch(timeout_ms);
    return 0;
}
开发者ID:HunterChen,项目名称:libgo,代码行数:16,代码来源:linux_glibc_hook.cpp

示例11: nanosleep

int nanosleep(const struct timespec *req, struct timespec *rem)
{
    if (!nanosleep_f) coroutine_hook_init();

    Task* tk = g_Scheduler.GetCurrentTask();
    int timeout_ms = req->tv_sec * 1000 + req->tv_nsec / 1000000;
    DebugPrint(dbg_hook, "task(%s) hook nanosleep(milliseconds=%d). %s coroutine.",
            tk ? tk->DebugInfo() : "nil", timeout_ms,
            g_Scheduler.IsCoroutine() ? "In" : "Not in");

    if (!tk)
        return nanosleep_f(req, rem);

    g_Scheduler.SleepSwitch(timeout_ms);
    return 0;
}
开发者ID:HunterChen,项目名称:libgo,代码行数:16,代码来源:linux_glibc_hook.cpp

示例12: usleep

int usleep(useconds_t usec)
{
    if (!usleep_f) coroutine_hook_init();

    Task* tk = g_Scheduler.GetCurrentTask();
    DebugPrint(dbg_hook, "task(%s) hook usleep(microseconds=%u). %s coroutine.",
            tk ? tk->DebugInfo() : "nil", usec,
            g_Scheduler.IsCoroutine() ? "In" : "Not in");

    if (!tk)
        return usleep_f(usec);

    int timeout_ms = usec / 1000;
    g_Scheduler.SleepSwitch(timeout_ms);
    return 0;

}
开发者ID:HunterChen,项目名称:libgo,代码行数:17,代码来源:linux_glibc_hook.cpp

示例13: Wakeup

bool BlockObject::Wakeup()
{
    std::unique_lock<LFLock> lock(lock_);
    Task* tk = wait_queue_.pop();
    if (!tk) {
        if (wakeup_ >= max_wakeup_) {
            DebugPrint(dbg_syncblock, "wakeup failed.");
            return false;
        }

        ++wakeup_;
        DebugPrint(dbg_syncblock, "wakeup to %lu.", (long unsigned)wakeup_);
        return true;
    }

    g_Scheduler.AddTaskRunnable(tk);
    DebugPrint(dbg_syncblock, "wakeup task(%s).", tk->DebugInfo());
    return true;
}
开发者ID:Gd58,项目名称:cpp_features,代码行数:19,代码来源:block_object.cpp

示例14: CoSwitch

void IoWait::CoSwitch(std::vector<FdStruct> && fdsts, int timeout_ms)
{
    Task* tk = g_Scheduler.GetCurrentTask();
    if (!tk) return ;

    uint32_t id = ++tk->GetIoWaitData().io_block_id_;
    tk->state_ = TaskState::io_block;
    tk->GetIoWaitData().wait_successful_ = 0;
    tk->GetIoWaitData().io_block_timeout_ = timeout_ms;
    tk->GetIoWaitData().io_block_timer_.reset();
    tk->GetIoWaitData().wait_fds_.swap(fdsts);
    for (auto &fdst : tk->GetIoWaitData().wait_fds_) {
        fdst.epoll_ptr.tk = tk;
        fdst.epoll_ptr.io_block_id = id;
    }

    DebugPrint(dbg_ioblock, "task(%s) CoSwitch id=%d, nfds=%d, timeout=%d",
            tk->DebugInfo(), id, (int)fdsts.size(), timeout_ms);
    g_Scheduler.CoYield();
}
开发者ID:ceasar09,项目名称:libgo,代码行数:20,代码来源:io_wait.cpp

示例15: CoBlockWait

void BlockObject::CoBlockWait()
{
    if (!g_Scheduler.IsCoroutine()) {
        while (!TryBlockWait()) usleep(10 * 1000);
        return ;
    }

    std::unique_lock<LFLock> lock(lock_);
    if (wakeup_ > 0) {
        DebugPrint(dbg_syncblock, "wait immedaitely done.");
        --wakeup_;
        return ;
    }

    Task* tk = g_Scheduler.GetLocalInfo().current_task;
    tk->block_ = this;
    tk->state_ = TaskState::sys_block;
    lock.unlock();
    DebugPrint(dbg_syncblock, "wait to switch. task(%s)", tk->DebugInfo());
    g_Scheduler.Yield();
}
开发者ID:Gd58,项目名称:cpp_features,代码行数:21,代码来源:block_object.cpp


注:本文中的Task::DebugInfo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。