From 9d752805de2020b6a8705c4abfce536620dcb760 Mon Sep 17 00:00:00 2001 From: Nick Foster Date: Wed, 16 Mar 2011 10:31:52 -0700 Subject: USB zero copy impl: proper cleanup for canceled transfers -- wait for cancel before freeing --- host/lib/transport/libusb1_zero_copy.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'host/lib/transport') diff --git a/host/lib/transport/libusb1_zero_copy.cpp b/host/lib/transport/libusb1_zero_copy.cpp index 87adece45..b425843fa 100644 --- a/host/lib/transport/libusb1_zero_copy.cpp +++ b/host/lib/transport/libusb1_zero_copy.cpp @@ -105,6 +105,12 @@ static void libusb_async_cb(libusb_transfer *lut){ (*static_cast *>(lut->user_data))(); } +//! callback to free transfer upon cancellation +static void cancel_transfer_cb(libusb_transfer *lut) { + if(lut->status == LIBUSB_TRANSFER_CANCELLED) libusb_free_transfer(lut); + else std::cout << "cancel_transfer unexpected status " << lut->status << std::endl; +} + /*********************************************************************** * USB zero_copy device class **********************************************************************/ @@ -190,16 +196,18 @@ public: } ~libusb_zero_copy_impl(void){ - //shutdown the threads - _threads_running = false; - _thread_group.interrupt_all(); - _thread_group.join_all(); - //cancel and free all transfers BOOST_FOREACH(libusb_transfer *lut, _all_luts){ + lut->callback = &cancel_transfer_cb; libusb_cancel_transfer(lut); - libusb_free_transfer(lut); + while(lut->status != LIBUSB_TRANSFER_CANCELLED && lut->status != LIBUSB_TRANSFER_COMPLETED) { + boost::this_thread::sleep(boost::posix_time::milliseconds(10)); + } } + //shutdown the threads + _threads_running = false; + _thread_group.interrupt_all(); + _thread_group.join_all(); } managed_recv_buffer::sptr get_recv_buff(double timeout){ -- cgit v1.2.3 From fb2059949e0ad898e745aafbe958dfb2f326b077 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 21 Mar 2011 10:34:16 -0700 Subject: usb: fix callback cast in libusb zero copy under msvc --- host/lib/transport/libusb1_zero_copy.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'host/lib/transport') diff --git a/host/lib/transport/libusb1_zero_copy.cpp b/host/lib/transport/libusb1_zero_copy.cpp index 697944089..9f38ce97b 100644 --- a/host/lib/transport/libusb1_zero_copy.cpp +++ b/host/lib/transport/libusb1_zero_copy.cpp @@ -199,7 +199,7 @@ public: ~libusb_zero_copy_impl(void){ //cancel and free all transfers BOOST_FOREACH(libusb_transfer *lut, _all_luts){ - lut->callback = &cancel_transfer_cb; + lut->callback = libusb_transfer_cb_fn(&cancel_transfer_cb); libusb_cancel_transfer(lut); while(lut->status != LIBUSB_TRANSFER_CANCELLED && lut->status != LIBUSB_TRANSFER_COMPLETED) { boost::this_thread::sleep(boost::posix_time::milliseconds(10)); -- cgit v1.2.3 From 95b966a599c0030921dc6b530ca8c94633d905f6 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 23 Mar 2011 18:48:30 -0700 Subject: uhd: update copyright headers with automated script --- host/Modules/UHDComponent.cmake | 2 +- host/Modules/UHDPackage.cmake | 2 +- host/Modules/UHDPython.cmake | 2 +- host/include/uhd/types/serial.hpp | 2 +- host/include/uhd/types/time_spec.hpp | 2 +- host/include/uhd/usrp/gps_ctrl.hpp | 2 +- host/include/uhd/usrp/tune_helper.hpp | 2 +- host/lib/device.cpp | 2 +- host/lib/ic_reg_maps/common.py | 2 +- host/lib/ic_reg_maps/gen_ad9522_regs.py | 2 +- host/lib/transport/if_addrs.cpp | 2 +- host/lib/usrp/CMakeLists.txt | 2 +- host/lib/usrp/dboard_base.cpp | 2 +- host/lib/usrp/dsp_utils.cpp | 2 +- host/lib/usrp/gps_ctrl.cpp | 2 +- host/lib/usrp/tune_helper.cpp | 2 +- host/lib/usrp/usrp1/clock_ctrl.hpp | 2 +- host/lib/usrp/usrp1/usrp1_ctrl.cpp | 2 +- host/lib/usrp/usrp1/usrp1_ctrl.hpp | 2 +- host/lib/usrp/usrp1/usrp1_iface.cpp | 2 +- host/lib/usrp/usrp1/usrp1_iface.hpp | 2 +- host/lib/usrp/usrp2/CMakeLists.txt | 2 +- host/lib/usrp/usrp2/clock_ctrl.cpp | 2 +- host/lib/usrp/usrp2/usrp2_iface.hpp | 2 +- host/lib/usrp/usrp_e100/clock_ctrl.hpp | 2 +- host/lib/usrp/usrp_e100/usrp_e100_iface.hpp | 2 +- host/lib/utils/images.cpp | 2 +- host/tests/addr_test.cpp | 2 +- host/tests/byteswap_test.cpp | 2 +- host/tests/dict_test.cpp | 2 +- host/tests/module_test.cpp | 2 +- host/tests/subdev_spec_test.cpp | 2 +- host/tests/time_spec_test.cpp | 2 +- host/tests/tune_helper_test.cpp | 2 +- host/tests/vrt_test.cpp | 2 +- host/tests/warning_test.cpp | 2 +- 36 files changed, 36 insertions(+), 36 deletions(-) (limited to 'host/lib/transport') diff --git a/host/Modules/UHDComponent.cmake b/host/Modules/UHDComponent.cmake index 4ea55bbb9..52b7450d5 100644 --- a/host/Modules/UHDComponent.cmake +++ b/host/Modules/UHDComponent.cmake @@ -1,5 +1,5 @@ # -# Copyright 2010 Ettus Research LLC +# Copyright 2010-2011 Ettus Research LLC # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/host/Modules/UHDPackage.cmake b/host/Modules/UHDPackage.cmake index 03483e042..8ca8995cd 100644 --- a/host/Modules/UHDPackage.cmake +++ b/host/Modules/UHDPackage.cmake @@ -1,5 +1,5 @@ # -# Copyright 2010 Ettus Research LLC +# Copyright 2010-2011 Ettus Research LLC # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/host/Modules/UHDPython.cmake b/host/Modules/UHDPython.cmake index 345e0187d..90a778609 100644 --- a/host/Modules/UHDPython.cmake +++ b/host/Modules/UHDPython.cmake @@ -1,5 +1,5 @@ # -# Copyright 2010 Ettus Research LLC +# Copyright 2010-2011 Ettus Research LLC # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/host/include/uhd/types/serial.hpp b/host/include/uhd/types/serial.hpp index ef6125933..8281fd3ec 100644 --- a/host/include/uhd/types/serial.hpp +++ b/host/include/uhd/types/serial.hpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/host/include/uhd/types/time_spec.hpp b/host/include/uhd/types/time_spec.hpp index 2046fbd3f..02de20ea1 100644 --- a/host/include/uhd/types/time_spec.hpp +++ b/host/include/uhd/types/time_spec.hpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/host/include/uhd/usrp/gps_ctrl.hpp b/host/include/uhd/usrp/gps_ctrl.hpp index 74f984ee0..21d400b3b 100644 --- a/host/include/uhd/usrp/gps_ctrl.hpp +++ b/host/include/uhd/usrp/gps_ctrl.hpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/host/include/uhd/usrp/tune_helper.hpp b/host/include/uhd/usrp/tune_helper.hpp index e97ab0298..0d468a4e2 100644 --- a/host/include/uhd/usrp/tune_helper.hpp +++ b/host/include/uhd/usrp/tune_helper.hpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/host/lib/device.cpp b/host/lib/device.cpp index 0002bee6e..1b3daa103 100644 --- a/host/lib/device.cpp +++ b/host/lib/device.cpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/host/lib/ic_reg_maps/common.py b/host/lib/ic_reg_maps/common.py index a509936b4..24f5bf8be 100644 --- a/host/lib/ic_reg_maps/common.py +++ b/host/lib/ic_reg_maps/common.py @@ -1,5 +1,5 @@ # -# Copyright 2010 Ettus Research LLC +# Copyright 2010-2011 Ettus Research LLC # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/host/lib/ic_reg_maps/gen_ad9522_regs.py b/host/lib/ic_reg_maps/gen_ad9522_regs.py index 86605c34a..1512da811 100755 --- a/host/lib/ic_reg_maps/gen_ad9522_regs.py +++ b/host/lib/ic_reg_maps/gen_ad9522_regs.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# Copyright 2010 Ettus Research LLC +# Copyright 2010-2011 Ettus Research LLC # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/host/lib/transport/if_addrs.cpp b/host/lib/transport/if_addrs.cpp index b7c8ad844..83a1ee56f 100644 --- a/host/lib/transport/if_addrs.cpp +++ b/host/lib/transport/if_addrs.cpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/host/lib/usrp/CMakeLists.txt b/host/lib/usrp/CMakeLists.txt index 59dabbd58..018beb417 100644 --- a/host/lib/usrp/CMakeLists.txt +++ b/host/lib/usrp/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright 2010 Ettus Research LLC +# Copyright 2010-2011 Ettus Research LLC # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/host/lib/usrp/dboard_base.cpp b/host/lib/usrp/dboard_base.cpp index 999dd9ffc..e14c9d144 100644 --- a/host/lib/usrp/dboard_base.cpp +++ b/host/lib/usrp/dboard_base.cpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/host/lib/usrp/dsp_utils.cpp b/host/lib/usrp/dsp_utils.cpp index a3a557060..2686e895b 100644 --- a/host/lib/usrp/dsp_utils.cpp +++ b/host/lib/usrp/dsp_utils.cpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/host/lib/usrp/gps_ctrl.cpp b/host/lib/usrp/gps_ctrl.cpp index e0ab6de90..ff8e9cee6 100644 --- a/host/lib/usrp/gps_ctrl.cpp +++ b/host/lib/usrp/gps_ctrl.cpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/host/lib/usrp/tune_helper.cpp b/host/lib/usrp/tune_helper.cpp index ced80c187..9637301ad 100644 --- a/host/lib/usrp/tune_helper.cpp +++ b/host/lib/usrp/tune_helper.cpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/host/lib/usrp/usrp1/clock_ctrl.hpp b/host/lib/usrp/usrp1/clock_ctrl.hpp index 645472f02..339d547e6 100644 --- a/host/lib/usrp/usrp1/clock_ctrl.hpp +++ b/host/lib/usrp/usrp1/clock_ctrl.hpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/host/lib/usrp/usrp1/usrp1_ctrl.cpp b/host/lib/usrp/usrp1/usrp1_ctrl.cpp index 3fa6cb8b7..22e9fd1ce 100644 --- a/host/lib/usrp/usrp1/usrp1_ctrl.cpp +++ b/host/lib/usrp/usrp1/usrp1_ctrl.cpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/host/lib/usrp/usrp1/usrp1_ctrl.hpp b/host/lib/usrp/usrp1/usrp1_ctrl.hpp index ee68f8401..970ca2951 100644 --- a/host/lib/usrp/usrp1/usrp1_ctrl.hpp +++ b/host/lib/usrp/usrp1/usrp1_ctrl.hpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/host/lib/usrp/usrp1/usrp1_iface.cpp b/host/lib/usrp/usrp1/usrp1_iface.cpp index 0c37610ce..ea7c1cea5 100644 --- a/host/lib/usrp/usrp1/usrp1_iface.cpp +++ b/host/lib/usrp/usrp1/usrp1_iface.cpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/host/lib/usrp/usrp1/usrp1_iface.hpp b/host/lib/usrp/usrp1/usrp1_iface.hpp index fdb7464ce..2ebcdbacc 100644 --- a/host/lib/usrp/usrp1/usrp1_iface.hpp +++ b/host/lib/usrp/usrp1/usrp1_iface.hpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/host/lib/usrp/usrp2/CMakeLists.txt b/host/lib/usrp/usrp2/CMakeLists.txt index e8811a8fb..49be9ac7d 100644 --- a/host/lib/usrp/usrp2/CMakeLists.txt +++ b/host/lib/usrp/usrp2/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright 2010 Ettus Research LLC +# Copyright 2010-2011 Ettus Research LLC # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/host/lib/usrp/usrp2/clock_ctrl.cpp b/host/lib/usrp/usrp2/clock_ctrl.cpp index abda53bf2..7572ed6b1 100644 --- a/host/lib/usrp/usrp2/clock_ctrl.cpp +++ b/host/lib/usrp/usrp2/clock_ctrl.cpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/host/lib/usrp/usrp2/usrp2_iface.hpp b/host/lib/usrp/usrp2/usrp2_iface.hpp index df53ec66a..08f3955f1 100644 --- a/host/lib/usrp/usrp2/usrp2_iface.hpp +++ b/host/lib/usrp/usrp2/usrp2_iface.hpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/host/lib/usrp/usrp_e100/clock_ctrl.hpp b/host/lib/usrp/usrp_e100/clock_ctrl.hpp index 1f9960ce4..623fbc73b 100644 --- a/host/lib/usrp/usrp_e100/clock_ctrl.hpp +++ b/host/lib/usrp/usrp_e100/clock_ctrl.hpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/host/lib/usrp/usrp_e100/usrp_e100_iface.hpp b/host/lib/usrp/usrp_e100/usrp_e100_iface.hpp index cb0ca2dd4..d9fe96db7 100644 --- a/host/lib/usrp/usrp_e100/usrp_e100_iface.hpp +++ b/host/lib/usrp/usrp_e100/usrp_e100_iface.hpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/host/lib/utils/images.cpp b/host/lib/utils/images.cpp index 2b6c02772..a124cc208 100644 --- a/host/lib/utils/images.cpp +++ b/host/lib/utils/images.cpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/host/tests/addr_test.cpp b/host/tests/addr_test.cpp index d4b45aa1a..01a7ab607 100644 --- a/host/tests/addr_test.cpp +++ b/host/tests/addr_test.cpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/host/tests/byteswap_test.cpp b/host/tests/byteswap_test.cpp index 3d50c9bfa..7d94bbfba 100644 --- a/host/tests/byteswap_test.cpp +++ b/host/tests/byteswap_test.cpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/host/tests/dict_test.cpp b/host/tests/dict_test.cpp index 0501a7878..7b388d090 100644 --- a/host/tests/dict_test.cpp +++ b/host/tests/dict_test.cpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/host/tests/module_test.cpp b/host/tests/module_test.cpp index 47a0e1af9..af2f749a7 100644 --- a/host/tests/module_test.cpp +++ b/host/tests/module_test.cpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/host/tests/subdev_spec_test.cpp b/host/tests/subdev_spec_test.cpp index 8817d5eee..aa0b9a119 100644 --- a/host/tests/subdev_spec_test.cpp +++ b/host/tests/subdev_spec_test.cpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/host/tests/time_spec_test.cpp b/host/tests/time_spec_test.cpp index 070392f93..e57bbced1 100644 --- a/host/tests/time_spec_test.cpp +++ b/host/tests/time_spec_test.cpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/host/tests/tune_helper_test.cpp b/host/tests/tune_helper_test.cpp index aabaaaf6e..51d216825 100644 --- a/host/tests/tune_helper_test.cpp +++ b/host/tests/tune_helper_test.cpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/host/tests/vrt_test.cpp b/host/tests/vrt_test.cpp index 9e131a10b..066f1493b 100644 --- a/host/tests/vrt_test.cpp +++ b/host/tests/vrt_test.cpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/host/tests/warning_test.cpp b/host/tests/warning_test.cpp index db19955de..3394f84d4 100644 --- a/host/tests/warning_test.cpp +++ b/host/tests/warning_test.cpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by -- cgit v1.2.3 From 2d1bd00bf04274358aed15b5652e67187424a424 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 28 Mar 2011 23:41:01 -0700 Subject: usb: changes to allow for static linking of libusb on windows --- host/lib/transport/CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'host/lib/transport') diff --git a/host/lib/transport/CMakeLists.txt b/host/lib/transport/CMakeLists.txt index a5bf9c5f1..656ca9987 100644 --- a/host/lib/transport/CMakeLists.txt +++ b/host/lib/transport/CMakeLists.txt @@ -31,6 +31,10 @@ IF(ENABLE_USB) MESSAGE(STATUS "USB support enabled via libusb.") INCLUDE_DIRECTORIES(${LIBUSB_INCLUDE_DIR}) LIBUHD_APPEND_LIBS(${LIBUSB_LIBRARIES}) + IF(WIN32) + #needed when statically linking libusb + LIBUHD_APPEND_LIBS(Setupapi.lib) + ENDIF(WIN32) LIBUHD_APPEND_SOURCES( ${CMAKE_CURRENT_SOURCE_DIR}/libusb1_control.cpp ${CMAKE_CURRENT_SOURCE_DIR}/libusb1_zero_copy.cpp -- cgit v1.2.3 From 1c5076ea68345e74de35cad43e4a4b4adf68fa15 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 31 Mar 2011 15:00:56 -0700 Subject: uhd: implemented boost barriers on all code that creates threads The barrier ensures that the thread must spawn before the caller exits. Some of the code already used a mutex to accomplish this, however cygwin chokes when a mutex is locked twice by the same thread. Mutex implementations were replaced with the barrier implementation. Also the barrier implementation is far cleaner. --- host/lib/transport/libusb1_zero_copy.cpp | 8 ++++++-- host/lib/usrp/usrp1/soft_time_ctrl.cpp | 14 ++++++++------ host/lib/usrp/usrp2/io_impl.cpp | 25 ++++++++++++------------- host/lib/usrp/usrp_e100/io_impl.cpp | 16 +++++++++++----- 4 files changed, 37 insertions(+), 26 deletions(-) (limited to 'host/lib/transport') diff --git a/host/lib/transport/libusb1_zero_copy.cpp b/host/lib/transport/libusb1_zero_copy.cpp index 9f38ce97b..fe6936c7e 100644 --- a/host/lib/transport/libusb1_zero_copy.cpp +++ b/host/lib/transport/libusb1_zero_copy.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -191,9 +192,11 @@ public: //spawn the event handler threads size_t concurrency = hints.cast("concurrency_hint", 1); + boost::barrier spawn_barrier(concurrency+1); for (size_t i = 0; i < concurrency; i++) _thread_group.create_thread( - boost::bind(&libusb_zero_copy_impl::run_event_loop, this) + boost::bind(&libusb_zero_copy_impl::run_event_loop, this, boost::ref(spawn_barrier)) ); + spawn_barrier.wait(); } ~libusb_zero_copy_impl(void){ @@ -263,7 +266,8 @@ private: boost::thread_group _thread_group; bool _threads_running; - void run_event_loop(void){ + void run_event_loop(boost::barrier &spawn_barrier){ + spawn_barrier.wait(); set_thread_priority_safe(); libusb_context *context = libusb::session::get_global_session()->get_context(); _threads_running = true; diff --git a/host/lib/usrp/usrp1/soft_time_ctrl.cpp b/host/lib/usrp/usrp1/soft_time_ctrl.cpp index e1b671811..1bab34e7b 100644 --- a/host/lib/usrp/usrp1/soft_time_ctrl.cpp +++ b/host/lib/usrp/usrp1/soft_time_ctrl.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -43,10 +44,11 @@ public: _stream_on_off(stream_on_off) { //synchronously spawn a new thread - _update_mutex.lock(); //lock mutex before spawned - _thread_group.create_thread(boost::bind(&soft_time_ctrl_impl::recv_cmd_dispatcher, this)); - _update_mutex.lock(); //lock blocks until spawned - _update_mutex.unlock(); //unlock mutex before done + boost::barrier spawn_barrier(2); + _thread_group.create_thread(boost::bind( + &soft_time_ctrl_impl::recv_cmd_dispatcher, this, boost::ref(spawn_barrier)) + ); + spawn_barrier.wait(); //initialize the time to something this->set_time(time_spec_t(0.0)); @@ -175,8 +177,8 @@ public: _stream_mode = cmd.stream_mode; } - void recv_cmd_dispatcher(void){ - _update_mutex.unlock(); + void recv_cmd_dispatcher(boost::barrier &spawn_barrier){ + spawn_barrier.wait(); try{ boost::any cmd; while (true){ diff --git a/host/lib/usrp/usrp2/io_impl.cpp b/host/lib/usrp/usrp2/io_impl.cpp index 340e9d155..07cbd2432 100644 --- a/host/lib/usrp/usrp2/io_impl.cpp +++ b/host/lib/usrp/usrp2/io_impl.cpp @@ -25,7 +25,8 @@ #include #include #include -#include +#include +#include #include using namespace uhd; @@ -209,11 +210,10 @@ struct usrp2_impl::io_impl{ vrt_packet_handler::send_state packet_handler_send_state; //methods and variables for the pirate crew - void recv_pirate_loop(usrp2_mboard_impl::sptr, zero_copy_if::sptr, size_t); + void recv_pirate_loop(boost::barrier &, usrp2_mboard_impl::sptr, zero_copy_if::sptr, size_t); boost::thread_group recv_pirate_crew; bool recv_pirate_crew_raiding; bounded_buffer async_msg_fifo; - boost::mutex spawn_mutex; }; /*********************************************************************** @@ -223,13 +223,15 @@ struct usrp2_impl::io_impl{ * - put async message packets into queue **********************************************************************/ void usrp2_impl::io_impl::recv_pirate_loop( - usrp2_mboard_impl::sptr mboard, zero_copy_if::sptr err_xport, size_t index + boost::barrier &spawn_barrier, + usrp2_mboard_impl::sptr mboard, + zero_copy_if::sptr err_xport, + size_t index ){ + spawn_barrier.wait(); set_thread_priority_safe(); recv_pirate_crew_raiding = true; - spawn_mutex.unlock(); - //store a reference to the flow control monitor (offset by max dsps) flow_control_monitor &fc_mon = *(this->fc_mons[index*usrp2_mboard_impl::MAX_NUM_DSPS]); @@ -286,19 +288,16 @@ void usrp2_impl::io_init(void){ _io_impl = UHD_PIMPL_MAKE(io_impl, (dsp_xports)); //create a new pirate thread for each zc if (yarr!!) + boost::barrier spawn_barrier(_mboards.size()+1); for (size_t i = 0; i < _mboards.size(); i++){ - //lock the unlocked mutex (non-blocking) - _io_impl->spawn_mutex.lock(); //spawn a new pirate to plunder the recv booty _io_impl->recv_pirate_crew.create_thread(boost::bind( &usrp2_impl::io_impl::recv_pirate_loop, - _io_impl.get(), _mboards.at(i), err_xports.at(i), i + _io_impl.get(), boost::ref(spawn_barrier), + _mboards.at(i), err_xports.at(i), i )); - //block here until the spawned thread unlocks - _io_impl->spawn_mutex.lock(); - //exit loop iteration in an unlocked condition - _io_impl->spawn_mutex.unlock(); } + spawn_barrier.wait(); //update mapping here since it didnt b4 when io init not called first update_xport_channel_mapping(); diff --git a/host/lib/usrp/usrp_e100/io_impl.cpp b/host/lib/usrp/usrp_e100/io_impl.cpp index fc6aaeaee..cbab5a761 100644 --- a/host/lib/usrp/usrp_e100/io_impl.cpp +++ b/host/lib/usrp/usrp_e100/io_impl.cpp @@ -23,7 +23,8 @@ #include "../../transport/vrt_packet_handler.hpp" #include #include -#include +#include +#include #include using namespace uhd; @@ -93,7 +94,7 @@ struct usrp_e100_impl::io_impl{ bool continuous_streaming; //a pirate's life is the life for me! - void recv_pirate_loop(usrp_e100_clock_ctrl::sptr); + void recv_pirate_loop(boost::barrier &, usrp_e100_clock_ctrl::sptr); bounded_buffer recv_pirate_booty; bounded_buffer async_msg_fifo; boost::thread_group recv_pirate_crew; @@ -105,8 +106,10 @@ struct usrp_e100_impl::io_impl{ * - while raiding, loot for recv buffers * - put booty into the alignment buffer **********************************************************************/ -void usrp_e100_impl::io_impl::recv_pirate_loop(usrp_e100_clock_ctrl::sptr clock_ctrl) -{ +void usrp_e100_impl::io_impl::recv_pirate_loop( + boost::barrier &spawn_barrier, usrp_e100_clock_ctrl::sptr clock_ctrl +){ + spawn_barrier.wait(); set_thread_priority_safe(); recv_pirate_crew_raiding = true; @@ -201,9 +204,12 @@ void usrp_e100_impl::io_init(void){ _iface->poke32(UE_REG_CTRL_TX_POLICY, UE_FLAG_CTRL_TX_POLICY_NEXT_PACKET); //spawn a pirate, yarrr! + boost::barrier spawn_barrier(2); _io_impl->recv_pirate_crew.create_thread(boost::bind( - &usrp_e100_impl::io_impl::recv_pirate_loop, _io_impl.get(), _clock_ctrl + &usrp_e100_impl::io_impl::recv_pirate_loop, _io_impl.get(), + boost::ref(spawn_barrier), _clock_ctrl )); + spawn_barrier.wait(); } void usrp_e100_impl::issue_stream_cmd(const stream_cmd_t &stream_cmd){ -- cgit v1.2.3 From 7cd216e967161a0d3a4d7b9bc03583d270ce4de3 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 4 Apr 2011 13:10:06 -0700 Subject: uhd: specify msvc for implementations known only to work on msvc --- host/CMakeLists.txt | 9 +++++++-- host/Modules/UHDPackage.cmake | 12 ++++++------ host/include/uhd/config.hpp | 2 +- host/include/uhd/utils/byteswap.ipp | 6 +++--- host/lib/transport/CMakeLists.txt | 4 ++-- 5 files changed, 19 insertions(+), 14 deletions(-) (limited to 'host/lib/transport') diff --git a/host/CMakeLists.txt b/host/CMakeLists.txt index 3808481bf..7df04995c 100644 --- a/host/CMakeLists.txt +++ b/host/CMakeLists.txt @@ -80,16 +80,21 @@ ENDIF(CMAKE_COMPILER_IS_GNUCXX) IF(MSVC) INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/msvc) - ADD_DEFINITIONS(-D_WIN32_WINNT=0x0501) #minimum version required is windows xp - ADD_DEFINITIONS(-DNOMINMAX) #disables stupidity and enables std::min and std::max ADD_DEFINITIONS( #stop all kinds of compatibility warnings -D_SCL_SECURE_NO_WARNINGS + -D_SCL_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE + -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE ) ENDIF(MSVC) +IF(WIN32) + ADD_DEFINITIONS(-D_WIN32_WINNT=0x0501) #minimum version required is windows xp + ADD_DEFINITIONS(-DNOMINMAX) #disables stupidity and enables std::min and std::max +ENDIF(WIN32) + ######################################################################## # Setup Boost ######################################################################## diff --git a/host/Modules/UHDPackage.cmake b/host/Modules/UHDPackage.cmake index 7ac677d28..4986e314c 100644 --- a/host/Modules/UHDPackage.cmake +++ b/host/Modules/UHDPackage.cmake @@ -21,18 +21,18 @@ INCLUDE(UHDVersion) #sets version information ######################################################################## # Setup additional defines for OS types ######################################################################## -IF(UNIX AND EXISTS "/etc/debian_version") +IF(CMAKE_SYSTEM_NAME STREQUAL "Linux") + SET(LINUX TRUE) +ENDIF() + +IF(LINUX AND EXISTS "/etc/debian_version") SET(DEBIAN TRUE) ENDIF() -IF(UNIX AND EXISTS "/etc/redhat-release") +IF(LINUX AND EXISTS "/etc/redhat-release") SET(REDHAT TRUE) ENDIF() -IF(CMAKE_SYSTEM_NAME STREQUAL "Linux") - SET(LINUX TRUE) -ENDIF(CMAKE_SYSTEM_NAME STREQUAL "Linux") - ######################################################################## # Setup package file name ######################################################################## diff --git a/host/include/uhd/config.hpp b/host/include/uhd/config.hpp index fdb168950..6fd2932cf 100644 --- a/host/include/uhd/config.hpp +++ b/host/include/uhd/config.hpp @@ -49,7 +49,7 @@ typedef ptrdiff_t ssize_t; #endif //BOOST_MSVC //define cross platform attribute macros -#if defined(BOOST_HAS_DECLSPEC) +#if defined(BOOST_MSVC) #define UHD_EXPORT __declspec(dllexport) #define UHD_IMPORT __declspec(dllimport) #define UHD_INLINE __forceinline diff --git a/host/include/uhd/utils/byteswap.ipp b/host/include/uhd/utils/byteswap.ipp index a070a7cf5..c090dee55 100644 --- a/host/include/uhd/utils/byteswap.ipp +++ b/host/include/uhd/utils/byteswap.ipp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -21,8 +21,8 @@ /*********************************************************************** * Platform-specific implementation details for byteswap below: **********************************************************************/ -#if defined(UHD_PLATFORM_WIN32) //http://msdn.microsoft.com/en-us/library/a3140177%28VS.80%29.aspx - #include +#if defined(BOOST_MSVC) //http://msdn.microsoft.com/en-us/library/a3140177%28VS.80%29.aspx + #include UHD_INLINE boost::uint16_t uhd::byteswap(boost::uint16_t x){ return _byteswap_ushort(x); diff --git a/host/lib/transport/CMakeLists.txt b/host/lib/transport/CMakeLists.txt index 656ca9987..a7179d561 100644 --- a/host/lib/transport/CMakeLists.txt +++ b/host/lib/transport/CMakeLists.txt @@ -31,10 +31,10 @@ IF(ENABLE_USB) MESSAGE(STATUS "USB support enabled via libusb.") INCLUDE_DIRECTORIES(${LIBUSB_INCLUDE_DIR}) LIBUHD_APPEND_LIBS(${LIBUSB_LIBRARIES}) - IF(WIN32) + IF(MSVC) #needed when statically linking libusb LIBUHD_APPEND_LIBS(Setupapi.lib) - ENDIF(WIN32) + ENDIF(MSVC) LIBUHD_APPEND_SOURCES( ${CMAKE_CURRENT_SOURCE_DIR}/libusb1_control.cpp ${CMAKE_CURRENT_SOURCE_DIR}/libusb1_zero_copy.cpp -- cgit v1.2.3 From 1ba366a94ef70980fb5db5dd0142c3d3596ef9aa Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 4 Apr 2011 16:09:02 -0700 Subject: usb: newer libusb1 does not need to link with setupapi.lib --- host/lib/transport/CMakeLists.txt | 4 ---- 1 file changed, 4 deletions(-) (limited to 'host/lib/transport') diff --git a/host/lib/transport/CMakeLists.txt b/host/lib/transport/CMakeLists.txt index a7179d561..a5bf9c5f1 100644 --- a/host/lib/transport/CMakeLists.txt +++ b/host/lib/transport/CMakeLists.txt @@ -31,10 +31,6 @@ IF(ENABLE_USB) MESSAGE(STATUS "USB support enabled via libusb.") INCLUDE_DIRECTORIES(${LIBUSB_INCLUDE_DIR}) LIBUHD_APPEND_LIBS(${LIBUSB_LIBRARIES}) - IF(MSVC) - #needed when statically linking libusb - LIBUHD_APPEND_LIBS(Setupapi.lib) - ENDIF(MSVC) LIBUHD_APPEND_SOURCES( ${CMAKE_CURRENT_SOURCE_DIR}/libusb1_control.cpp ${CMAKE_CURRENT_SOURCE_DIR}/libusb1_zero_copy.cpp -- cgit v1.2.3 From dbfbc497a8e0a144e0db2b8daa0f4baba5284775 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 5 Apr 2011 16:32:48 -0700 Subject: uhd: tweaks for cygwin/mingw, always link winsock2, findusb1, __USE_W32_SOCKETS --- host/CMakeLists.txt | 4 ++++ host/Modules/FindUSB1.cmake | 6 +++--- host/lib/CMakeLists.txt | 8 -------- host/lib/transport/CMakeLists.txt | 4 ++++ 4 files changed, 11 insertions(+), 11 deletions(-) (limited to 'host/lib/transport') diff --git a/host/CMakeLists.txt b/host/CMakeLists.txt index 7df04995c..552fe492c 100644 --- a/host/CMakeLists.txt +++ b/host/CMakeLists.txt @@ -90,6 +90,10 @@ IF(MSVC) ) ENDIF(MSVC) +IF(CYGWIN) + ADD_DEFINITIONS(-D__USE_W32_SOCKETS) #boost asio says we need this +ENDIF(CYGWIN) + IF(WIN32) ADD_DEFINITIONS(-D_WIN32_WINNT=0x0501) #minimum version required is windows xp ADD_DEFINITIONS(-DNOMINMAX) #disables stupidity and enables std::min and std::max diff --git a/host/Modules/FindUSB1.cmake b/host/Modules/FindUSB1.cmake index ebcac99eb..efb2e288b 100644 --- a/host/Modules/FindUSB1.cmake +++ b/host/Modules/FindUSB1.cmake @@ -17,12 +17,12 @@ if (LIBUSB_INCLUDE_DIR AND LIBUSB_LIBRARIES) set(LIBUSB_FOUND TRUE) else (LIBUSB_INCLUDE_DIR AND LIBUSB_LIBRARIES) - IF (NOT WIN32) # use pkg-config to get the directories and then use these values # in the FIND_PATH() and FIND_LIBRARY() calls find_package(PkgConfig) - pkg_check_modules(PC_LIBUSB libusb-1.0) - ENDIF(NOT WIN32) + IF(PKG_CONFIG_FOUND) + pkg_check_modules(PC_LIBUSB libusb-1.0) + ENDIF(PKG_CONFIG_FOUND) FIND_PATH(LIBUSB_INCLUDE_DIR libusb.h PATHS ${PC_LIBUSB_INCLUDEDIR} ${PC_LIBUSB_INCLUDE_DIRS}) diff --git a/host/lib/CMakeLists.txt b/host/lib/CMakeLists.txt index 268f05df6..8ca7c7dca 100644 --- a/host/lib/CMakeLists.txt +++ b/host/lib/CMakeLists.txt @@ -68,14 +68,6 @@ MACRO(INCLUDE_SUBDIRECTORY subdir) LIST(REMOVE_AT _cmake_binary_dirs 0) ENDMACRO(INCLUDE_SUBDIRECTORY) -######################################################################## -# Cygwin special -######################################################################## -IF(CYGWIN) - ADD_DEFINITIONS(-D__USE_W32_SOCKETS) #boost asio says we need this - LIBUHD_APPEND_LIBS(ws2_32) -ENDIF(CYGWIN) - ######################################################################## # Include subdirectories (different than add) ######################################################################## diff --git a/host/lib/transport/CMakeLists.txt b/host/lib/transport/CMakeLists.txt index a5bf9c5f1..30f8db48a 100644 --- a/host/lib/transport/CMakeLists.txt +++ b/host/lib/transport/CMakeLists.txt @@ -79,6 +79,10 @@ SET_SOURCE_FILES_PROPERTIES( PROPERTIES COMPILE_DEFINITIONS "${IF_ADDRS_DEFS}" ) +IF(WIN32 AND UNIX) #MinGW/Cygwin needs winsock2 + LIBUHD_APPEND_LIBS(ws2_32) +ENDIF() + ######################################################################## # Append to the list of sources for lib uhd ######################################################################## -- cgit v1.2.3 From d07870f698e314a516939ca91de3d7307c9bade7 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 5 Apr 2011 20:37:29 -0700 Subject: usb: mark libusb callbacks with LIBUSB_CALL to ensure correct calling convention --- host/lib/transport/libusb1_zero_copy.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'host/lib/transport') diff --git a/host/lib/transport/libusb1_zero_copy.cpp b/host/lib/transport/libusb1_zero_copy.cpp index fe6936c7e..e42cab1d1 100644 --- a/host/lib/transport/libusb1_zero_copy.cpp +++ b/host/lib/transport/libusb1_zero_copy.cpp @@ -34,13 +34,23 @@ using namespace uhd::transport; static const size_t DEFAULT_NUM_XFERS = 16; //num xfers static const size_t DEFAULT_XFER_SIZE = 32*512; //bytes +//! Define LIBUSB_CALL when its missing (non-windows) +#ifndef LIBUSB_CALL + #define LIBUSB_CALL +#endif /*LIBUSB_CALL*/ + +/*! + * All libusb callback functions should be marked with the LIBUSB_CALL macro + * to ensure that they are compiled with the same calling convention as libusb. + */ + //! helper function: handles all async callbacks -static void libusb_async_cb(libusb_transfer *lut){ +static void LIBUSB_CALL libusb_async_cb(libusb_transfer *lut){ (*static_cast *>(lut->user_data))(); } //! callback to free transfer upon cancellation -static void cancel_transfer_cb(libusb_transfer *lut){ +static void LIBUSB_CALL cancel_transfer_cb(libusb_transfer *lut){ if (lut->status == LIBUSB_TRANSFER_CANCELLED) libusb_free_transfer(lut); else std::cout << "libusb cancel_transfer unexpected status " << lut->status << std::endl; } -- cgit v1.2.3 From 74fc8946688d53ccd5d067d3f86e26b990af1bd4 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 6 Apr 2011 09:55:54 -0700 Subject: uhd: always link winsock2 on windows, disable pthread SCHED_RR for cygwin --- host/lib/transport/CMakeLists.txt | 4 +++- host/lib/utils/CMakeLists.txt | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'host/lib/transport') diff --git a/host/lib/transport/CMakeLists.txt b/host/lib/transport/CMakeLists.txt index 30f8db48a..90360977a 100644 --- a/host/lib/transport/CMakeLists.txt +++ b/host/lib/transport/CMakeLists.txt @@ -79,7 +79,9 @@ SET_SOURCE_FILES_PROPERTIES( PROPERTIES COMPILE_DEFINITIONS "${IF_ADDRS_DEFS}" ) -IF(WIN32 AND UNIX) #MinGW/Cygwin needs winsock2 +#On windows, the boost asio implementation uses the winsock2 library. +#Note: we exclude the .lib extension for cygwin and mingw platforms. +IF(WIN32) LIBUHD_APPEND_LIBS(ws2_32) ENDIF() diff --git a/host/lib/utils/CMakeLists.txt b/host/lib/utils/CMakeLists.txt index c0d99b37e..26c02b5b4 100644 --- a/host/lib/utils/CMakeLists.txt +++ b/host/lib/utils/CMakeLists.txt @@ -36,6 +36,11 @@ CHECK_CXX_SOURCE_COMPILES(" " HAVE_PTHREAD_SETSCHEDPARAM ) +IF(CYGWIN) + #SCHED_RR non-operational on cygwin + SET(HAVE_PTHREAD_SETSCHEDPARAM False) +ENDIF(CYGWIN) + CHECK_CXX_SOURCE_COMPILES(" #include int main(){ -- cgit v1.2.3