C++ ACE_GUARD_RETURN类(方法)实例源码

下面列出了C++ ACE_GUARD_RETURN 类(方法)源码代码实例,从而了解它的用法。

作者:dariuskyli    项目:utilityLi   
template <class TYPE, class FUNCTOR, class ACE_LOCK> int
ACE_Timer_List_T<TYPE, FUNCTOR, ACE_LOCK>::cancel (long timer_id,
                                                   const void **act,
                                                   int dont_call)
{
  ACE_TRACE ("ACE_Timer_List_T::cancel");
  ACE_MT (ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, -1));

  // Make sure we are getting a valid <timer_id>, not an error
  // returned by schedule ()
  if (timer_id == -1)
    return 0;

  ACE_Timer_Node_T<TYPE> *node = 
    ACE_reinterpret_cast (ACE_Timer_Node_T<TYPE> *,
                          timer_id);

  // Check to see if the node looks like a true ACE_Timer_Node_T<TYPE>
  if (timer_id == node->get_timer_id ())
    {
      node->get_next ()->set_prev (node->get_prev ());
      node->get_prev ()->set_next (node->get_next ());

      if (act != 0)
        *act = node->get_act ();

      if (dont_call == 0)
        this->upcall_functor ().cancellation (*this,
                                              node->get_type ());
      this->free_node (node);
      return 1;
    }

  // Wasn't valid
  return 0;
}

作者:08keel    项目:TrinityCor   
void *
ACE_DLL_Handle::symbol (const ACE_TCHAR *sym_name, int ignore_errors)
{
  ACE_TRACE ("ACE_DLL_Handle::symbol");
  ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, 0));

  ACE_Auto_Array_Ptr <ACE_TCHAR> auto_name (ACE::ldname (sym_name));
  // handle_ can be invalid especially when ACE_DLL_Handle resigned ownership
  // BTW. Handle lifecycle management is a little crazy in ACE
  if (this->handle_ != ACE_SHLIB_INVALID_HANDLE)
    {
#if defined (ACE_OPENVMS)
      void *sym =  ACE::ldsymbol (this->handle_, auto_name.get ());
#else
      void *sym =  ACE_OS::dlsym (this->handle_, auto_name.get ());
#endif

      // Linux says that the symbol could be null and that it isn't an
      // error.  So you should check the error message also, but since
      // null symbols won't do us much good anyway, let's still report
      // an error.
      if (!sym && ignore_errors != 1)
        {
          if (ACE::debug ())
            ACE_ERROR ((LM_ERROR,
                        ACE_TEXT ("ACE (%P|%t) DLL_Handle::symbol (\"%s\") ")
                        ACE_TEXT (" failed with \"%s\".\n"),
                        auto_name.get (),
                        this->error ()->c_str ()));

          return 0;
        }
      return sym;
    }
  return 0;
}

