• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ scoped_lock函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中scoped_lock函数的典型用法代码示例。如果您正苦于以下问题:C++ scoped_lock函数的具体用法?C++ scoped_lock怎么用?C++ scoped_lock使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了scoped_lock函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: scoped_lock

  void GazeboRosSkidSteerDrive::cmdVelCallback(
      const geometry_msgs::Twist::ConstPtr& cmd_msg) {

    boost::mutex::scoped_lock scoped_lock(lock);
    x_ = cmd_msg->linear.x;
    rot_ = cmd_msg->angular.z;
  }
开发者ID:team-diana,项目名称:gazebo_ros_pkgs,代码行数:7,代码来源:gazebo_ros_skid_steer_drive.cpp


示例2: ensure_connection

int swd::database::save_parameter(const int& request_id, const std::string& path,
 const std::string& value, const int& total_whitelist_rules,
 const int& critical_impact, const int& threat) {
    ensure_connection();

    boost::unique_lock<boost::mutex> scoped_lock(dbi_mutex_);

    char *path_esc = strdup(path.c_str());
    dbi_conn_quote_string(conn_, &path_esc);

    char *value_esc = strdup(value.c_str());
    dbi_conn_quote_string(conn_, &value_esc);

    dbi_result res = dbi_conn_queryf(conn_, "INSERT INTO parameters "
     "(request_id, path, value, total_whitelist_rules, critical_impact, threat) "
     "VALUES (%i, %s, %s, %i, %i, %i)", request_id, path_esc, value_esc,
     total_whitelist_rules, critical_impact, threat);

    free(path_esc);
    free(value_esc);

    if (!res) {
        throw swd::exceptions::database_exception("Can't execute parameter query");
    }

    int id = dbi_conn_sequence_last(conn_, "parameters_id_seq");

    dbi_result_free(res);

    return id;
}
开发者ID:MiauWuffMiau,项目名称:shadowd,代码行数:31,代码来源:database.cpp


示例3: scoped_lock

JNIEnv *ThingsManagerJVM::getEnv()
{
    std::unique_lock<std::mutex> scoped_lock(m_currentThreadMutex);

    if (NULL == m_jvm)
    {
        LOGE("Failed to get JVM");
        return NULL;
    }

    JNIEnv *env = NULL;
    jint ret = m_jvm->GetEnv((void **)&env, JNI_CURRENT_VERSION);
    switch (ret)
    {
        case JNI_OK:
            return env;
        case JNI_EDETACHED:
            if (0 > m_jvm->AttachCurrentThread(&env, NULL))
            {
                LOGE("Failed to attach current thread to env");
                return NULL;
            }
            return env;
        case JNI_EVERSION:
            LOGE("JNI version not supported");
        default:
            LOGE("Failed to get the environment");
            return NULL;
    }
}
开发者ID:WojciechLuczkow,项目名称:iotivity,代码行数:30,代码来源:jni_things_manager_jvm.cpp


示例4: scoped_lock

void CInfoConsole::AddLineHelper (int priority, const char *text)
{
	if (priority > verboseLevel)
		return;

	PUSH_CODE_MODE;
	ENTER_MIXED;
	boost::recursive_mutex::scoped_lock scoped_lock(infoConsoleMutex);

	char text2[50];
	if(strlen(text)>42){
		memcpy(text2,text,42);
		text2[42]=0;
	} else
		strcpy(text2,text);
	(*filelog) << text2  << "\n";
	filelog->flush();
	InfoLine l;
	if((int)data.size()>(numLines-1)){
		data[1].time+=data[0].time;
		data.pop_front();
	}
	data.push_back(l);
	data.back().text=text2;
	data.back().time=lifetime-lastTime;
	lastTime=lifetime;

	if(strlen(text)>42){
		AddLine("%s",&text[42]);
	}
	POP_CODE_MODE;
}
开发者ID:genxinzou,项目名称:svn-spring-archive,代码行数:32,代码来源:InfoConsole.cpp


示例5: scoped_lock

void EventManager::freePool(BaseEventPool* pool)
{
	boost::recursive_mutex::scoped_lock scoped_lock(mEventPoolMutex);
	
	pool->clear();
	mPoolQueue.push_back(pool);
}
开发者ID:liuyudong,项目名称:Brute-Force-Game-Engine,代码行数:7,代码来源:EventManager.cpp


