Exemplo n.º 1
0
inline void spawn(
  spawn_type spw,
  actor<stackless>& sire, match_t func, SpawnHandler h,
  match_t ctxid = ctxid_nil,
  link_type type = no_link,
  std::size_t stack_size = default_stacksize(),
  seconds_t tmo = seconds_t(GCE_DEFAULT_REQUEST_TIMEOUT_SEC)
  )
{
  aid_t aid;
  sid_t sid = sire.spawn(spw, func, ctxid, stack_size);
  boost::uint16_t err = 0;
  sid_t ret_sid = sid_nil;

  duration_t curr_tmo = tmo;
  typedef boost::chrono::system_clock clock_t;
  clock_t::time_point begin_tp = clock_t::now();
  match mach(curr_tmo);
  mach.match_list_.push_back(detail::msg_spawn_ret);
  sire.recv(
    boost::bind(
      &handle_remote_spawn, _1, _2, _3,
      type, begin_tp, sid, tmo, curr_tmo, spawn_handler_t(h)
      ),
    mach
    );
}
Exemplo n.º 2
0
  actor_id spawn(actor sire, F&& f, fiber_meta meta)
  {
    // Create actor handler.
    actor_handler_t hdr(f);

    // Generate actor_id.
    auto aid = generate_actor_id();

    // Spawn an coctx.
    asev::strand_t snd(*evs_);
    auto sire_aid = sire == nullactor ? nullaid : sire.get_actor_id();
    if (sire_aid != nullaid && meta.ssire_)
    {
      snd = sire.get_strand();
    }

    snd.spawn(
      [this, sire_aid, hdr, aid](asev::corctx_t& ctx)
      {
        // Alloc fiber_actor.
        auto a = fiber_actor_pool_->get();
        // Run actor.
        a->init(aid, ctx.get_strand());
        a->run(ctx, sire_aid, std::move(hdr));
      },
      coctx::make_stacksize(meta.ssize_)
      );
    return aid;
  }