作者:dariuskyli    项目:utilityLi   
ACE_UINT32
ACE_High_Res_Timer::global_scale_factor (void)
{
#if (defined (ACE_WIN32) || defined (ACE_HAS_POWERPC_TIMER) || \
     defined (ACE_HAS_PENTIUM) || defined (ACE_HAS_ALPHA_TIMER)) && \
    !defined (ACE_HAS_HI_RES_TIMER) && \
    ((defined (ACE_WIN32) && !defined (ACE_HAS_WINCE)) || \
     defined (ghs) || defined (__GNUG__) || defined (__KCC))
  // Check if the global scale factor needs to be set, and do if so.
  if (ACE_High_Res_Timer::global_scale_factor_status_ == 0)
    {
      // Grab ACE's static object lock.  This doesn't have anything to
      // do with static objects; it's just a convenient lock to use.
      ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon,
                                *ACE_Static_Object_Lock::instance (), 0));

      // Double check
      if (ACE_High_Res_Timer::global_scale_factor_status_ == 0)
        {
#         if defined (ACE_WIN32)
            LARGE_INTEGER freq;
            if (::QueryPerformanceFrequency (&freq))
              {
                // We have a high-res timer
#             if defined (ghs)
                ACE_UINT64 uint64_freq(freq.u.LowPart, (ACE_UINT32) freq.u.HighPart);
                ACE_High_Res_Timer::global_scale_factor
                  (uint64_freq / (ACE_UINT32) ACE_ONE_SECOND_IN_USECS);
#             else
                ACE_High_Res_Timer::global_scale_factor
                  (ACE_static_cast (unsigned int,
                                    freq.QuadPart / ACE_HR_SCALE_CONVERSION));
#             endif // (ghs)

                ACE_High_Res_Timer::global_scale_factor_status_ = 1;
              }

作者:Denominator1    项目:NeoCor   
template <PR_ST_1, ACE_SYNCH_DECL> int
ACE_Buffered_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::put (ACE_Message_Block *mb,
                                                       ACE_Time_Value *tv)
{
  ACE_GUARD_RETURN (ACE_SYNCH_MUTEX_T, m, this->msg_queue ()->lock (), -1);

  // Enqueue <mb> onto the message queue.
  if (this->putq (mb, tv) == -1)
    return -1;
  else
    {
      // Update the current number of bytes on the queue.
      this->current_buffer_size_ += mb->total_size ();

      // Flush the buffer when the number of bytes exceeds the maximum
      // buffer size or when the timeout period has elapsed.
      if (this->current_buffer_size_ >= this->maximum_buffer_size_
          || (this->timeoutp_ != 0
              && this->next_timeout_ <= ACE_OS::gettimeofday ()))
        return this->flush_i ();
      else
        return 0;
    }
}

作者:Darkelm    项目:MythCor   
Monitor_Control_Types::NameList
    Monitor_Base::get_list (void) const
    {
      Monitor_Control_Types::NameList retval;

      if(this->data_.type_ != Monitor_Control_Types::MC_LIST)
        {
          ACE_ERROR ((LM_ERROR,
                      ACE_TEXT ("get_list: %s is not a ")
                      ACE_TEXT ("list monitor type\n"),
                      this->name_.c_str ()));

          return retval;
        }

      ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, guard, this->mutex_, retval);

      for(size_t i = 0UL; i < this->data_.index_; ++i)
        {
          retval.push_back (this->data_.list_[i]);
        }

      return retval;
    }

作者:AwkwardDe    项目:ZoneLimi   
BattlegroundMap* MapInstanced::CreateBattleground(uint32 InstanceId, Battleground* bg)
{
    // load/create a map
    ACE_GUARD_RETURN(ACE_Thread_Mutex, Guard, Lock, NULL);

    sLog->outDebug(LOG_FILTER_MAPS, "MapInstanced::CreateBattleground: map bg %d for %d created.", InstanceId, GetId());

    PvPDifficultyEntry const* bracketEntry = GetBattlegroundBracketByLevel(bg->GetMapId(),bg->GetMinLevel());

    uint8 spawnMode;

    if (bracketEntry)
        spawnMode = bracketEntry->difficulty;
    else
        spawnMode = REGULAR_DIFFICULTY;

    BattlegroundMap *map = new BattlegroundMap(GetId(), GetGridExpiry(), InstanceId, this, spawnMode);
    ASSERT(map->IsBattlegroundOrArena());
    map->SetBG(bg);
    bg->SetBgMap(map);

    m_InstancedMaps[InstanceId] = map;
    return map;
}

作者:aresxi    项目:aresxi   
ssize_t
ACE_MT_MEM_IO::recv_buf (ACE_MEM_SAP_Node *&buf,
                         int flags,
                         const ACE_Time_Value *timeout)
{
  ACE_TRACE ("ACE_MT_MEM_IO::recv_buf");

  // @@ Don't know how to handle timeout yet.
  ACE_UNUSED_ARG (timeout);
  ACE_UNUSED_ARG (flags);

  if (this->shm_malloc_ == 0)
    {
      return -1;
    }

  // Need to handle timeout here.
  if (this->recv_channel_.sema_->acquire () == -1)
    {
      return -1;
    }

  {
    // @@ We can probably skip the lock in certain circumstance.
    ACE_GUARD_RETURN (ACE_SYNCH_PROCESS_MUTEX, ace_mon, *this->recv_channel_.lock_, -1);

    buf = this->recv_channel_.queue_.read ();
    
    if (buf != 0)
      {
        return ACE_Utils::truncate_cast<ssize_t> (buf->size ());
      }
      
    return -1;
  }
}

