Fix for SHSTK
This commit is contained in:
2
can
2
can
Submodule can updated: d71e58468e...38d6d57271
@@ -3,18 +3,21 @@ cmake_policy(SET CMP0020 NEW)
|
||||
|
||||
find_package(PIP REQUIRED)
|
||||
|
||||
add_executable(asyncdevicepool asyncdevicepool.cpp)
|
||||
target_link_libraries(asyncdevicepool PIP can)
|
||||
|
||||
if(WIN32)
|
||||
add_custom_target(copy_dependencies
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${PCAN_LIB} ${CMAKE_CURRENT_BINARY_DIR}/PCANBasic${CMAKE_SHARED_LIBRARY_SUFFIX}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${VSCAN_LIB} ${CMAKE_CURRENT_BINARY_DIR}/vs_can_api${CMAKE_SHARED_LIBRARY_SUFFIX})
|
||||
|
||||
add_dependencies(asyncdevicepool copy_dependencies)
|
||||
|
||||
add_executable(can_send_multithread can_send_multithread.cpp)
|
||||
target_include_directories(can_send_multithread PUBLIC ${PIP_INCLUDES} ${CAN_INCLUDES})
|
||||
target_link_libraries(can_send_multithread can)
|
||||
add_dependencies(can_send_multithread copy_dependencies)
|
||||
|
||||
add_executable(can_send can_send.cpp)
|
||||
target_include_directories(can_send PUBLIC ${PIP_INCLUDES} ${CAN_INCLUDES})
|
||||
target_link_libraries(can_send can)
|
||||
add_dependencies(can_send copy_dependencies)
|
||||
endif()
|
||||
80
experiments/can/asyncdevicepool.cpp
Normal file
80
experiments/can/asyncdevicepool.cpp
Normal file
@@ -0,0 +1,80 @@
|
||||
#include <asyncdevicepool.h>
|
||||
|
||||
using namespace std::chrono;
|
||||
|
||||
class FakeDevice : public CANDevice {
|
||||
PIOBJECT_SUBCLASS(FakeDevice, CANDevice)
|
||||
public:
|
||||
double duration_ms;
|
||||
|
||||
explicit FakeDevice(int counter) : duration_ms(0.0), counter(counter) {}
|
||||
|
||||
bool send(const CAN_Raw &m) override {
|
||||
counter--;
|
||||
if (counter <= 0) {
|
||||
if (counter == 0) duration_ms = (duration_cast<milliseconds>(high_resolution_clock::now().time_since_epoch()) - start_time).count();
|
||||
counter = -1;
|
||||
throw can::error(0, can_category);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool open() override {
|
||||
start_time = duration_cast<milliseconds>(high_resolution_clock::now().time_since_epoch());
|
||||
return true;
|
||||
}
|
||||
|
||||
void close() override {
|
||||
if (read_handle != can::event::invalid_handle) can::event::close(read_handle);
|
||||
}
|
||||
|
||||
can::event::handle getReadEventHandle() override {
|
||||
if (read_handle == can::event::invalid_handle) {
|
||||
read_handle = can::event::make();
|
||||
}
|
||||
return read_handle;
|
||||
}
|
||||
|
||||
protected:
|
||||
bool nextMsg(CAN_Raw &rawMsg) override {
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
int counter = 0;
|
||||
milliseconds start_time;
|
||||
};
|
||||
|
||||
int main() {
|
||||
int device_count = 63;
|
||||
PIBlockingQueue<double> wait_queue(device_count);
|
||||
|
||||
AsyncDevicePool asyncDevicePool;
|
||||
asyncDevicePool.set_can_error_handler([&wait_queue](const can::error& error, CANDevice* device) {
|
||||
// can::stdout_error_handler(error, device);
|
||||
wait_queue.put(dynamic_cast<FakeDevice*>(device)->duration_ms);
|
||||
return false;
|
||||
});
|
||||
|
||||
int it_count = 1'000'000;
|
||||
PIVector<CANDevice*> devices;
|
||||
for (int i = 0; i < device_count; ++i) {
|
||||
devices << new FakeDevice(it_count / device_count);
|
||||
asyncDevicePool.add(devices.back());
|
||||
}
|
||||
|
||||
for (int i = 0; i < it_count; ++i) {
|
||||
CAN_Raw msg = { .Id = 0x11, .Size = 4, .Data = { 0x0, 0x1, 0x2, 0x3 } };
|
||||
asyncDevicePool.send(devices[i % device_count], msg);
|
||||
if (i % 1000 == 999) {
|
||||
std::this_thread::yield();
|
||||
// std::cout << i / 1000 << "/" << counter / 1000 << std::endl;
|
||||
// std::this_thread::sleep_for(milliseconds(1));
|
||||
}
|
||||
}
|
||||
|
||||
double duration_ms;
|
||||
for (int i = 0; i < device_count; ++i) duration_ms = wait_queue.take();
|
||||
std::cout << duration_ms << " ms" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
@@ -4,13 +4,10 @@ cmake_policy(SET CMP0020 NEW)
|
||||
find_package(PIP REQUIRED)
|
||||
|
||||
add_executable(mutex mutex.cpp)
|
||||
target_include_directories(mutex PUBLIC ${PIP_INCLUDES})
|
||||
target_link_libraries(mutex ${PIP_LIBRARY} ${PIP_CONCURRENT_LIBRARY})
|
||||
target_link_libraries(mutex PIP)
|
||||
|
||||
add_executable(mutex_multithread mutex_multithread.cpp)
|
||||
target_include_directories(mutex_multithread PUBLIC ${PIP_INCLUDES})
|
||||
target_link_libraries(mutex_multithread ${PIP_LIBRARY} ${PIP_CONCURRENT_LIBRARY})
|
||||
target_link_libraries(mutex_multithread PIP)
|
||||
|
||||
add_executable(vectors vectors.cpp)
|
||||
target_include_directories(vectors PUBLIC ${PIP_INCLUDES})
|
||||
target_link_libraries(vectors ${PIP_LIBRARY})
|
||||
target_link_libraries(vectors PIP)
|
||||
@@ -4,9 +4,7 @@ cmake_policy(SET CMP0020 NEW)
|
||||
find_package(SM REQUIRED)
|
||||
|
||||
add_executable(block_choice block_choice.cpp)
|
||||
target_include_directories(block_choice PUBLIC ${SMBRICKS_INCLUDES} ${PIP_INCLUDES})
|
||||
target_link_libraries(block_choice ${PIP_LIBRARY})
|
||||
target_link_libraries(block_choice PIP)
|
||||
|
||||
add_executable(smbusdata_crash_test smbusdata_crash_test.cpp)
|
||||
target_include_directories(smbusdata_crash_test PUBLIC ${SMBRICKS_INCLUDES} ${PIP_INCLUDES})
|
||||
target_link_libraries(smbusdata_crash_test SMBricks_shared ${PIP_LIBRARY} ${PIP_CRYPT_LIBRARY})
|
||||
target_link_libraries(smbusdata_crash_test SMBricks_shared PIP::Crypt)
|
||||
|
||||
Reference in New Issue
Block a user