示例6: scoped_lock

  // Update the controller
  void YoubotArmController::UpdateChild()
  {
    boost::mutex::scoped_lock scoped_lock(lock);

    if(cmd_mode_ == CMD_POSITION)
    {
        arm_joints_[0]->SetAngle(0, math::Angle(cmd_.q1));
        arm_joints_[1]->SetAngle(0, math::Angle(cmd_.q2));
        arm_joints_[2]->SetAngle(0, math::Angle(cmd_.q3));
        arm_joints_[3]->SetAngle(0, math::Angle(cmd_.q4));
        arm_joints_[4]->SetAngle(0, math::Angle(cmd_.q5));
    }
    else if(cmd_mode_ == CMD_VELOCITY)
    {
        arm_joints_[0]->SetVelocity(0, cmd_.q1);
        arm_joints_[1]->SetVelocity(0, cmd_.q2);
        arm_joints_[2]->SetVelocity(0, cmd_.q3);
        arm_joints_[3]->SetVelocity(0, cmd_.q4);
        arm_joints_[4]->SetVelocity(0, cmd_.q5);
    }
    else if(cmd_mode_ == CMD_TORQUE)
    {
        arm_joints_[0]->SetForce(0, cmd_.q1);
        arm_joints_[1]->SetForce(0, cmd_.q2);
        arm_joints_[2]->SetForce(0, cmd_.q3);
        arm_joints_[3]->SetForce(0, cmd_.q4);
        arm_joints_[4]->SetForce(0, cmd_.q5);
    }
  }
开发者ID:LUHbots,项目名称:luh_youbot_os,代码行数:30,代码来源:arm_controller.cpp


示例7: scoped_lock

bool
GazeboRosIMU::SetAccelBiasCallback(thinc_sim_gazebo_plugins::SetBias::Request &req, thinc_sim_gazebo_plugins::SetBias::Response &res)
{
  boost::mutex::scoped_lock scoped_lock(lock);
  accelModel.reset(math::Vector3(req.bias.x, req.bias.y, req.bias.z));
  return true;
}
开发者ID:capparell,项目名称:thinc_simulator,代码行数:7,代码来源:gazebo_ros_imu.cpp


示例8: scoped_lock

void WorkerQueue::push(ServerWorker* worker){
  //mutex lock (scoped)
  boost::mutex::scoped_lock scoped_lock(mutex);
  worker->add();
  this->workers_list.push_back(worker);

}
开发者ID:OlaJakubowicz,项目名称:porpe,代码行数:7,代码来源:WorkerQueue.cpp


示例9: scoped_lock

Config* Config::Instance(){
	boost::mutex::scoped_lock scoped_lock(instanceMutex);

	if(theSingleInstance == NULL)
			theSingleInstance = new Config();
	return theSingleInstance;
}
开发者ID:Chudovishee,项目名称:yquest,代码行数:7,代码来源:config.cpp


示例10: LogTimestampStr

void BCLog::Logger::LogPrintStr(const std::string &str)
{
    std::string strTimestamped = LogTimestampStr(str);

    if (m_print_to_console) {
        // print to console
        fwrite(strTimestamped.data(), 1, strTimestamped.size(), stdout);
        fflush(stdout);
    }
    if (m_print_to_file) {
        std::lock_guard<std::mutex> scoped_lock(m_file_mutex);

        // buffer if we haven't opened the log yet
        if (m_fileout == nullptr) {
            m_msgs_before_open.push_back(strTimestamped);
        }
        else
        {
            // reopen the log file, if requested
            if (m_reopen_file) {
                m_reopen_file = false;
                m_fileout = fsbridge::freopen(m_file_path, "a", m_fileout);
                if (!m_fileout) {
                    return;
                }
                setbuf(m_fileout, nullptr); // unbuffered
            }

            FileWriteStr(strTimestamped, m_fileout);
        }
    }
}
开发者ID:fujicoin,项目名称:fujicoin,代码行数:32,代码来源:logging.cpp


示例11: scoped_lock

    int StatsTable::FindCounter(const std::string& name)
    {
        // Note: the API returns counters numbered from 1..N, although
        // internally, the array is 0..N-1.  This is so that we can return
        // zero as "not found".
        if(!impl_)
        {
            return 0;
        }

        // Create a scope for our auto-lock.
        {
            AutoLock scoped_lock(counters_lock_);

            // Attempt to find the counter.
            CountersMap::const_iterator iter;
            iter = counters_.find(name);
            if(iter != counters_.end())
            {
                return iter->second;
            }
        }

        // Counter does not exist, so add it.
        return AddCounter(name);
    }
