32#include <condition_variable>
47 std::unique_lock<std::mutex> lock(mutex_);
50 condition_.notify_one();
55 std::unique_lock<std::mutex> lock(mutex_);
56 condition_.wait(lock, [
this] {
return !queue_.empty(); });
57 auto value = (T *)queue_.front();
63 std::queue<T *> queue_;
65 std::condition_variable condition_;
88 std::unique_lock<std::mutex> *lock;
93 auto s = _kit->
open_send(0, mem, block, 0);
95 std::cout <<
"Establish CS and CR connections: " << std::endl;
96 std::cout <<
"Failed to enable data uplink " <<
nsukit::status2_string(s) <<
", currently uplinked: " << current << std::endl;
105 if (current == total)
break;
107 lock =
new std::unique_lock<std::mutex>(*mu);
121 std::unique_lock<std::mutex> *lock;
123 unsigned int *buffer;
126 auto st = std::chrono::steady_clock::now();
129 lock =
new std::unique_lock<std::mutex>(*mu);
135 buffer = (
unsigned int *)_kit->
get_buffer(mem, block);
136 for(
int i=0; i<block; i++) buffer[i] = i;
138 speed_count += block;
141 auto count = std::chrono::steady_clock::now() - st;
142 std::cout << std::flush <<
'\r' <<
"当前数据生成速度: " << speed_count*1000./(count.count()) <<
"MB/s" << std::endl;
146 std::cout << std::endl;
150int main(
int argc,
char *argv[]) {
151 unsigned int ds_block = 1024*1024;
154 nsukit::NSUSoc <nsukit::TCPCmdUItf, nsukit::PCIECmdUItf, nsukit::PCIEStreamUItf> kit{};
157 std::cout <<
"Unsupported parameter passing method" << std::endl;
159 std::cout << argv[0] <<
" {IP} {totalBytes} {filePath}" << std::endl;
162 nsuSize_t total_len = std::atoi(argv[2]);
163 if (total_len % ds_block != 0) {
164 std::cout <<
"The total length of upstream data total_len "
165 << total_len <<
" Bytes should be "
166 << ds_block <<
" Integer multiple of Bytes" << std::endl;
175 auto res = kit.link_cmd(¶m);
180 res = kit.link_stream(¶m);
185 for (
int i=0; i<10; i++) {
192 res = kit.execute(
"系统开启");
198 std::thread up_trd(
download_thread, &kit, &q, ds_block, total_len, &mu);
199 std::thread generate_trd(
data_generate, &kit, &q, ds_block, &mu);
205 res = kit.execute(
"系统停止");
210 std::cout <<
"Data download completed" << std::endl;
virtual nsuVoidBuf_p get_buffer(nsuMemory_p fd, nsuStreamLen_t length=0)
virtual nsukitStatus_t open_send(nsuChnlNum_t chnl, nsuMemory_p fd, nsuStreamLen_t length, nsuStreamLen_t offset=0)
virtual nsukitStatus_t wait_stream(nsuMemory_p fd, float timeout=0.)
void data_generate(nsukit::BaseKit *_kit, Deque *q, nsuSize_t block, std::mutex *mu)
void download_thread(nsukit::BaseKit *_kit, Deque *q, nsuSize_t block, nsuSize_t total, std::mutex *mu)
ThreadSafeQueue< void > memQueue
std::string NSU_DLLEXPORT status2_string(nsukitStatus_t status)
nsuBoardNum_t stream_board
@ NSUKIT_STATUS_STREAM_RUNNING
DLLEXTERN typedef size_t nsuSize_t
DLLEXTERN typedef void * nsuMemory_p