/**
|
/**
|
* @file
|
* @file
|
* @copyright Copyright 2016 GNSS Sensor Ltd. All right reserved.
|
* @copyright Copyright 2016 GNSS Sensor Ltd. All right reserved.
|
* @author Sergey Khabarov - sergeykhbr@gmail.com
|
* @author Sergey Khabarov - sergeykhbr@gmail.com
|
* @brief Thread interface declaration.
|
* @brief Thread interface declaration.
|
*/
|
*/
|
|
|
#ifndef __DEBUGGER_ITHREAD_H__
|
#ifndef __DEBUGGER_ITHREAD_H__
|
#define __DEBUGGER_ITHREAD_H__
|
#define __DEBUGGER_ITHREAD_H__
|
|
|
#include "iface.h"
|
#include <iface.h>
|
#include "api_core.h"
|
#include <api_core.h>
|
|
|
namespace debugger {
|
namespace debugger {
|
|
|
static const char *const IFACE_THREAD = "IThread";
|
static const char *const IFACE_THREAD = "IThread";
|
|
|
class IThread : public IFace {
|
class IThread : public IFace {
|
public:
|
public:
|
IThread() : IFace(IFACE_THREAD) {
|
IThread() : IFace(IFACE_THREAD) {
|
AttributeType t1;
|
AttributeType t1;
|
RISCV_generate_name(&t1);
|
RISCV_generate_name(&t1);
|
RISCV_event_create(&loopEnable_, t1.to_string());
|
RISCV_event_create(&loopEnable_, t1.to_string());
|
threadInit_.Handle = 0;
|
threadInit_.Handle = 0;
|
}
|
}
|
|
|
/** create and start seperate thread */
|
/** create and start seperate thread */
|
virtual bool run() {
|
virtual bool run() {
|
threadInit_.func = reinterpret_cast<lib_thread_func>(runThread);
|
threadInit_.func = reinterpret_cast<lib_thread_func>(runThread);
|
threadInit_.args = this;
|
threadInit_.args = this;
|
RISCV_thread_create(&threadInit_);
|
RISCV_thread_create(&threadInit_);
|
|
|
if (threadInit_.Handle) {
|
if (threadInit_.Handle) {
|
RISCV_event_set(&loopEnable_);
|
RISCV_event_set(&loopEnable_);
|
}
|
}
|
return loopEnable_.state;
|
return loopEnable_.state;
|
}
|
}
|
|
|
/** @brief Stop and join thread */
|
/** @brief Stop and join thread */
|
virtual void stop() {
|
virtual void stop() {
|
RISCV_event_clear(&loopEnable_);
|
RISCV_event_clear(&loopEnable_);
|
if (threadInit_.Handle) {
|
if (threadInit_.Handle) {
|
RISCV_thread_join(threadInit_.Handle, 50000);
|
RISCV_thread_join(threadInit_.Handle, 50000);
|
}
|
}
|
threadInit_.Handle = 0;
|
threadInit_.Handle = 0;
|
}
|
}
|
|
|
/** check thread status */
|
/** check thread status */
|
virtual bool isEnabled() { return loopEnable_.state; }
|
virtual bool isEnabled() { return loopEnable_.state; }
|
|
|
|
/** Pass data from the parent thread */
|
|
virtual void setExtArgument(void *args) {}
|
|
|
protected:
|
protected:
|
/** working cycle function */
|
/** working cycle function */
|
virtual void busyLoop() =0;
|
virtual void busyLoop() =0;
|
|
|
static void runThread(void *arg) {
|
static void runThread(void *arg) {
|
reinterpret_cast<IThread *>(arg)->busyLoop();
|
reinterpret_cast<IThread *>(arg)->busyLoop();
|
}
|
}
|
|
|
protected:
|
protected:
|
event_def loopEnable_;
|
event_def loopEnable_;
|
LibThreadType threadInit_;
|
LibThreadType threadInit_;
|
};
|
};
|
|
|
} // namespace debugger
|
} // namespace debugger
|
|
|
#endif // __DEBUGGER_ITHREAD_H__
|
#endif // __DEBUGGER_ITHREAD_H__
|
|
|