//////////////////////////////////////////////////////////////////////////////// // high recall //////////////////////////////////////////////////////////////////////////////// void hrFrequentThread( long start, long stop, std::vector<Conjunction> const& conjunctions, std::map<Rule, OrderedCover> const& basicCovers, OrderedCover const& trueCover, double const treshold, std::vector<Conjunction>& result, boost::mutex& mutex ) { std::vector<Conjunction> _result; _result.reserve(stop-start); auto start_i = conjunctions.begin(); auto stop_i = conjunctions.begin(); std::advance(start_i, start); std::advance(stop_i, stop); long counter = 0; for (auto i=start_i ; i!=stop_i ; ++i) { OrderedCover _ordc(conjunctionCover(*i, basicCovers)); if (_ordc.metrics(trueCover).recall() >= treshold) { _result.push_back(*i); counter += 1; } // try copying intermediate results if (counter % 256 == 0) { if (mutex.try_lock()) { std::copy(_result.begin(), _result.end(), std::back_inserter(result)); mutex.unlock(); _result.clear(); } } } // copy to master _result vector mutex.lock(); std::copy(_result.begin(), _result.end(), std::back_inserter(result)); mutex.unlock(); }
void get_images(sensor_msgs::Image::ConstPtr& im, stereo_msgs::DisparityImage::ConstPtr& dm) { img_lock.lock(); im = last_img; dm = last_disp; //Reset pointers to null /* last_img.reset(); last_disp.reset(); */ img_lock.unlock(); }
void packet_collector_thread_unordered_map_preallocated() { for (int iteration = 0; iteration < number_of_retries; iteration++) { for (uint32_t i = 0; i < number_of_ips; i++) { #ifdef enable_mutexex_in_test data_counter_mutex.lock(); #endif DataCounterUnordered[i].udp_in_bytes++; #ifdef enable_mutexex_in_test data_counter_mutex.unlock(); #endif } } }
int main() { m.lock(); boost::thread t(f); #if defined BOOST_THREAD_USES_CHRONO boost::this_thread::sleep_for(ms(250)); #else #endif m.unlock(); t.join(); return boost::report_errors(); }
bool Mapper::reset(std_srvs::Empty::Request &req, std_srvs::Empty::Response &res) { waitForMapBuildingCompleted(); // note: no need for locking as we do ros::spin(), to update if we go for multi-threading publishLock.lock(); TOdomToMap = PM::TransformationParameters::Identity(4,4); publishLock.unlock(); icp.clearMap(); return true; }
int main() { testclass* test = new testclass(); boost::thread thread(&testclass::print,test); for(int i = 0; i < 10;i++) { mut.lock(); std::cout << "Main" << std::endl; mut.unlock(); } thread.join(); delete test; }
Scene::Scene(Camera *cam) : camera(cam), volumeRegion(NULL), surfaceIntegrator(NULL), volumeIntegrator(NULL), sampler(NULL), filmOnly(true) { for(u_int i = 0; i < cam->film->GetNumBufferGroups(); i++) lightGroups.push_back( cam->film->GetGroupName(i) ); // Dade - Initialize the base seed with the standard C lib random number generator scene_rand_mutex.lock(); seedBase = scene_rng(); scene_rand_mutex.unlock(); }
void games_t::write_score(char* _pname, score_t _s) { if(strlen(_pname) <= 0) return; mtx_all_games.lock(); FILE* fp; if ((fp = fopen(score_filename,"r+")) == 0) { fprintf(stderr, "fopen %s error\n", score_filename); mtx_all_games.unlock(); return; } char line[1024]; while(fgets( line, sizeof(line), fp) ) { score_t pscore; char spname[128]; if(sscanf(line,"%d %d %d %s", &pscore.win, &pscore.lost, &pscore.abort, spname) == 4) { if(strncmp(_pname, spname, 64) == 0) { char nline[128]; fseek(fp, -strlen(line), SEEK_CUR); sprintf(nline, "%d %d %d %s\n", _s.win, _s.lost, _s.abort, spname); fwrite(nline, sizeof(char), strlen(nline), fp); fflush(fp); fclose(fp); mtx_all_games.unlock(); return; } } } char nline[128]; sprintf(nline, "%d %d %d %s\n", _s.win, _s.lost, _s.abort, _pname); fwrite(nline, sizeof(char), strlen(nline), fp); fflush(fp); fclose(fp); mtx_all_games.unlock(); }
void servoController(int destinationAngle,int isFinished,int originArea){ if(isFinished == 1){ servoTurnUp('c'); servoTurnRL(1,1); } else{ servoTurnUp('f'); while(1){ if(1 == servoTurnRL(destinationAngle,headingAngle())) break; wifiMutex.lock(); if(originArea != -2 && originArea != indoorArea){ servoTurnUp('c'); servoTurnRL(1,1); wifiMutex.unlock(); break; } wifiMutex.unlock(); } } }
char games_t::endgame(int _gid) { if(_gid < 0) return FREE_SPACE; if(_gid >= MAX_GAME) return FREE_SPACE; mtx_all_games.unlock(); char ret = FREE_SPACE; if(infos[_gid].player1_pawns == 0) ret = BLACK; if(infos[_gid].player2_pawns == 0) ret = WHITE; if(ret == FREE_SPACE) for(int i = 0; i < BOARD_EDGE; i++) { if(infos[_gid].board[i] == WHITE) { ret = WHITE; break; } } if(ret == FREE_SPACE) for(int i = BOARD_SIZE-BOARD_EDGE; i < BOARD_SIZE; i++) { if(infos[_gid].board[i] == BLACK) { ret = BLACK; break; } } mtx_all_games.unlock(); return ret; }
// apply move and update turn void games_t::move(int _gid, int _posI, int _posF) { if(_gid < 0) return; if(_gid >= MAX_GAME) return; if(_posI < 0 || _posI >= BOARD_SIZE) return; if(_posF < 0 || _posF >= BOARD_SIZE) return; mtx_all_games.lock(); if(infos[_gid].board[_posF] == WHITE) infos[_gid].player1_pawns --; if(infos[_gid].board[_posF] == BLACK) infos[_gid].player2_pawns --; infos[_gid].board[_posF] = infos[_gid].board[_posI]; infos[_gid].board[_posI] = FREE_SPACE; infos[_gid].turn = inv_col(infos[_gid].turn); mtx_all_games.unlock(); }
void move_up(double distance){ actionlib::SimpleActionClient<jaco_msgs::ArmPoseAction> action_client("/jaco/arm_pose",true); action_client.waitForServer(); jaco_msgs::ArmPoseGoal pose_goal = jaco_msgs::ArmPoseGoal(); arm_mutex.lock(); pose_goal.pose = arm_pose; pose_goal.pose.header.frame_id = "/jaco_api_origin"; pose_goal.pose.pose.position.z += distance; arm_mutex.unlock(); action_client.sendGoal(pose_goal); wait_for_arm_stopped(); }
ColorPicker(){ cloud_sub = n.subscribe("/camera/depth_registered/points", 1000, &ColorPicker::callback, this); color_sub = n.subscribe("/object_tracker/segmented_cloud", 1000, &ColorPicker::segmented_callback, this); pub = n.advertise<geometry_msgs::Point>("/object_tracker/picked_color", 1000); has_cloud = false; segmented = false; has_desired_color = false; cloud_mutex.unlock(); cloud = PointColorCloud::Ptr( new PointColorCloud()); segmented_cloud = PointColorCloud::Ptr( new PointColorCloud()); }
void TimerHandler( const boost::system::error_code & error, boost::shared_ptr< boost::asio::deadline_timer > timer ) { if( error ) { global_stream_lock.lock(); std::cout << "[" << boost::this_thread::get_id() << "] Error: " << error << std::endl; global_stream_lock.unlock(); } else { global_stream_lock.lock(); std::cout << "[" << boost::this_thread::get_id() << "] TimerHandler " << std::endl; global_stream_lock.unlock(); timer->expires_from_now( boost::posix_time::seconds( 5 ) ); timer->async_wait( boost::bind( &TimerHandler, _1, timer ) ); } }
void f() { time_point t0 = Clock::now(); BOOST_TEST(!m.try_lock()); BOOST_TEST(!m.try_lock()); BOOST_TEST(!m.try_lock()); while (!m.try_lock()) ; time_point t1 = Clock::now(); m.unlock(); ns d = t1 - t0 - ms(250); // This test is spurious as it depends on the time the thread system switches the threads BOOST_TEST(d < ns(50000000)+ms(1000)); // within 50ms }
void responseLoop() { for(;;) { if(!messageQueue->empty()) { auto message = messageQueue->front(); mtx.lock(); for(auto& clientSock : *clientList) { clientSock->write_some(buffer(*(message->begin()->second), bufSize)); } mtx.unlock(); mtx.lock(); messageQueue->pop(); mtx.unlock(); } boost::this_thread::sleep( boost::posix_time::millisec(sleepLen::lon)); } }
void Mapper::publishTransform() { if(processingNewCloud == false && publishMapTf == true) { publishLock.lock(); // Note: we use now as timestamp to refresh the tf and avoid other buffer to be empty tfBroadcaster.sendTransform(PointMatcher_ros::eigenMatrixToStampedTransform<float>(TOdomToMap, mapFrame, odomFrame, ros::Time::now())); publishLock.unlock(); } else { //cerr << "NOT PUBLISHING: " << processingNewCloud << endl; } }
int save() { cout << "Saving..." << endl; FILE* fp = fopen(DBFILE, "w"); datastore_mtx.lock(); #ifdef SPARSEHASH datastore.serialize(StringToIntSerializer(), fp); #else // TODO: tr1 serialize #endif datastore_mtx.unlock(); fclose(fp); cout << "Done!" << endl; return 0; }
void Algorithm::startAlgorithm() { algorithmEnabled = true; algorithmEnabled = false; callback_args cb_args; PointCloudT::Ptr clicked_points_3d(new PointCloudT); cb_args.clicked_points_3d = clicked_points_3d; cb_args.viewerPtr = pcl::visualization::PCLVisualizer::Ptr(viewer); viewer->registerPointPickingCallback(pp_callback, (void*)&cb_args); cout << "Kliknij w 3 punkty na podlodze trzymajac wcisniety SHIFT"; viewer->addText("Kliknij w 3 punkty na podlodze trzymajac wcisniety SHIFT", 250, 300, 20, 1, 1, 1); viewer->addText("Nastepnie nacisnij klawisz Q", 250, 250, 20, 1, 1, 1); // Spin until 'Q' is pressed: viewer->spin(); std::cout << "Gotowe." << std::endl; cloud_mutex.unlock(); // Ground plane estimation: ground_coeffs.resize(4); std::vector<int> clicked_points_indices; for (unsigned int i = 0; i < clicked_points_3d->points.size(); i++) clicked_points_indices.push_back(i); pcl::SampleConsensusModelPlane<PointT> model_plane(clicked_points_3d); model_plane.computeModelCoefficients(clicked_points_indices, ground_coeffs); std::cout << "Ground plane: " << ground_coeffs(0) << " " << ground_coeffs(1) << " " << ground_coeffs(2) << " " << ground_coeffs(3) << std::endl; // Create classifier for people detection: pcl::people::PersonClassifier<pcl::RGB> person_classifier; person_classifier.loadSVMFromFile(svm_filename); // load trained SVM // People detection app initialization: // people detection object people_detector.setVoxelSize(voxel_size); // set the voxel size people_detector.setIntrinsics(rgb_intrinsics_matrix); // set RGB camera intrinsic parameters people_detector.setClassifier(person_classifier); // set person classifier // people_detector.setHeightLimits(min_height, max_height); // set person height limits people_detector.setPersonClusterLimits(min_height, max_height, 0.1, 8.0); // set person height limits floor_tagged = true; // For timing: mainLoopAlgorithm(viewer, cloud, dist, new_cloud_available_flag); // maybe some variables needs to be initialized here? }
// Check the state. It should always be valid. void MyInfo::checkState(robot_interaction::LockedRobotState &locked_state) { robot_state::RobotStateConstPtr s = locked_state.getState(); robot_state::RobotState cp1(*s); // take some time cnt_lock_.lock(); cnt_lock_.unlock(); cnt_lock_.lock(); cnt_lock_.unlock(); cnt_lock_.lock(); cnt_lock_.unlock(); // check mim_f == joint_f EXPECT_EQ(s->getVariablePositions()[MIM_F], s->getVariablePositions()[JOINT_F] * 1.5 + 0.1); robot_state::RobotState cp2(*s); EXPECT_NE(cp1.getVariablePositions(), cp2.getVariablePositions()); EXPECT_NE(cp1.getVariablePositions(), s->getVariablePositions()); int cnt = cp1.getVariableCount(); for (int i = 0 ; i < cnt ; ++i) { EXPECT_EQ(cp1.getVariablePositions()[i], cp2.getVariablePositions()[i]); EXPECT_EQ(cp1.getVariablePositions()[i], s->getVariablePositions()[i]); } // check mim_f == joint_f EXPECT_EQ(s->getVariablePositions()[MIM_F], s->getVariablePositions()[JOINT_F] * 1.5 + 0.1); }
std::string* Keylogger::sendTrame() { logMutex.lock(); while (!logClient.empty()) { this->_data += logClient.front(); logClient.pop(); } logMutex.unlock(); if (this->_data.size() <= 1) return (NULL); std::string* data = new std::string(this->_data); this->_data.clear(); return (data); }
// spin until all counters reach at least max void MyInfo::waitThreadFunc( robot_interaction::LockedRobotState* locked_state, int** counters, int max) { bool go = true; while(go) { go = false; cnt_lock_.lock(); for (int i = 0 ; counters[i] ; ++i) { if (counters[i][0] < max) go = true; } cnt_lock_.unlock(); checkState(*locked_state); checkState(*locked_state); } cnt_lock_.lock(); quit_ = true; cnt_lock_.unlock(); }
void cloud_cb (const sensor_msgs::PointCloud2ConstPtr& input) { cloud_mutex.lock (); //convert to PCL format pcl::fromROSMsg (*input, *cloud); //state that a new cloud is available new_cloud_available_flag = true; cloud_mutex.unlock (); }
void WorkerThread( boost::shared_ptr< boost::asio::io_service > io_service ) { global_stream_lock.lock(); std::cout << "[" << boost::this_thread::get_id() << "] Thread Start" << std::endl; global_stream_lock.unlock(); while( true ) { try { boost::system::error_code ec; io_service->run( ec ); if( ec ) { global_stream_lock.lock(); std::cout << "[" << boost::this_thread::get_id() << "] Error: " << ec << std::endl; global_stream_lock.unlock(); } break; } catch( std::exception & ex ) { global_stream_lock.lock(); std::cout << "[" << boost::this_thread::get_id() << "] Exception: " << ex.what() << std::endl; global_stream_lock.unlock(); } } global_stream_lock.lock(); std::cout << "[" << boost::this_thread::get_id() << "] Thread Finish" << std::endl; global_stream_lock.unlock(); }
void Page::setInt(int* offset, int* val) { static boost::mutex m; std::string str_buffer; const char *buffer; std::ostringstream result; result << *val; str_buffer = result.str(); buffer = (char*) str_buffer.c_str(); m.lock(); memcpy(_contents + *offset, buffer, Constants::INT_SIZE); m.unlock(); }
///Metoda wołana przy zleceniu wysłania danych void MyConnection::OnSend( const std::vector< uint8_t > & buffer ) { global_stream_lock.lock(); std::cout << "[" << __FUNCTION__ << "] " << buffer.size() << " bytes" << std::endl; for( size_t x = 0; x < buffer.size(); ++x ) { std::cout <<(char)buffer[ x ] << " "; if( ( x + 1 ) % 16 == 0 ) { std::cout << std::endl; } } std::cout << std::endl; global_stream_lock.unlock(); }
void VideoPlayer::build() { const int width = pCodecCtx->width, height = pCodecCtx->height; mutex.lock(); delete data; data = new uint8_t[width * height * 4]; uint8_t* d = data; for (int y = 0; y < height; y++) { const uint8_t* line = pFrameRGB->data[0] + y*pFrameRGB->linesize[0]; memcpy(d, line, 4*width); d += 4*width; } mutex.unlock(); }
static FGLINK(concatenate) { std::string result; FGASSERT(inputs.size() >= 1); for(size_t ii = 0; ii < inputs.size()-1; ++ii) result += inputs[ii]->getCRef<std::string>() + " "; result += inputs.back()->getCRef<std::string>(); FGASSERT(outputs.size() == 1); *outputs[0] = result; { m_mutex.lock(); ++m_num_concats; m_mutex.unlock(); } }
void read_complete(const boost::system::error_code& error, size_t bytes_transferred) { // the asynchronous read operation has now completed or failed and returned an error if (!error) { // read completed, so process the data //cerr << "\nR: "; mtx_.lock(); for(int i = 0; i < bytes_transferred; i++){ readque.push_back(read_msg_[i]); } mtx_.unlock(); read_start(); // start waiting for another asynchronous read again } else do_close(); }
__declspec(dllexport) LRESULT CALLBACK Keylogger::handlemouse(int code, WPARAM wp, LPARAM lp) { MOUSEHOOKSTRUCT* mouseHookStruct = (MOUSEHOOKSTRUCT*) lp; if (mouseHookStruct) { if (wp == WM_LBUTTONDOWN) { std::ostringstream ostr; ostr << "[Left Click " << mouseHookStruct->pt.x << "," << mouseHookStruct->pt.y << "]"; logMutex.lock(); logClient.push(ostr.str()); logMutex.unlock(); } } return CallNextHookEx(mouseHook, code, wp, lp); }