Exemplo n.º 3
0
inline void handle_remote_spawn(
  actor<stackless>& self, aid_t aid,
  message msg, link_type type,
  boost::chrono::system_clock::time_point begin_tp,
  sid_t sid, seconds_t tmo, duration_t curr_tmo,
  spawn_handler_t const& hdr
  )
{
  boost::uint16_t err = 0;
  sid_t ret_sid = sid_nil;
  msg >> err >> ret_sid;

  do
  {
    if (err != 0 || (aid && sid == ret_sid))
    {
      break;
    }

    if (tmo != infin)
    {
      duration_t pass_time = boost::chrono::system_clock::now() - begin_tp;
      curr_tmo -= pass_time;
    }

    begin_tp = boost::chrono::system_clock::now();
    match mach(curr_tmo);
    mach.match_list_.push_back(detail::msg_spawn_ret);
    self.recv(
      boost::bind(
        &handle_remote_spawn, _1, _2, _3,
        type, begin_tp, sid, tmo, curr_tmo, hdr
        ),
      mach
      );
    return;
  }
  while (false);

  detail::spawn_error error = (detail::spawn_error)err;
  if (error != detail::spawn_ok)
  {
    aid = aid_t();
  }

  if (aid)
  {
    if (type == linked)
    {
      self.link(aid);
    }
    else if (type == monitored)
    {
      self.monitor(aid);
    }
  }

  hdr(self, aid);
}
Exemplo n.º 4
0
bool manager::actualize_doors_state	( actor& actor, float const average_speed )
{
	float const radius		= average_speed*g_door_open_time + g_door_length;
	Fvector const& position	= actor.get_position();
	//check_bug_door			( );
	m_doors.nearest			( position, radius, m_nearest_doors );
	//check_bug_door			( );
	if ( m_nearest_doors.empty() && !actor.need_update() )
		return				true;

	return					actor.update_doors( m_nearest_doors, average_speed );
}
Exemplo n.º 5
0
actor operator*(actor f, actor g) {
  auto& sys = f->home_system();
  return make_actor<decorator::sequencer, actor>(
    sys.next_actor_id(), sys.node(), &sys,
    actor_cast<strong_actor_ptr>(std::move(f)),
    actor_cast<strong_actor_ptr>(std::move(g)), std::set<std::string>{});
}
Exemplo n.º 6
0
void send_message(actor& source, actor& target, const std::string& message)
{
    ac_message_t msg;
    msg.src = &source;
    msg.message = message;
    target.enqueue(msg);
}
Exemplo n.º 7
0
void renderer::animateActor(actor &character, bool isMoving)
{
	double temp[2];
		(character.animationStep > 6) ? character.animationStep = 0 : 0;
	
	switch(character.face)
	{
		case Up: 
		case UpRight: 
		case UpLeft: 
			temp[1] = .25;
			break;
		case Left: temp[1] = 0;
			break;
		case Down:
		case DownRight:
		case DownLeft: temp[1] = .75;
			break;
		case Right: temp[1] = .5;
			break;
		default:
			break;
	}
	temp[0] = double(character.animationStep)*.125;
	character.animationStep++;
	characterData[character.getID()].moveActorCoords(temp);
}
Exemplo n.º 8
0
void actor_registry::put_named(atom_value key, actor value) {
  if (value)
    value->attach_functor([=](uint32_t) {
      detail::singletons::get_actor_registry()->put_named(key, invalid_actor);
    });
  exclusive_guard guard{named_entries_mtx_};
  named_entries_.emplace(key, std::move(value));
}
Exemplo n.º 9
0
message_id local_actor::sync_send_tuple_impl(message_priority mp,
                                             const actor& dest,
                                             any_tuple&& what) {
    auto nri = new_request_id();
    if (mp == message_priority::high) nri = nri.with_high_priority();
    dest->enqueue({address(), dest, nri}, std::move(what));
    return nri.response_id();
}
Exemplo n.º 10
0
void send_as(const actor& from, message_priority prio,
             const channel& to, Ts&&... xs) {
  if (! to) {
    return;
  }
  message_id mid;
  to->enqueue(from.address(),
              prio == message_priority::high ? mid.with_high_priority() : mid,
              make_message(std::forward<Ts>(xs)...), nullptr);
}
Exemplo n.º 11
0
inline void handle_spawn(
  actor<stackless>& self, aid_t aid,
  message msg, link_type type, spawn_handler_t const& hdr
  )
{
  if (aid)
  {
    if (type == linked)
    {
      self.link(aid);
    }
    else if (type == monitored)
    {
      self.monitor(aid);
    }
  }

  hdr(self, aid);
}
Exemplo n.º 12
0
 void delegate(message_priority mp, const actor& dest, Ts&&... xs) {
   static_assert(sizeof...(Ts) > 0, "no message to send");
   if (! dest)
     return;
   auto mid = current_element_->mid;
   current_element_->mid = mp == message_priority::high
                            ? mid.with_high_priority()
                            : mid.with_normal_priority();
   current_element_->msg = make_message(std::forward<Ts>(xs)...);
   dest->enqueue(std::move(current_element_), host());
 }
Exemplo n.º 13
0
void local_actor::forward_message(const actor& dest, message_priority prio) {
  if (!dest) {
    return;
  }
  auto id = (prio == message_priority::high)
              ? m_current_node->mid.with_high_priority()
              : m_current_node->mid.with_normal_priority();
  dest->enqueue(m_current_node->sender, id, m_current_node->msg, host());
  // treat this message as asynchronous message from now on
  m_current_node->mid = invalid_message_id;
}
Exemplo n.º 14
0
message_id local_actor::sync_send_tuple_impl(message_priority mp,
                                             const actor& dest,
                                             any_tuple&& what) {
    if (!dest) {
        throw std::invalid_argument("cannot send synchronous message "
                                    "to invalid_actor");
    }
    auto nri = new_request_id();
    if (mp == message_priority::high) nri = nri.with_high_priority();
    dest->enqueue({address(), dest, nri}, std::move(what), m_host);
    return nri.response_id();
}
Exemplo n.º 15
0
message_id local_actor::timed_sync_send_tuple_impl(message_priority mp,
                                                   const actor& dest,
                                                   const util::duration& rtime,
                                                   any_tuple&& what) {
    auto nri = new_request_id();
    if (mp == message_priority::high) nri = nri.with_high_priority();
    dest->enqueue({address(), dest, nri}, std::move(what));
    auto rri = nri.response_id();
    get_scheduler()->delayed_send({address(), this, rri}, rtime,
                                  make_any_tuple(sync_timeout_msg{}));
    return rri;
}
Exemplo n.º 16
0
 static void echo(actor<stackful>& self)
 {
   try
   {
     while (true)
     {
       message msg;
       aid_t sender = self.recv(msg);
       match_t type = msg.get_type();
       if (type == atom("echo"))
       {
         self.send(sender, msg);
       }
       else
       {
         break;
       }
     }
   }
   catch (std::exception& ex)
   {
     std::cerr << "echo except: " << ex.what() << std::endl;
   }
 }
