Ejemplo n.º 1
0
 value_type value_pop() {
     for (;;) {
         slot * s{ nullptr };
         std::size_t idx{ 0 };
         channel_op_status status{ try_value_pop_( s, idx) };
         if ( channel_op_status::success == status) {
             value_type value{ std::move( * reinterpret_cast< value_type * >( std::addressof( s->storage) ) ) };
             s->cycle.store( idx + capacity_, std::memory_order_release);
             not_full_cnd_.notify_one();
             return std::move( value);
         } else if ( channel_op_status::empty == status) {
             std::unique_lock< std::mutex > lk{ mtx_ };
             ++waiting_consumer_;
             if ( is_closed() ) {
                 throw std::runtime_error{ "boost fiber: channel is closed" };
             }
             if ( ! is_empty_() ) {
                 continue;
             }
             not_empty_cnd_.wait( lk, [this](){ return is_closed() || ! is_empty_(); });
             --waiting_consumer_;
         } else {
             BOOST_ASSERT( channel_op_status::closed == status);
             throw std::runtime_error{ "boost fiber: channel is closed" };
         }
     }
 }
Ejemplo n.º 2
0
 channel_op_status push( value_type const& value) {
     for (;;) {
         if ( is_closed() ) {
             return channel_op_status::closed;
         }
         channel_op_status status{ try_push_( value) };
         if ( channel_op_status::success == status) {
             std::unique_lock< std::mutex > lk{ mtx_ };
             if ( 0 < waiting_consumer_) {
                 not_empty_cnd_.notify_one();
             }
             return status;
         } else if ( channel_op_status::full == status) {
             std::unique_lock< std::mutex > lk{ mtx_ };
             if ( is_closed() ) {
                 return channel_op_status::closed;
             }
             if ( ! is_full_() ) {
                 continue;
             }
             not_full_cnd_.wait( lk, [this]{ return is_closed() || ! is_full_(); });
         } else {
             BOOST_ASSERT( channel_op_status::closed == status);
             return status;
         }
     }
 }
Ejemplo n.º 3
0
/**
 * @brief Updates the entity.
 */
void Door::update() {

  Detector::update();

  if (!initialized) {
    update_dynamic_tiles();
    initialized = true;
  }

  if (is_closed()
      && get_opening_method() == OPENING_BY_EXPLOSION
      && get_equipment().has_ability("detect_weak_walls")
      && Geometry::get_distance(get_center_point(), get_hero().get_center_point()) < 40
      && !is_suspended()
      && System::now() >= next_hint_sound_date) {
    Sound::play("cane");
    next_hint_sound_date = System::now() + 500;
  }

  if (is_changing() && get_sprite().is_animation_finished()) {
    // Toggle door_open when the changing animation finishes.
    set_open(is_opening());
  }

  if (is_saved() && !is_changing()) {
    bool open_in_savegame = get_savegame().get_boolean(savegame_variable);
    if (open_in_savegame && is_closed()) {
      set_opening();
    }
    else if (!open_in_savegame && is_open()) {
      set_closing();
    }
  }
}
Ejemplo n.º 4
0
static VALUE method_get_next_event(VALUE self, VALUE blocking) {
  // dbg.h 
  check_debug(!is_closed(self), "we are closed, not trying to get event");

  char buf[64];
  FETCH_DATA_PTR(self, zk);

  for (;;) {
    check_debug(!is_closed(self), "we're closed in the middle of method_get_next_event, bailing");

    zkrb_event_t *event = zkrb_dequeue(zk->queue, 1);

    /* Wait for an event using rb_thread_select() on the queue's pipe */
    if (event == NULL) {
      if (NIL_P(blocking) || (blocking == Qfalse)) { 
        goto error;
      } 
      else {
        // if we're shutting down, don't enter this section, we don't want to block
        check_debug(!is_shutting_down(self), "method_get_next_event, we're shutting down, don't enter blocking section");

        int fd = zk->queue->pipe_read;
        ssize_t bytes_read = 0;

        // wait for an fd to become readable, opposite of rb_thread_fd_writable
        rb_thread_wait_fd(fd);

        // clear all bytes here, we'll catch all the events on subsequent calls
        // (until we run out of events)
        bytes_read = read(fd, buf, sizeof(buf));

        if (bytes_read == -1) {
          rb_raise(rb_eRuntimeError, "read failed: %d", errno);
        }

        zkrb_debug_inst(self, "read %zd bytes from the queue (%p)'s pipe", bytes_read, zk->queue);

        continue;
      }
    }

    VALUE hash = zkrb_event_to_ruby(event);
    zkrb_event_free(event);
    return hash;
  }

  error: 
    return Qnil;
}
Ejemplo n.º 5
0
/**
 * @brief Notifies this detector that the player is interacting with it by
 * pressing the action command.
 *
 * This function is called when the player presses the action command
 * while the hero is facing this detector, and the action command effect lets
 * him do this.
 * The hero opens the door if possible, otherwise a message is shown.
 */
