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

Subversion Repositories riscv_vhdl

[/] [riscv_vhdl/] [trunk/] [debugger/] [src/] [common/] [async_tqueue.cpp] - Blame information for rev 3

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 sergeykhbr
/**
2
 * @file
3
 * @copyright  Copyright 2016 GNSS Sensor Ltd. All right reserved.
4
 * @author     Sergey Khabarov - sergeykhbr@gmail.com
5
 * @brief      Asynchronous queue with time markers.
6
 */
7
 
8
#include "api_utils.h"
9
#include "async_tqueue.h"
10
 
11
namespace debugger {
12
 
13
AsyncTQueueType::AsyncTQueueType() {
14
    preLen_ = 0;
15
    curLen_ = 0;
16
    stepPreQueued_.make_list(0);
17
    stepQueue_.make_list(16);   /** it will be auto reallocated if needed */
18
    item_.make_list(Queue_Total);
19
    RISCV_mutex_init(&mutex_);
20
}
21
 
22
AsyncTQueueType::~AsyncTQueueType() {
23
    RISCV_mutex_destroy(&mutex_);
24
}
25
 
26
void AsyncTQueueType::put(uint64_t time, IFace *cb) {
27
    RISCV_mutex_lock(&mutex_);
28
    item_[Queue_Time].make_uint64(time);
29
    item_[Queue_IFace].make_iface(cb);
30
    if (preLen_ == stepPreQueued_.size()) {
31
        unsigned new_sz = 2 * stepPreQueued_.size();
32
        if (new_sz == 0) {
33
            new_sz = 1;
34
        }
35
        stepPreQueued_.realloc_list(new_sz);
36
    }
37
    stepPreQueued_[preLen_].attr_free();
38
    stepPreQueued_[preLen_] = item_;
39
    preLen_++;
40
    RISCV_mutex_unlock(&mutex_);
41
}
42
void AsyncTQueueType::pushPreQueued() {
43
    if (preLen_ == 0) {
44
        return;
45
    }
46
    RISCV_mutex_lock(&mutex_);
47
    for (unsigned i = 0; i < preLen_; i++) {
48
        if (curLen_ < stepQueue_.size()) {
49
            stepQueue_[curLen_].attr_free();
50
            stepQueue_[curLen_] = stepPreQueued_[i];
51
        } else {
52
            stepQueue_.add_to_list(&stepPreQueued_[i]);
53
        }
54
        curLen_++;
55
    }
56
    preLen_= 0;
57
    RISCV_mutex_unlock(&mutex_);
58
}
59
 
60
void AsyncTQueueType::initProc() {
61
    curIdx_ = 0;
62
}
63
 
64
IFace *AsyncTQueueType::getNext(uint64_t step_cnt) {
65
    IFace *ret = 0;
66
    if (curIdx_ >= curLen_) {
67
        return ret;
68
    }
69
    for (unsigned i = curIdx_; i < curLen_; i++) {
70
        uint64_t ev_time = stepQueue_[i][Queue_Time].to_uint64();
71
 
72
        if (step_cnt < ev_time) {
73
            continue;
74
        }
75
        ret = stepQueue_[i][Queue_IFace].to_iface();
76
 
77
        // remove item from list using swap function to avoid usage
78
        // of allocation/deallocation calls.
79
        stepQueue_.swap_list_item(i, curLen_ - 1);
80
        curLen_--;
81
        curIdx_--;
82
        break;
83
    }
84
    return ret;
85
}
86
 
87
}  // namespace debugger
88
 

powered by: WebSVN 2.1.0

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