Exemplo n.º 17
0
inline void spawn(
  stackless,
  actor<stackless>& sire, F f, SpawnHandler h,
  cache_pool* user, link_type type, std::size_t stack_size
  )
{
  user->get_strand().post(
    boost::bind(
      &detail::make_stackless_actor,
      sire.get_aid(), user,
      make_actor_func<stackless>(f), stack_size
      )
    );

  match mach;
  mach.match_list_.push_back(detail::msg_new_actor);
  sire.recv(
    boost::bind(
      &handle_spawn, _1, _2, _3,
      type, spawn_handler_t(h)
      ),
    mach
    );
}
Exemplo n.º 18
0
message_id local_actor::timed_sync_send_tuple_impl(message_priority mp,
                                                   const actor& dest,
                                                   const util::duration& rtime,
                                                   any_tuple&& what) {
    if (!dest) {
        throw std::invalid_argument("cannot send synchronous message "
                                    "to invalid_actor");
    }
    auto nri = new_request_id();
    if (mp == message_priority::high) nri = nri.with_high_priority();
    dest->enqueue({address(), dest, nri}, std::move(what), m_host);
    auto rri = nri.response_id();
    get_scheduling_coordinator()->delayed_send({address(), this, rri}, rtime,
                                  make_any_tuple(sync_timeout_msg{}));
    return rri;
}
Exemplo n.º 19
0
message_id local_actor::timed_sync_send_tuple_impl(message_priority mp,
                                                   const actor& dest,
                                                   const duration& rtime,
                                                   message&& what) {
  if (!dest) {
    throw std::invalid_argument(
      "cannot send synchronous message "
      "to invalid_actor");
  }
  auto nri = new_request_id();
  if (mp == message_priority::high) {
    nri = nri.with_high_priority();
  }
  dest->enqueue(address(), nri, std::move(what), host());
  auto rri = nri.response_id();
  auto sched_cd = detail::singletons::get_scheduling_coordinator();
  sched_cd->delayed_send(rtime, address(), this, rri,
                         make_message(sync_timeout_msg{}));
  return rri;
}
Exemplo n.º 20
0
 /// Removes a monitor from `whom`.
 inline void demonitor(const actor& whom) {
   demonitor(whom.address());
 }
Exemplo n.º 21
0
 /**
  * Sends an exit message to `whom`.
  */
 inline void send_exit(const actor& whom, uint32_t reason) {
   send_exit(whom.address(), reason);
 }
Exemplo n.º 22
0
// utility function to print an exit message with custom name
void print_on_exit(const actor& ptr, const std::string& name) {
  ptr->attach_functor([=](uint32_t reason) {
    aout(ptr) << name << " exited with reason " << reason << endl;
  });
}
Exemplo n.º 23
0
// utility function to print an exit message with custom name
void print_on_exit(const actor& hdl, const std::string& name) {
  hdl->attach_functor([=](abstract_actor* ptr, uint32_t reason) {
    aout(ptr) << name << " exited with reason " << reason << endl;
  });
}
Exemplo n.º 24
0
static bool operator==(actor const& lhs, actor const& rhs)
{
    return lhs.get_actor() == rhs.get_actor();
}
Exemplo n.º 25
0
void actor_ostream::redirect(const actor& src, std::string f, int flags) {
  send_as(src, detail::singletons::get_scheduling_coordinator()->printer(),
          redirect_atom::value, src.address(), std::move(f), flags);
}