void Door::notify_action_command_pressed() {

  if (get_hero().is_free() && is_closed()) {

    if (can_open()) {
      Sound::play("door_unlocked");
      Sound::play("door_open");

      if (is_saved()) {
        get_savegame().set_boolean(savegame_variable, true);
      }

      if (is_opening_condition_consumed()) {
        consume_opening_condition();
      }

      set_opening();

      get_hero().check_position();
    }
    else if (!cannot_open_dialog_id.empty()) {
      Sound::play("wrong");
      get_dialog_box().start_dialog(cannot_open_dialog_id);
    }
  }
}
Ejemplo n.º 6
0
    //  发送消息
	void TCPSessionHandler::send(const NetMessage &message)
	{
		if (is_closed())
		{
			return;
		}

		if (message.empty())
		{
			return;
		}

		bool wanna_send = messages_to_be_sent_.empty();
		messages_to_be_sent_.push_back(message);

		if (wanna_send)
		{
			if (thread_id_ == io_thread_manager_->get_main_thread()->get_id())
			{
				io_thread_manager_->get_main_thread()->post(std::bind(session_handler_stuff::SendMessageListDirectly, shared_from_this()));
			}
			else
			{
				io_thread_manager_->get_main_thread()->post(std::bind(session_handler_stuff::PackMessageList, shared_from_this()));
			}
		}
	}
Ejemplo n.º 7
0
/**
 * @brief This function is called when an explosion's sprite
 * detects a pixel-perfect collision with a sprite of this entity.
 * @param explosion the explosion
 * @param sprite_overlapping the sprite of the current entity that collides with the explosion
 */
void Door::notify_collision_with_explosion(Explosion& explosion, Sprite& sprite_overlapping) {

  if (get_opening_method() == OPENING_BY_EXPLOSION
      && is_closed()) {
    set_opening();
  }
}
Ejemplo n.º 8
0
bool
AbstractTaskFactory::mutate_closed_finish_per_task_type()
{
  if (m_task.TaskSize() < 2)
    return false;

  if (!is_position_finish(m_task.TaskSize() - 1))
    return false;

  bool changed = false;

  if (get_ordered_task_behaviour().is_closed) {
    if (!is_closed()) {
      OrderedTaskPoint *tp = m_task.get_tp(m_task.TaskSize() - 1);
      assert(tp);
      if (tp->GetType() == TaskPoint::FINISH) {
        FinishPoint *fp = createFinish(m_task.get_tp(0)->GetWaypoint());
        assert(fp);
        remove(m_task.TaskSize() - 1, false);
        append(*fp, false);
        delete fp;
        changed = true;
      }
    }
  }
  return changed;
}
Ejemplo n.º 9
0
	void c_geo_linear_obj::ensure_closed(bool bclosed)
	{
		if (m_shape_pts.size() <= 2)
			return;

		gd::vertex_array pts;
		get_vertexs(pts);
		if (pts.size() <= 2)
			return;

		if (is_closed())
		{
			if (!bclosed)
			{
				pts.erase(pts.end() - 1);
				set_vertexs(pts.data(), pts.size());
			}
		}
		else
		{
			if (bclosed)
			{
				pts.push_back(pts[0]);
				set_vertexs(pts.data(), pts.size());
			}
		}
	}
Ejemplo n.º 10
0
 void Session::sleep_for( const milliseconds& delay, const function< void ( const shared_ptr< Session > ) >& callback )
 {
     auto session = shared_from_this( );
     
     if ( is_closed( ) )
     {
         const auto error_handler = m_pimpl->get_error_handler( );
         return error_handler( 500, runtime_error( "Sleep failed: session already closed." ), session );
     }
     
     m_pimpl->m_request->m_pimpl->m_socket->sleep_for( delay, [ delay, session, callback, this ]( const error_code & error )
     {
         if ( error )
         {
             const auto message = String::format( "Wait failed: %s", error.message( ).data( ) );
             const auto error_handler = m_pimpl->get_error_handler( );
             return error_handler( 500, runtime_error( message ), session );
         }
         
         if ( callback not_eq nullptr )
         {
             callback( session );
         }
     } );
 }
Ejemplo n.º 11
0
 void Session::fetch( const size_t length, const function< void ( const shared_ptr< Session >, const Bytes& ) >& callback )
 {
     auto session = shared_from_this( );
     
     if ( is_closed( ) )
     {
         const auto error_handler = m_pimpl->get_error_handler( );
         return error_handler( 500, runtime_error( "Fetch failed: session already closed." ), session );
     }
     
     if ( length > m_pimpl->m_request->m_pimpl->m_buffer->size( ) )
     {
         size_t size = length - m_pimpl->m_request->m_pimpl->m_buffer->size( );
         
         m_pimpl->m_request->m_pimpl->m_socket->start_read( m_pimpl->m_request->m_pimpl->m_buffer, size, [ this, session, length, callback ]( const error_code & error, size_t )
         {
             if ( error )
             {
                 const auto message = String::format( "Fetch failed: %s", error.message( ).data( ) );
                 const auto error_handler = m_pimpl->get_error_handler( );
                 return error_handler( 500, runtime_error( message ), session );
             }
             
             m_pimpl->fetch_body( length, session, callback );
         } );
     }
     else
     {
         m_pimpl->fetch_body( length, session, callback );
     }
 }
Ejemplo n.º 12
0
 void Session::yield( const Response& response, const function< void ( const shared_ptr< Session > ) >& callback )
 {
     auto session = shared_from_this( );
     
     if ( is_closed( ) )
     {
         const auto error_handler = m_pimpl->get_error_handler( );
         return error_handler( 500, runtime_error( "Yield failed: session already closed." ), session );
     }
     
     m_pimpl->transmit( response, [ this, session, callback ]( const error_code & error, size_t )
     {
         if ( error )
         {
             const auto message = String::format( "Yield failed: %s", error.message( ).data( ) );
             const auto error_handler = m_pimpl->get_error_handler( );
             return error_handler( 500, runtime_error( message ), session );
         }
         
         if ( callback == nullptr )
         {
             m_pimpl->m_request->m_pimpl->m_socket->start_read( m_pimpl->m_request->m_pimpl->m_buffer, "\r\n\r\n", [ this, session ]( const error_code & error, const size_t length )
             {
                 m_pimpl->m_keep_alive_callback( error, length, session );
             } );
             
             return;
         }
         else
         {
             callback( session );
         }
     } );
 }
Ejemplo n.º 13
0
 void Session::yield( const Bytes& body, const function< void ( const shared_ptr< Session > ) >& callback )
 {
     auto session = shared_from_this( );
     
     if ( is_closed( ) )
     {
         const auto error_handler = m_pimpl->get_error_handler( );
         return error_handler( 500, runtime_error( "Yield failed: session already closed." ), session );
     }
     
     m_pimpl->m_request->m_pimpl->m_socket->start_write( body, [ this, session, callback ]( const error_code & error, size_t )
     {
         if ( error )
         {
             const auto message = String::format( "Yield failed: %s", error.message( ).data( ) );
             const auto error_handler = m_pimpl->get_error_handler( );
             return error_handler( 500, runtime_error( message ), session );
         }
         
         if ( callback not_eq nullptr )
         {
             callback( session );
         }
     } );
 }
Ejemplo n.º 14
0
 void Session::close( const Response& response )
 {
     auto session = shared_from_this( );
     
     if ( is_closed( ) )
     {
         const auto error_handler = m_pimpl->get_error_handler( );
         return error_handler( 500, runtime_error( "Close failed: session already closed." ), session );
     }
     
     m_pimpl->transmit( response, [ this, session ]( const error_code & error, size_t )
     {
         if ( error )
         {
             const auto message = String::format( "Close failed: %s", error.message( ).data( ) );
             const auto error_handler = m_pimpl->get_error_handler( );
             return error_handler( 500, runtime_error( message ), session );
         }
         
         m_pimpl->m_manager->save( session, [ this ]( const shared_ptr< Session > )
         {
             m_pimpl->m_request->m_pimpl->m_socket->close( );
         } );
     } );
 }
Ejemplo n.º 15
0
	bool c_geo_linear_obj::set_vertexs(const gd::GeoVertex* pts, int npt)
	{
		if (npt >= 2)
		{
			m_shape_pts.clear();
			Curve::Curve(pts, npt, 0.01, is_closed(), m_shape_pts);
		}
		else
		{
			for (int i = 0; i < npt; i++)
			{
				m_shape_pts.push_back(pts[i]);
			}
		}

		m_vertex_indexs.clear();
		Curve::GetVertexIndex(m_shape_pts, m_vertex_indexs);

		m_shape_rects.clear();
		get_shape_rects(m_shape_pts, m_shape_rects);

		m_bound = gd::Rect3D();
		for (int i = 0; i < m_shape_rects.size(); i++)
		{
			if (i == 0)
				m_bound = m_shape_rects[i].rect;
			else
				m_bound.union_rect(m_shape_rects[i].rect);
		}

		return true;
	}
Ejemplo n.º 16
0
// the single threaded version of this call. will go away when we do direct
// event delivery (soon)
static VALUE method_zkrb_get_next_event_st(VALUE self) {
  volatile VALUE rval = Qnil;

  if (is_closed(self)) {
    zkrb_debug("we are closed, not gonna try to get an event");
    return Qnil;
  }

  FETCH_DATA_PTR(self, zk);

  zkrb_event_t *event = zkrb_dequeue(zk->queue, 0);

  if (event != NULL) {
    rval = zkrb_event_to_ruby(event);
    zkrb_event_free(event);

#if THREADED
    int fd = zk->queue->pipe_read;

    // we don't care in this case. this is just until i can remove the self
    // pipe from the queue
    char b[128];
    while(read(fd, b, sizeof(b)) == sizeof(b)){}
#endif
  }

  return rval;
}
Ejemplo n.º 17
0
int do_read(object who) {
   if (is_closed()) {
      this_player()->simple_action("$N $vtry to read a closed notebook.");
   } else {
      this_player()->simple_action("$N $vread the notebook but cannot understand the language.");
   }
   return 1;
}
Ejemplo n.º 18
0
/**
 * \brief Stop the rendering process.
 * \return false if this screen has been closed by the user.
 */
bool bear::visual::gl_screen::end_render()
{
  glFlush();
  SDL_GL_SwapBuffers();
  VISUAL_GL_ERROR_THROW();

  return !is_closed();
} // gl_screen::end_render()
Ejemplo n.º 19
0
/**
 * @brief Starts closing the door and plays the corresponding animations.
 *
 * Nothing is done if the door is already in the process of being closed.
 */
void Door::close() {

  if (is_closed() || is_closing()) {
    // The door is already closed or being closed: nothing to do.
    return;
  }

  set_closing();

  if (is_saved()) {
    get_savegame().set_boolean(savegame_variable, false);
  }
}
Ejemplo n.º 20
0
void websocket_hybi_17::frame_started(error_code err, size_t bytes_transferred)
{
	if ( is_closed(err, bytes_transferred) )
	{
		return;
	}

	if ( !check_err(err, "Frame start") ||
		 !check_err(bytes_transferred == sizeof(frame_start_), "Frame start") )
	{
		return;
	}

	payload_len_ = (frame_start_[1] & 0x7F);
	if ( payload_len_ == 126 )
	{
		uint16_t len;
		boost::asio::read(*tcp_conn_, boost::asio::buffer(&len, sizeof(len)), err);
		payload_len_ = ntohs(len);
	}
	else if ( payload_len_ == 127 )
	{
		uint64_t len = 0;
		boost::asio::read(*tcp_conn_, boost::asio::buffer(&len, sizeof(len)), err);
		payload_len_ = static_cast<size_t>(ntohll(len));
	}
	if ( !check_err(err, "Payload length") )
	{
		return;
	}
	if ( !check_err(payload_len_ < MAX_DATA_SIZE, "Payload length exceeded") )
	{
		return;
	}

	bool const is_masked = (frame_start_[1] & 0x80) != 0;
	//check_err(is_masked == !is_client_side(), "Frame from client should be masked");

	if ( is_masked )
	{
		boost::asio::read(*tcp_conn_, boost::asio::buffer(frame_mask_), err);
		if ( !check_err(err, "Payload mask") )
		{
			return;
		}
	}

	boost::asio::async_read(*tcp_conn_, read_buf_.prepare(payload_len_),
		boost::bind(&websocket_hybi_17::on_frame_payload, this,
			boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred));
}
Ejemplo n.º 21
0
/**
 *  Move snake to the next state
 */
bool Snake::update() {
  int nodes = (int)xs.size();

  if (is_closed()) {
    double x = (xs[0] + xs[nodes - 1]) / 2;
    double y = (ys[0] + ys[nodes - 1]) / 2;
    xs[0] = xs[nodes - 1] = x;
    ys[0] = ys[nodes - 1] = y;
  }

  cv::Mat x_dist(nodes, 1, CV_64F), y_dist(nodes, 1, CV_64F);

  for (int k = 0; k < nodes; ++k) {
    double x_force =
        grad.first.at<double>(ys[k], xs[k]) *
        (edge_weight * hess.at<double>(ys[k], xs[k]) - line_weight);
    double y_force =
        grad.second.at<double>(ys[k], xs[k]) *
        (edge_weight * hess.at<double>(ys[k], xs[k]) - line_weight);
    x_dist.at<double>(k, 0) = tick * x_force;
    y_dist.at<double>(k, 0) = tick * y_force;
  }

  cv::Mat forced_xs(xs), forced_ys(ys);

  forced_xs += x_dist;
  forced_ys += y_dist;

//  std::vector<double> prev_xs(xs), prev_ys(ys);

  xs = (cv::Mat)(pentamat * forced_xs);
  ys = (cv::Mat)(pentamat * forced_ys);

//  double acc_x = 0, acc_y = 0;
//  double eps = ???;
//
//  for (int k = 0; k < nodes; ++k)
//  {
//    acc_x += xs[k] - prev_xs[k];
//    acc_y += ys[k] - prev_ys[k];
//  }
//  acc_x += acc_y; acc_x /= tick;
//
//  if (std::abs(acc_x) < eps)
//  {
//    return true;
//  }

  return false;
}
Ejemplo n.º 22
0
/**
 * @brief Enables or disables the dynamic tiles related to this door.
 *
 * The dynamic tiles impacted by this function are the ones whose prefix is the door's name
 * followed by "_closed" or "_open", depending on the door state.
 */
void Door::update_dynamic_tiles() {

  std::list<MapEntity*> tiles = get_entities().get_entities_with_prefix(DYNAMIC_TILE, get_name() + "_closed");
  std::list<MapEntity*>::iterator it;
  for (it = tiles.begin(); it != tiles.end(); it++) {
    DynamicTile* tile = static_cast<DynamicTile*>(*it);
    tile->set_enabled(is_closed() || is_opening());
  }

  tiles = get_entities().get_entities_with_prefix(DYNAMIC_TILE, get_name() + "_open");
  for (it = tiles.begin(); it != tiles.end(); it++) {
    DynamicTile* tile = static_cast<DynamicTile*>(*it);
    tile->set_enabled(is_open() || is_closing());
  }
}
Ejemplo n.º 23
0
    // 关闭连接
	void TCPSessionHandler::close()
	{
		if (is_closed())
		{
			return;
		}

        session_handler_stuff::PackMessageList(shared_from_this());

		ThreadPointer thread_ptr = get_thread_manager()->get_thread(thread_id_);
		if (thread_ptr != nullptr)
		{
			thread_ptr->post(std::bind(session_handler_stuff::CloseSession, thread_ptr, session_id_));
		}
	}
Ejemplo n.º 24
0
bool 
FAITaskFactory::validate() const
{

  if (!m_task.has_start() || !m_task.has_finish()) {
    return false;
  }

  if ((m_task.task_size()>2) && (!is_closed()))
    return false;

  if (!is_unique())
    return false;

  return true;
}
Ejemplo n.º 25
0
static VALUE method_get_next_event(VALUE self, VALUE blocking) {
  char buf[64];
  FETCH_DATA_PTR(self, zk);

  for (;;) {

    // we use the is_running(self) method here because it allows us to have a
    // ruby-land semaphore that we can also use in the java extension
    //
    if (is_closed(self) || !is_running(self)) {
      zkrb_debug_inst(self, "is_closed(self): %d, is_running(self): %d, method_get_next_event is exiting loop", is_closed(self), is_running(self));
      return Qnil;  // this case for shutdown
    }

    zkrb_event_t *event = zkrb_dequeue(zk->queue, 1);

    /* Wait for an event using rb_thread_select() on the queue's pipe */
    if (event == NULL) {
      if (NIL_P(blocking) || (blocking == Qfalse)) { 
        return Qnil; // no event for us
      } 
      else {
        int fd = zk->queue->pipe_read;
        ssize_t bytes_read = 0;

        // wait for an fd to become readable, opposite of rb_thread_fd_writable
        rb_thread_wait_fd(fd);

        bytes_read = read(fd, buf, sizeof(buf));

        if (bytes_read == -1) {
          rb_raise(rb_eRuntimeError, "read failed: %d", errno);
        }

        zkrb_debug_inst(self, "read %zd bytes from the queue (%p)'s pipe", bytes_read, zk->queue);

        continue;
      }
    }

    VALUE hash = zkrb_event_to_ruby(event);
    zkrb_event_free(event);
    return hash;
  }
}
Ejemplo n.º 26
0
bool
AbstractTaskFactory::validate()
{
  clearValidationErrors();

  bool valid = true;

  if (!m_task.has_start()) {
    addValidationError(NO_VALID_START);
    valid = false;
  }
  if (!m_task.has_finish()) {
    addValidationError(NO_VALID_FINISH);
    valid = false;
  }

  if (get_ordered_task_behaviour().is_closed && !is_closed()) {
    addValidationError(TASK_NOT_CLOSED);
    valid = false;
  }

  if (get_ordered_task_behaviour().is_fixed_size()) {
    if (m_task.TaskSize() != get_ordered_task_behaviour().max_points) {
      addValidationError(INCORRECT_NUMBER_TURNPOINTS);
      valid = false;
    }
  } else {
    if (m_task.TaskSize() < get_ordered_task_behaviour().min_points) {
      addValidationError(UNDER_MIN_TURNPOINTS);
      valid = false;
    }
    if (m_task.TaskSize() > get_ordered_task_behaviour().max_points) {
      addValidationError(EXCEEDS_MAX_TURNPOINTS);
      valid = false;
    }
  }

  if (get_ordered_task_behaviour().homogeneous_tps && !is_homogeneous()) {
    addValidationError(TASK_NOT_HOMOGENEOUS);
    valid = false;
  }

  return valid;
}
Ejemplo n.º 27
0
t_tag		*check_all_lines(char **conf)
{
  int		i;
  t_tag		*list;

  i = 1;
  list = NULL;
  while (i < (my_strslen(conf) - 1))
    {
      if (conf[i][0] == '<' && conf[i][1] != '/')
	is_closed(conf[i], conf, i);
      else if (conf[i][0] == '<' && conf[i][1] == '/')
	is_opened(conf[i], conf, i);
      else
	list = is_value_good(conf[i], conf, i, list);
      i = i + 1;
    }
  return (list);
}
Ejemplo n.º 28
0
/**
 * @brief Notifies this detector that a collision was just detected with another entity.
 *
 * This function is called by the engine when there is a collision with another entity.
 *
 * @param entity_overlapping the entity overlapping the detector
 * @param collision_mode the collision mode that detected the collision
 */
void Door::notify_collision(MapEntity& entity_overlapping, CollisionMode collision_mode) {

  if (is_closed() && entity_overlapping.is_hero()) {

    Hero& hero = static_cast<Hero&>(entity_overlapping);

    if (get_keys_effect().get_action_key_effect() == KeysEffect::ACTION_KEY_NONE
        && hero.is_free()) {

      if (can_open()) {
        // The action command opens the door.
        get_keys_effect().set_action_key_effect(KeysEffect::ACTION_KEY_OPEN);
      }
      else if (!get_cannot_open_dialog_id().empty()) {
        // The action command shows a dialog.
        get_keys_effect().set_action_key_effect(KeysEffect::ACTION_KEY_LOOK);
      }
    }
  }
}
Ejemplo n.º 29
0
 void consume_item ()
 {
   csema_.acquire ();
   if (!is_closed ())
     {
       ACE_Message_Block *mb = 0;
       this->getq (mb);
       if (mb->msg_type () == ACE_Message_Block::MB_HANGUP)
         {
           this->shutdown ();
           mb->release ();
           return;
         }
       else
         {
           ACE_DEBUG ((LM_DEBUG,
                       ACE_TEXT ("(%t) Consumed %d\n"),
                       *((int*)mb->rd_ptr ())));
           mb->release();
         }
       psema_.release ();
     }
 }
Ejemplo n.º 30
0
void write_readable_trans(/* FILE *fp, */ Trans *t)
{
    int i, j;
    int size    = t->size;
    Score *pi    = t->pi;
    Score *gamma = t->gamma;
    Score *trans = t->trans;

    printf("There are %d tags\n", size);
    for (i = 0 ; i < size ; i++)
	printf(" Tag %d is %s%s pi %g gamma %g\n", i, unmap_tag(i),
			(is_closed(i)) ? " (closed)" : " ",
			pi[i], gamma[i]);

    /* Write transitions, direct and normalised */
    for (j = 0 ; j < size ; j++)
    {
	printf("From %s\n", unmap_tag(j));
	for (i = 0 ; i < size ; i++)
	    if (Trans_(trans,j,i,size) != 0)
		printf(" %s : %g (%g)\n", unmap_tag(i),
		      Trans_(trans,j,i,size), Trans_(trans,j,i,size)/gamma[j]);
    }
}