开发者ID:abyvaltsev,项目名称:putty-nd3.x,代码行数:26,代码来源:stats_table.cpp


示例12: OpenDebugLog

bool OpenDebugLog()
{
    boost::call_once(&DebugPrintInit, debugPrintInitFlag);
    boost::mutex::scoped_lock scoped_lock(*mutexDebugLog);

    assert(fileout == nullptr);
    assert(vMsgsBeforeOpenLog);
    fs::path pathDebug = GetDebugLogPath();

    fileout = fsbridge::fopen(pathDebug, "a");
    if (!fileout) {
        return false;
    }

    setbuf(fileout, nullptr); // unbuffered
    // dump buffered messages from before we opened the log
    while (!vMsgsBeforeOpenLog->empty()) {
        FileWriteStr(vMsgsBeforeOpenLog->front(), fileout);
        vMsgsBeforeOpenLog->pop_front();
    }

    delete vMsgsBeforeOpenLog;
    vMsgsBeforeOpenLog = nullptr;
    return true;
}
开发者ID:Bluecoreg,项目名称:bitcoin,代码行数:25,代码来源:util.cpp


示例13: scoped_lock

////////////////////////////////////////////////////////////////////////////////
// Update the controller
void GazeboPanel::Update()
{
  boost::mutex::scoped_lock scoped_lock(lock);

  if ( terminated_ )
    {
      return;
    }

  common::Time current_time = world_->GetSimTime();

  // check score
  double angle = joint_->GetAngle(0).Radian();
  if ( fmod(current_time.Double(), 1) == 0 ) {
    ROS_INFO_STREAM("Current time is " << current_time.Double() << ", Current angle is = " << angle);
  }

  // void Entity::GetNearestEntityBelow(double &_distBelow,  std::string &_entityName)
  //
  std::stringstream ss;
  std_msgs::String msg_time;
  ss << 20*60 - current_time.Double();
  msg_time.data = ss.str();
  pub_time_.publish(msg_time);
  if ( fabs(angle) > 3.14)
    {
      std_msgs::String msg_score, msg_time;
      msg_score.data = "Mission Completed";
      ROS_INFO_STREAM("Remaining time is " << msg_time.data << "[sec], Score is " << msg_score.data);
      pub_score_.publish(msg_score);
      terminated_ = true;
    }
}
开发者ID:kuri-kustar,项目名称:kuri_mbzirc_sim,代码行数:35,代码来源:mbzirc_gazebo_panel_plugin.cpp


示例14: scoped_lock

void GazeboRosCarDrive::cmdVelCallback ( const geometry_msgs::Twist::ConstPtr& cmd_msg ) {

    boost::mutex::scoped_lock scoped_lock ( lock );
    base_speed_cmd_ = cmd_msg->linear.x;
    base_omega_cmd_ = cmd_msg->angular.z;

}
开发者ID:Oflameo,项目名称:APPPRS,代码行数:7,代码来源:gazebo_ros_car_drive.cpp


示例15: scoped_lock

int CNet::SendData(unsigned char *data, int length,int connection)
{
    if(playbackDemo && !serverNet)
        return 1;

    if(length<=0)
        logOutput.Print("Errenous send length in SendData %i",length);

    Connection* c=&connections[connection];
    if(c->active) {
        if(c->localConnection) {
            boost::mutex::scoped_lock scoped_lock(netMutex);
            Connection* lc=c->localConnection;
            if(lc->readyLength+length>=NETWORK_BUFFER_SIZE) {
                logOutput.Print("Overflow when sending to local connection %i %i %i %i %i",imServer,connection,lc->readyLength,length,NETWORK_BUFFER_SIZE);
                return 0;
            }
            memcpy(&lc->readyData[lc->readyLength],data,length);
            lc->readyLength+=length;
        } else {
            if(c->outgoingLength+length>=NETWORK_BUFFER_SIZE) {
                logOutput.Print("Overflow when sending to remote connection %i %i %i %i %i",imServer,connection,c->outgoingLength,length,NETWORK_BUFFER_SIZE);
                return 0;
            }
            memcpy(&c->outgoingData[c->outgoingLength],data,length);
            c->outgoingLength+=length;
        }
    }
    return 1;
}
开发者ID:genxinzou,项目名称:svn-spring-archive,代码行数:30,代码来源:Net.cpp