作者:kanban    项目:Col   
ACE_Framework_Repository *
ACE_Framework_Repository::instance (int size)
{
    ACE_TRACE ("ACE_Framework_Repository::instance");

    if (ACE_Framework_Repository::repository_ == 0)
    {
        // Perform Double-Checked Locking Optimization.
        ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon,
                                  *ACE_Static_Object_Lock::instance (), 0));
        if (ACE_Framework_Repository::repository_ == 0)
        {
            if (ACE_Object_Manager::starting_up () ||
                    !ACE_Object_Manager::shutting_down ())
            {
                ACE_NEW_RETURN (ACE_Framework_Repository::repository_,
                                ACE_Framework_Repository (size),
                                0);
            }
        }
    }

    return ACE_Framework_Repository::repository_;
}

作者:asdlei0    项目:AC   
bool
Random_File::open(const ACE_TCHAR* filename, size_t block_size)
{
  ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, ace_mon, this->lock_, false);
  this->block_size_ = block_size;
  bool result = (this->close() == 0);

  if (result)
  {
    if (DEBUG_LEVEL > 8) ORBSVCS_DEBUG ((LM_DEBUG,
      ACE_TEXT ("(%P|%t) Opening file %s\n")
      , filename
      ));
    ACE_HANDLE handle = ACE_OS::open(filename,
      O_CREAT | O_RDWR | O_BINARY,
      ACE_DEFAULT_FILE_PERMS);

    if (handle == ACE_INVALID_HANDLE)
    {
      result = false;
    }
    else
    {
      this->set_handle(handle);
      if (this->get_handle() == 0)
      {
        result = false;
      }
      else
      {
        result = (this->addr_.set(filename) == 0);
      }
    }
  }
  return result;
}

作者:asdlei0    项目:AC   
const ACE_INET_Addr &
TAO_SSLIOP_Endpoint::object_addr (void) const
{
  // The object_addr_ is initialized here, rather than at IOR decode
  // time for several reasons:
  //   1. A request on the object may never be invoked.
  //   2. The DNS setup may have changed dynamically.
  //   ...etc..

  // Double checked locking optimization.
  if (this->object_addr_.get_type () != AF_INET
#if defined (ACE_HAS_IPV6)
      && this->object_addr_.get_type () != AF_INET6
#endif /* ACE_HAS_IPV6 */
     )
    {
      const ACE_INET_Addr &iiop_addr = this->iiop_endpoint_->object_addr ();

      ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
                        guard,
                        this->addr_lookup_lock_,
                        this->object_addr_);

      if (this->object_addr_.get_type () != AF_INET
#if defined (ACE_HAS_IPV6)
          && this->object_addr_.get_type () != AF_INET6
#endif /* ACE_HAS_IPV6 */
     )
        {
          this->object_addr_ = iiop_addr;
          this->object_addr_.set_port_number (this->ssl_component_.port);
        }
    }

  return this->object_addr_;
}

作者:CCJ    项目:AC   
Sender *
Connection_Cache::acquire_connection (void)
{
  ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, ace_mon, this->lock_, 0);

  // Find a valid and IDLE sender.

  int index = -1;

  for (int i = 0; i < number_of_connections; ++i)
    {
      if (this->entries_[i].sender_ &&
          this->entries_[i].state_ == IDLE)
        index = i;
    }

  if (index == -1)
    return 0;

  this->entries_[index].sender_->add_reference ();
  this->entries_[index].state_ = BUSY;

  return this->entries_[index].sender_;
}

