libuv test

master
zcy 2023-05-25 00:09:05 +08:00
parent 2c6edbbb54
commit 4799898fe8
2 changed files with 19 additions and 50 deletions

View File

@ -1,6 +1,5 @@
#include "loger.h"
#include "debug.h"
#include "pattern/ringbuffer.hpp"
#include <math.h>
#pragma pack(4)
@ -49,51 +48,7 @@ BYTE_ORDER HostByteOrder(){
}
RingBuffer<int> pTest(200);
int tmp[200];
int tmp2[200];
int main(){
int randlen;
for (int w = 0; w < 200; w++) {
tmp2[w] = w;
}
for(int i = 0;i < 100;i++){
std::cout << "\r\n";
std::cout << "round " << i << std::endl;
randlen = rand() % 100;
std::cout <<"randlen" << randlen << "\r\n";
int z = 0;
for (z = 0; z < randlen; z++) {
pTest.Add(&tmp2[z], 1);
}
std::cout << "check\r\n";
for (z = 0; z < randlen; z++) {
printf("%02d ", pTest.At(z));
//std::cout << pTest.At(z) << " ";
if ((z != 0) && (z % 10 == 0)) {
std::cout << "\r\n";
}
}
std::cout << "\r\n";
std::cout << "take" << pTest.TakeBack(tmp, randlen) << "\r\n" << std::endl;
std::cout << "\r\n";
for (int z = 0; z < randlen; z++) {
printf("%02d ", tmp[z]);
// std::cout << tmp[z]<< " ";
if ((z != 0)&&(z % 10 == 0)){
std::cout<<"\r\n";
}
}
std::cout << "\r\n";
}
std::cout<<"byteorder "<<HostByteOrder()<<std::endl;
std::cout<< LimitFloat(1.123,2)<<std::endl;
std::cout<<LimitFloat(1.123,3) << std::endl;

View File

@ -11,6 +11,7 @@
uv_async_t async;
uv_async_t async2;
uv_async_t stopsig;
uv_loop_t* loop;
@ -37,20 +38,26 @@ void async_cb2(uv_async_t* handle)
printf("thread id:%lu.\n", id);
}
void idle_cb(uv_async_t *handle) {
printf("Idle callback\n");
uv_stop(uv_default_loop());
}
int main()
{
loop = uv_default_loop();
uv_thread_t id = uv_thread_self();
int id = GetCurrentThreadId();
printf("thread id:%lu.\n", id);
uv_async_init(loop, &async, async_cb);
uv_async_init(loop, &async2, async_cb2);
uv_async_init(loop, &stopsig, idle_cb);
uv_async_send(&async);
std::thread t1([]()->int{
Sleep(2000);
std::cout<<"start\r\n";
@ -59,9 +66,16 @@ int main()
uv_async_send(&async);
Sleep(1000);
uv_async_send(&async2);
Sleep(5000);
std::cout<<"stop\r\n";
uv_async_send(&stopsig);
std::cout<<"stop\r\n";
return 1;
});
t1.detach();
uv_run(loop, UV_RUN_DEFAULT);
uv_stop(loop);
return 0;
}
}