OpenCores
URL https://opencores.org/ocsvn/riscv_vhdl/riscv_vhdl/trunk

Subversion Repositories riscv_vhdl

[/] [riscv_vhdl/] [trunk/] [debugger/] [src/] [common/] [coreservices/] [ithread.h] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 sergeykhbr
/**
2
 * @file
3
 * @copyright  Copyright 2016 GNSS Sensor Ltd. All right reserved.
4
 * @author     Sergey Khabarov - sergeykhbr@gmail.com
5
 * @brief      Thread interface declaration.
6
 */
7
 
8
#ifndef __DEBUGGER_ITHREAD_H__
9
#define __DEBUGGER_ITHREAD_H__
10
 
11
#include <iface.h>
12
#include <api_core.h>
13
 
14
namespace debugger {
15
 
16
static const char *const IFACE_THREAD = "IThread";
17
 
18
class IThread : public IFace {
19
 public:
20
    IThread() : IFace(IFACE_THREAD) {
21
        AttributeType t1;
22
        RISCV_generate_name(&t1);
23
        RISCV_event_create(&loopEnable_, t1.to_string());
24
        threadInit_.Handle = 0;
25
    }
26
 
27
    /** create and start seperate thread */
28
    virtual bool run() {
29
        threadInit_.func = reinterpret_cast<lib_thread_func>(runThread);
30
        threadInit_.args = this;
31
        RISCV_thread_create(&threadInit_);
32
 
33
        if (threadInit_.Handle) {
34
            RISCV_event_set(&loopEnable_);
35
        }
36
        return loopEnable_.state;
37
    }
38
 
39
    /** @brief Stop and join thread */
40
    virtual void stop() {
41
        RISCV_event_clear(&loopEnable_);
42
        if (threadInit_.Handle) {
43
            RISCV_thread_join(threadInit_.Handle, 50000);
44
        }
45
        threadInit_.Handle = 0;
46
    }
47
 
48
    /** check thread status */
49
    virtual bool isEnabled() { return loopEnable_.state; }
50
 
51
    /** Pass data from the parent thread */
52
    virtual void setExtArgument(void *args) {}
53
 
54
 protected:
55
    /** working cycle function */
56
    virtual void busyLoop() =0;
57
 
58
    static void runThread(void *arg) {
59
        reinterpret_cast<IThread *>(arg)->busyLoop();
60
    }
61
 
62
 protected:
63
    event_def loopEnable_;
64
    LibThreadType threadInit_;
65
};
66
 
67
}  // namespace debugger
68
 
69
#endif  // __DEBUGGER_ITHREAD_H__

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.