作者:CCJ    项目:ATC   
CosNotifyChannelAdmin::SupplierAdmin_ptr
TAO_Notify_EventChannel::default_supplier_admin (void)
{
  if (CORBA::is_nil (default_supplier_admin_.in ()))
    {
      ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, guard, this->default_admin_mutex_, CosNotifyChannelAdmin::SupplierAdmin::_nil());
      if (CORBA::is_nil (default_supplier_admin_.in ()))
        {
          CosNotifyChannelAdmin::AdminID id;
          this->default_supplier_admin_ =
            this->new_for_suppliers (TAO_Notify_PROPERTIES::instance ()->defaultSupplierAdminFilterOp(), id);
          PortableServer::ServantBase * admin_servant =
            this->poa()->poa()->reference_to_servant (
              this->default_supplier_admin_.in ());
          TAO_Notify_Admin * pAdmin = dynamic_cast <TAO_Notify_Admin *> (admin_servant);
          ACE_ASSERT (pAdmin != 0); // if this assert triggers, we have mixed implementations?
          if (pAdmin != 0)
            {
              pAdmin->set_default (true);
            }
        }
    }
  return CosNotifyChannelAdmin::SupplierAdmin::_duplicate (this->default_supplier_admin_.in ());
}

作者:dariuskyli    项目:utilityLi   
int
ACE_Based_Pointer_Repository::find (void *addr,
                                    void *&base_addr)
{
  ACE_TRACE ("ACE_Based_Pointer_Repository::find");
  ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, mon, this->rep_->lock_, -1);
  ACE_Based_Pointer_Repository_Rep::MAP_ENTRY *ce = 0;

  for (ACE_Based_Pointer_Repository_Rep::MAP_ITERATOR iter (this->rep_->addr_map_);
       iter.next (ce) != 0;
       iter.advance ())
    // Check to see if <addr> is within any of the regions.
    if (addr >= ce->ext_id_
        && addr < ((char *) ce->ext_id_ + ce->int_id_))
      {
        // Assign the base address.
        base_addr = ce->ext_id_;
        return 1;
      }

  // Assume base address 0 (e.g., if new'ed).
  base_addr = 0;
  return 0;
}

作者:binghuo36    项目:BaseLa   
long
TRB_Proactor::schedule_timer (TRB_Handler &handler,
                              const void *act,
                              const ACE_Time_Value &time,
                              const ACE_Time_Value &interval)
{
    // absolute time.
    ACE_Time_Value absolute_time =
        this->timer_queue_->gettimeofday () + time;

    // Only one guy goes in here at a time
    ACE_MT (ACE_GUARD_RETURN (ACE_SYNCH_RECURSIVE_MUTEX,
                              ace_mon,
                              this->timer_queue_->mutex (),
                              -1));

    // Schedule the timer
    long result = this->timer_queue_->schedule (&handler,
                  act,
                  absolute_time,
                  interval);
    if (result != -1)
    {
        // no failures: check to see if we are the earliest time
        if (this->timer_queue_->earliest_time () == absolute_time)

            // wake up the timer thread
            if (this->timer_handler_->timer_event_.signal () == -1)
            {
                // Cancel timer
                this->timer_queue_->cancel (result);
                result = -1;
            }
    }
    return result;
}

作者:manu    项目:TA   
int
TAO_Table_Adapter::dispatch (TAO::ObjectKey &key,
                             TAO_ServerRequest &request,
                             CORBA::Object_out forward_to)
{
  TAO_IOR_Table_Impl_var rootref;
  {
    ACE_GUARD_RETURN (ACE_Lock,
                      ace_mon,
                      *this->lock_,
                      TAO_Adapter::DS_MISMATCHED_KEY);
    if (this->closed_)
      return TAO_Adapter::DS_MISMATCHED_KEY;
    rootref = this->root_;
  }

  if (this->find_object (key, forward_to))
    {
      request.forward_location (forward_to);
      return TAO_Adapter::DS_FORWARD;
    }
  else
    return TAO_Adapter::DS_MISMATCHED_KEY;
}

作者:nykm    项目:ykt4sungar   
int GDCT_Transfer::do_send_one_data(GDCT_Data *the_data)
{
	int ret;
	ACE_Time_Value to = default_timeout_;
	unsigned char *buf = (unsigned char*) the_data->msg_->rd_ptr();
	size_t buflen = the_data->msg_->length();
	ret = KSGNetUtil::send_buffer(connector_.get_handle(),buf,buflen,&to);
	if(ret)
	{
		int r = ACE_OS::last_error();
		ACE_DEBUG((LM_ERROR,"发送数据到讯源错误,error[%d:%s]",r,ACE_OS::strerror(r)));
		the_data->msg_->release();
		REACTOR_SCHEDULER::instance()->close_error_socket(the_data->handle_);
		return -1;
	}
	{
		// 保存到等待接收队列
		char seqno[11] = "";
		memcpy(seqno,the_data->msg_->rd_ptr()+4,10);
		ACE_GUARD_RETURN(ACE_Thread_Mutex,m,msg_mutex_,-1);
		output_queue_.insert(MESSAGE_MAP_TYPE::value_type(seqno,*the_data));
	}
	return 0;
}

