Sha256: 295dcd1d4a0abf3f0951fcdf92380c7c747826149d2d28888c7dc12626bb3bea

Contents?: true

Size: 833 Bytes

Versions: 9

Compression:

Stored size: 833 Bytes

Contents

#ifndef LIMONP_THREAD_HPP
#define LIMONP_THREAD_HPP

#include "Logging.hpp"
#include "NonCopyable.hpp"

namespace limonp {

class IThread: NonCopyable {
 public:
  IThread(): isStarted(false), isJoined(false) {
  }
  virtual ~IThread() {
    if(isStarted && !isJoined) {
      XCHECK(!pthread_detach(thread_));
    }
  };

  virtual void Run() = 0;
  void Start() {
    XCHECK(!isStarted);
    XCHECK(!pthread_create(&thread_, NULL, Worker, this));
    isStarted = true;
  }
  void Join() {
    XCHECK(!isJoined);
    XCHECK(!pthread_join(thread_, NULL));
    isJoined = true;
  }
 private:
  static void * Worker(void * data) {
    IThread * ptr = (IThread* ) data;
    ptr->Run();
    return NULL;
  }

  pthread_t thread_;
  bool isStarted;
  bool isJoined;
}; // class IThread

} // namespace limonp

#endif // LIMONP_THREAD_HPP

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
cppjieba_rb-0.4.2 ext/cppjieba/deps/limonp/Thread.hpp
cppjieba_rb-0.4.1 ext/cppjieba/deps/limonp/Thread.hpp
jieba-rb-5.0.0 ext/cppjieba/deps/limonp/Thread.hpp
cppjieba_rb-0.3.3 ext/cppjieba/deps/limonp/Thread.hpp
cppjieba_rb-0.3.1 ext/cppjieba/deps/limonp/Thread.hpp
cppjieba_rb-0.3.0 ext/cppjieba/deps/limonp/Thread.hpp
cppjieba_rb-0.2.3 ext/cppjieba/deps/limonp/Thread.hpp
cppjieba_rb-0.2.2 ext/cppjieba/deps/limonp/Thread.hpp
cppjieba_rb-0.2.1 ext/cppjieba/deps/limonp/Thread.hpp