threadimpl.h

来自「一个语言识别引擎」· C头文件 代码 · 共 73 行

H
73
字号
// -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-

/*
 * Copyright (C) 2006 Paul Fitzpatrick
 * CopyPolicy: Released under the terms of the GNU GPL v2.0.
 *
 */

#ifndef _YARP2_THREADIMPL_
#define _YARP2_THREADIMPL_

#include <yarp/Runnable.h>
#include <yarp/SemaphoreImpl.h>

#include <ace/Thread.h>


namespace yarp {
    class ThreadImpl;
}

/**
 * An abstraction for a thread of execution.
 */
class yarp::ThreadImpl : public Runnable {
public:
    ThreadImpl();
    ThreadImpl(Runnable *target);

    virtual ~ThreadImpl();

    int join(double seconds = -1);
    virtual void run();
    virtual void close();

    // should throw if no success
    virtual bool start();

    bool isClosing();
    
    bool isRunning() {
        return active;
    }

    virtual void beforeStart();
    virtual void afterStart(bool success);

    // call before start
    void setOptions(int stackSize = 0);

    static int getCount();

    // won't be public for long...
    static void changeCount(int delta);

    // get a unique key
    long int getKey();

private:
    int stackSize;
    ACE_hthread_t hid;
    ACE_thread_t id;
    bool active;
    bool closing;
    Runnable *delegate;

    static int threadCount;
    static SemaphoreImpl threadMutex;
};

#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?