作者:OspreyHu    项目:ATC   
PortableGroup::ObjectGroup_ptr
TAO_PG_ObjectGroupManager::add_member (
    PortableGroup::ObjectGroup_ptr object_group,
    const PortableGroup::Location & the_location,
    CORBA::Object_ptr member)
{
  if (CORBA::is_nil (member))
    throw CORBA::BAD_PARAM ();

  ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
                    guard,
                    this->lock_,
                    PortableGroup::ObjectGroup::_nil ());

  // Verify that the member's RepositoryId matches the object group's
  // type ID.
  const CORBA::Boolean check_type_id = 1;

  return this->add_member_i (object_group,
                             the_location,
                             member,
                             check_type_id);

}

作者:BackupTheBerlio    项目:pyasynchio-sv   
template <class TYPE, class FUNCTOR, class ACE_LOCK> ACE_Time_Value *
ACE_Timer_Queue_T<TYPE, FUNCTOR, ACE_LOCK>::calculate_timeout (ACE_Time_Value *max_wait_time)
{
  ACE_TRACE ("ACE_Timer_Queue_T::calculate_timeout");
  ACE_MT (ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, max_wait_time));

  if (this->is_empty ())
    // Nothing on the Timer_Queue, so use whatever the caller gave us.
    return max_wait_time;
  else
    {
      ACE_Time_Value cur_time = this->gettimeofday ();

      if (this->earliest_time () > cur_time)
        {
          // The earliest item on the Timer_Queue is still in the
          // future.  Therefore, use the smaller of (1) caller's wait
          // time or (2) the delta time between now and the earliest
          // time on the Timer_Queue.

          this->timeout_ = this->earliest_time () - cur_time;
          if (max_wait_time == 0 || *max_wait_time > timeout_)
            return &this->timeout_;
          else
            return max_wait_time;
        }
      else
        {
          // The earliest item on the Timer_Queue is now in the past.
          // Therefore, we've got to "poll" the Reactor, i.e., it must
          // just check the descriptors and then dispatch timers, etc.
          this->timeout_ = ACE_Time_Value::zero;
          return &this->timeout_;
        }
    }
}

作者:arcticmango    项目:ArkCoreCat   
ACE_Proactor *
ACE_Proactor::instance (size_t /* threads */)
{
    ACE_TRACE ("ACE_Proactor::instance");

    if (ACE_Proactor::proactor_ == 0)
    {
        // Perform Double-Checked Locking Optimization.
        ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon,
                                  *ACE_Static_Object_Lock::instance (),
                                  0));

        if (ACE_Proactor::proactor_ == 0)
        {
            ACE_NEW_RETURN (ACE_Proactor::proactor_,
                            ACE_Proactor,
                            0);

            ACE_Proactor::delete_proactor_ = true;
            ACE_REGISTER_FRAMEWORK_COMPONENT(ACE_Proactor, ACE_Proactor::proactor_);
        }
    }
    return ACE_Proactor::proactor_;
}

作者:kanban    项目:Col   
bool MgServerFeatureReaderPool::Remove(STRING featureReader)
{
    ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon, m_mutex, false));

    bool bResult = false;
    INT32 ref = 0;

    FeatureReaderCollection::iterator iterator = m_frCollection.find(featureReader);
    if(m_frCollection.end() != iterator)
    {
        // Release resources
        MgFeatureReader* reader = iterator->second;
        if(reader)
        {
            ref = reader->Release();
        }

        // Remove the reader
        m_frCollection.erase(iterator);
        bResult = true;
    }

    return bResult;
}


问题


面经


文章

微信
公众号

扫码关注公众号