示例16: scoped_lock

// ============================================================================
// AcquisitionTask::set_state
// ============================================================================
void AcquisitionTask::set_state(Tango::DevState state) 
{
    {
        yat::MutexLock scoped_lock(m_status_lock);
        m_state = state;
    }
}
开发者ID:MaxIV-KitsControls,项目名称:Lima-tango,代码行数:10,代码来源:AcquisitionTask.cpp


示例17: scoped_lock

void swd::log::open_file(std::string file) {
	/* Use mutex to avoid race conditions. */
	boost::unique_lock<boost::mutex> scoped_lock(mutex_);

	/* Set the file. */
	file_ = file;
}
开发者ID:L3V14TH4N,项目名称:shadowd,代码行数:7,代码来源:log.cpp


示例18: memcpy

//this is called all the way from the receiver threads, we should process this swiftly
//and keep in mind that it is called crazily and concurently from lots of threads
//we MUST copy the data too
//also, this function can be called by threads owning clients_mutex !!!
void Broadcaster::QueueMessage(int type, int uid, unsigned int streamid, unsigned int len, const char *data) {
    if (!m_is_running) {
        return;
    }
    queue_entry_t msg = {type, uid, streamid, len, ""};
    memcpy(msg.data, data, len);

    {
        MutexLocker scoped_lock(m_queue_mutex);
        if (m_msg_queue.empty()) {
            m_packet_drop_counter = 0;
            m_is_dropping_packets = (++m_packet_good_counter > 3) ? false : m_is_dropping_packets;
        } else if (type == RoRnet::MSG2_STREAM_DATA_DISCARDABLE) {
            auto search = std::find_if(m_msg_queue.begin(), m_msg_queue.end(), [&](const queue_entry_t& m)
                    { return m.type == RoRnet::MSG2_STREAM_DATA_DISCARDABLE && m.uid == uid && m.streamid == streamid; });
            if (search != m_msg_queue.end()) {
                // Found outdated discardable streamdata -> replace it
                (*search) = msg;
                m_packet_good_counter = 0;
                m_is_dropping_packets = (++m_packet_drop_counter > 3) ? true : m_is_dropping_packets;
                Messaging::StatsAddOutgoingDrop(sizeof(RoRnet::Header) + msg.datalen); // Statistics
                return;
            }
        }
        m_msg_queue.push_back(msg);
    }

    m_queue_cond.signal();
}
开发者ID:AnotherFoxGuy,项目名称:ror-server,代码行数:33,代码来源:broadcaster.cpp


示例19: scoped_lock

////////////////////////////////////////////////////////////////////////////////
// returns true always, imu is always calibrated in sim
bool GazeboRosIMU::ServiceCallback(std_srvs::Empty::Request &req,
                                        std_srvs::Empty::Response &res)
{
  boost::mutex::scoped_lock scoped_lock(lock);
  rateModel.reset();
  return true;
}
开发者ID:AlvarHHM,项目名称:tum_simulator,代码行数:9,代码来源:gazebo_ros_imu.cpp


示例20: scoped_lock

sp<IAppOpsService> AppOpsManager::getService()
{

    std::lock_guard<Mutex> scoped_lock(mLock);
    int64_t startTime = 0;
    sp<IAppOpsService> service = mService;
    while (service == NULL || !IInterface::asBinder(service)->isBinderAlive()) {
        sp<IBinder> binder = defaultServiceManager()->checkService(_appops);
        if (binder == NULL) {
            // Wait for the app ops service to come back...
            if (startTime == 0) {
                startTime = uptimeMillis();
                ALOGI("Waiting for app ops service");
            } else if ((uptimeMillis()-startTime) > 10000) {
                ALOGW("Waiting too long for app ops service, giving up");
                service = NULL;
                break;
            }
            sleep(1);
        } else {
            service = interface_cast<IAppOpsService>(binder);
            mService = service;
        }
    }
    return service;
}
开发者ID:MIPS,项目名称:frameworks-native,代码行数:26,代码来源:AppOpsManager.cpp



注:本文中的scoped_lock函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ scopy_函数代码示例发布时间:2022-05-30
下一篇:
C++ scopedLocker函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap