Example #1
0
void
MIF_Scheduler::receive_request (PortableInterceptor::ServerRequestInfo_ptr request_info,
                                RTScheduling::Current::IdType_out guid_out,
                                CORBA::String_out,
                                CORBA::Policy_out sched_param_out,
                                CORBA::Policy_out /*implicit_sched_param*/)
{

  if (TAO_debug_level > 0)
    ACE_DEBUG ((LM_DEBUG,
                "MIF_Scheduler::receive_request\n"));

  IOP::ServiceContext_var serv_cxt =
    request_info->get_request_service_context (Server_Interceptor::SchedulingInfo);

  if (serv_cxt != 0)
    {
      ACE_DEBUG ((LM_DEBUG,
                  "Got scheduling info\n"));

      RTScheduling::Current::IdType* guid;
      ACE_NEW (guid,
               RTScheduling::Current::IdType);

      guid->length (sizeof(size_t));
      ACE_OS::memcpy (guid->get_buffer (),
                      serv_cxt->context_data.get_buffer (),
                      sizeof (size_t));

      size_t gu_id;
      ACE_OS::memcpy (&gu_id,
                      guid->get_buffer (),
                      guid->length ());

      ACE_DEBUG ((LM_DEBUG,
                  "MIF_Scheduler::receive_request %d\n",
                  gu_id));


      CORBA::OctetSeq int_buf (sizeof (long));
      int_buf.length (int_buf.maximum ());
      int i = sizeof (long);
      for (unsigned int j = 0;j < sizeof (int);j++)
        {
          int_buf [j] = serv_cxt->context_data [i++];
        }

      int importance = 0;
      ACE_OS::memcpy (&importance,
                      int_buf.get_buffer (),
                      sizeof (importance));

      guid_out = guid;
      sched_param_out = DT_TEST::instance ()->scheduler ()->create_segment_scheduling_parameter (importance);

      if (TAO_debug_level > 0)
        ACE_DEBUG ((LM_DEBUG,
                    "%t The Guid is %d Importance is %d\n",
                    gu_id,
                    importance));

      DT* new_dt;
      ACE_NEW (new_dt,
               DT (this->lock_,
                   gu_id));

      new_dt->msg_priority (importance);
      lock_.acquire ();
      ready_que_.enqueue_prio (new_dt);
      new_dt->suspend ();
      lock_.release ();
    }
}
Example #2
0
FX_BOOL CPDF_SampledFunc::v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const {
  int pos = 0;
  CFX_FixedBufGrow<FX_FLOAT, 16> encoded_input_buf(m_nInputs);
  FX_FLOAT* encoded_input = encoded_input_buf;
  CFX_FixedBufGrow<uint32_t, 32> int_buf(m_nInputs * 2);
  uint32_t* index = int_buf;
  uint32_t* blocksize = index + m_nInputs;
  for (uint32_t i = 0; i < m_nInputs; i++) {
    if (i == 0)
      blocksize[i] = 1;
    else
      blocksize[i] = blocksize[i - 1] * m_EncodeInfo[i - 1].sizes;
    encoded_input[i] =
        PDF_Interpolate(inputs[i], m_pDomains[i * 2], m_pDomains[i * 2 + 1],
                        m_EncodeInfo[i].encode_min, m_EncodeInfo[i].encode_max);
    index[i] = std::min((uint32_t)std::max(0.f, encoded_input[i]),
                        m_EncodeInfo[i].sizes - 1);
    pos += index[i] * blocksize[i];
  }
  FX_SAFE_INT32 bits_to_output = m_nOutputs;
  bits_to_output *= m_nBitsPerSample;
  if (!bits_to_output.IsValid())
    return FALSE;

  FX_SAFE_INT32 bitpos = pos;
  bitpos *= bits_to_output.ValueOrDie();
  if (!bitpos.IsValid())
    return FALSE;

  FX_SAFE_INT32 range_check = bitpos;
  range_check += bits_to_output.ValueOrDie();
  if (!range_check.IsValid())
    return FALSE;

  const uint8_t* pSampleData = m_pSampleStream->GetData();
  if (!pSampleData)
    return FALSE;

  for (uint32_t j = 0; j < m_nOutputs; j++) {
    uint32_t sample =
        GetBits32(pSampleData, bitpos.ValueOrDie() + j * m_nBitsPerSample,
                  m_nBitsPerSample);
    FX_FLOAT encoded = (FX_FLOAT)sample;
    for (uint32_t i = 0; i < m_nInputs; i++) {
      if (index[i] == m_EncodeInfo[i].sizes - 1) {
        if (index[i] == 0)
          encoded = encoded_input[i] * (FX_FLOAT)sample;
      } else {
        FX_SAFE_INT32 bitpos2 = blocksize[i];
        bitpos2 += pos;
        bitpos2 *= m_nOutputs;
        bitpos2 += j;
        bitpos2 *= m_nBitsPerSample;
        if (!bitpos2.IsValid())
          return FALSE;
        uint32_t sample1 =
            GetBits32(pSampleData, bitpos2.ValueOrDie(), m_nBitsPerSample);
        encoded += (encoded_input[i] - index[i]) *
                   ((FX_FLOAT)sample1 - (FX_FLOAT)sample);
      }
    }
    results[j] =
        PDF_Interpolate(encoded, 0, (FX_FLOAT)m_SampleMax,
                        m_DecodeInfo[j].decode_min, m_DecodeInfo[j].decode_max);
  }
  return TRUE;
}
Example #3
0
void
MIF_Scheduler::send_request (PortableInterceptor::ClientRequestInfo_ptr request_info)
{
  CORBA::Policy_var sched_param = current_->scheduling_parameter ();

  MIF_Scheduling::SegmentSchedulingParameterPolicy_var sched_param_var =
    MIF_Scheduling::SegmentSchedulingParameterPolicy::_narrow (sched_param.in ());

  IOP::ServiceContext srv_con;
  srv_con.context_id = Client_Interceptor::SchedulingInfo;

  RTScheduling::Current::IdType_var guid = current_->id ();

  int guid_length = guid->length ();

  CORBA::OctetSeq seq_buf (guid_length);
  seq_buf.length (seq_buf.maximum ());
  ACE_OS::memcpy (seq_buf.get_buffer (),
                  guid->get_buffer (),
                  guid_length);

  int cxt_data_length = sizeof (int) + guid_length;
  srv_con.context_data.length (cxt_data_length);

  int i = 0;
  for (;i < guid_length;i++)
    {
      srv_con.context_data [i] = seq_buf [i];
    }

  int importance = sched_param_var->importance ();
  CORBA::OctetSeq int_buf (sizeof (importance));
  int_buf.length (int_buf.maximum ());
  ACE_OS::memcpy (int_buf.get_buffer (),
                  &importance,
                  sizeof (importance));

  int j = 0;
  for (;i < cxt_data_length;i++)
    {
      srv_con.context_data [i] = int_buf [j++];
    }

  request_info->add_request_service_context (srv_con,
                                             0);

  lock_.acquire ();
  if (ready_que_.message_count () > 0)
    {
      int priority;
      ACE_hthread_t current;
      ACE_Thread::self (current);
      if (ACE_Thread::getprio (current, priority) == -1)
        return;

      ACE_DEBUG ((LM_DEBUG,
                  "Initial thread priority is %d %d\n",
                  priority,
                  ACE_DEFAULT_THREAD_PRIORITY));

      RTCORBA::Priority rtpriority;
      RTCORBA::PriorityMapping* pm = this->mapping_manager_->mapping ();
      if (pm->to_CORBA(priority + 1, rtpriority))
        {
          current_->the_priority (rtpriority);

          ACE_Thread::self (current);
          if (ACE_Thread::getprio (current, priority) == -1)
            return;

          ACE_DEBUG ((LM_DEBUG,
                      "Bumped thread priority is %d\n",
                      priority));
        }

      DT* run_dt = 0;
      ACE_Message_Block* msg = 0;
      ready_que_.dequeue_head (msg);
      run_dt = dynamic_cast<DT*> (msg);
      run_dt->resume ();
      free_que_.enqueue_prio (run_dt);
    }
  lock_.release ();

}
Example #4
0
FX_BOOL CPDF_SampledFunc::v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const
{
    int pos = 0;
    CFX_FixedBufGrow<FX_FLOAT, 16> encoded_input_buf(m_nInputs);
    FX_FLOAT* encoded_input = encoded_input_buf;
    CFX_FixedBufGrow<int, 32> int_buf(m_nInputs * 2);
    int* index = int_buf;
    int* blocksize = index + m_nInputs;
    for (int i = 0; i < m_nInputs; i ++) {
        if (i == 0) {
            blocksize[i] = 1;
        } else {
            blocksize[i] = blocksize[i - 1] * m_pEncodeInfo[i - 1].sizes;
        }
        encoded_input[i] = PDF_Interpolate(inputs[i], m_pDomains[i * 2], m_pDomains[i * 2 + 1],
                                           m_pEncodeInfo[i].encode_min, m_pEncodeInfo[i].encode_max);
        index[i] = (int)encoded_input[i];
        if (index[i] < 0) {
            index[i] = 0;
        } else if (index[i] > m_pEncodeInfo[i].sizes - 1) {
            index[i] = m_pEncodeInfo[i].sizes - 1;
        }
        pos += index[i] * blocksize[i];
    }
    FX_SAFE_INT32 bitpos = pos;
    bitpos *= m_nBitsPerSample;
    bitpos *= m_nOutputs;
    if (!bitpos.IsValid()) {
        return FALSE;
    }
    FX_LPCBYTE pSampleData = m_pSampleStream->GetData();
    if (pSampleData == NULL) {
        return FALSE;
    }
    FX_SAFE_INT32 bitpos1 = m_nOutputs - 1 > 0 ? m_nOutputs - 1 : 0; 
    bitpos1 *= m_nBitsPerSample;
    bitpos1 += bitpos.ValueOrDie();
    if (!bitpos1.IsValid()) {
        return FALSE;
    }
    for (int j = 0; j < m_nOutputs; j ++) {
        FX_DWORD sample = _GetBits32(pSampleData, bitpos.ValueOrDie() + j * m_nBitsPerSample, m_nBitsPerSample);
        FX_FLOAT encoded = (FX_FLOAT)sample;
        for (int i = 0; i < m_nInputs; i ++) {
            if (index[i] == m_pEncodeInfo[i].sizes - 1) {
                if (index[i] == 0) {
                    encoded = encoded_input[i] * (FX_FLOAT)sample;
                }
            } else {
                FX_SAFE_INT32 bitpos2 = blocksize[i];
                bitpos2 += 1;
                bitpos2 *= m_nBitsPerSample; 
                bitpos2 *= m_nOutputs;
                bitpos2 += bitpos.ValueOrDie();
                if (!bitpos2.IsValid()) {
                    return FALSE;
                }
                FX_DWORD sample1 = _GetBits32(pSampleData, bitpos2.ValueOrDie(), m_nBitsPerSample);
                encoded += (encoded_input[i] - index[i]) * ((FX_FLOAT)sample1 - (FX_FLOAT)sample);
            }
        }
        results[j] = PDF_Interpolate(encoded, 0, (FX_FLOAT)m_SampleMax,
                                     m_pDecodeInfo[j].decode_min, m_pDecodeInfo[j].decode_max);
    }
    return TRUE;
}