Esempio n. 1
0
void LightProcess::Initialize(const std::string &prefix, int count,
                              const std::vector<int> &inherited_fds) {
  if (prefix.empty() || count <= 0) {
    return;
  }

  if (Available()) {
    // already initialized
    return;
  }

  g_procs.reset(new LightProcess[count]);
  g_procsCount = count;

  auto afdt_filename = folly::sformat("{}.{}", prefix, getpid());

  // remove the possible leftover
  remove(afdt_filename.c_str());

  afdt_error_t err = AFDT_ERROR_T_INIT;
  auto afdt_lid = afdt_listen(afdt_filename.c_str(), &err);
  if (afdt_lid < 0) {
    Logger::Warning("Unable to afdt_listen to %s: %d %s",
                    afdt_filename.c_str(),
                    errno, folly::errnoStr(errno).c_str());
    return;
  }

  SCOPE_EXIT {
    ::close(afdt_lid);
    remove(afdt_filename.c_str());
  };

  for (int i = 0; i < count; i++) {
    if (!g_procs[i].initShadow(afdt_lid, afdt_filename, i, inherited_fds)) {
      for (int j = 0; j < i; j++) {
        g_procs[j].closeShadow();
      }
      g_procs.reset();
      g_procsCount = 0;
      break;
    }
  }

  if (!s_handlerInited) {
    struct sigaction sa;
    struct sigaction old_sa;
    sa.sa_sigaction = &LightProcess::SigChldHandler;
    sa.sa_flags = SA_SIGINFO | SA_NOCLDSTOP;
    if (sigaction(SIGCHLD, &sa, &old_sa) != 0) {
      Logger::Error("Couldn't install SIGCHLD handler");
      abort();
    }
    s_handlerInited = true;
  }
}
Esempio n. 2
0
void LightProcess::Close() {
  for (int i = 0; i < g_procsCount; i++) {
    g_procs[i].closeShadow();
  }
  g_procs.reset();
  g_procsCount = 0;
}
Esempio n. 3
0
	void init_old_buffer(boost::scoped_array<unsigned long long> &array, const std::size_t size) {
		if (!array) {
			array.reset(new unsigned long long[size]);
			for (std::size_t i=0;i<size;i++) {
				array[i] = 0;
			}
		}
	}
Esempio n. 4
0
void AudioResampleImpl::splitAudioData(AudioData & data, boost::scoped_array<char*> & split) const
{
	auto dataFormat = data.format();

	if (dataFormat.isPlanar())
	{
		/// Для планарного формата необходимо представить данные из result
		const int numChannels = dataFormat.channelCount();
		split.reset(new char*[numChannels]);
		split_ref(data.begin(), data.end(), data.numBytes() / numChannels, split.get());
	}
	else
	{
		/// Interleaved данные помещаются в один массив
		split.reset(new char*[1]);
		split[0] = data.data();
	}
}
Esempio n. 5
0
void LightProcess::Close() {
  boost::scoped_array<LightProcess> procs;
  procs.swap(g_procs);
  int count = g_procsCount;
  g_procs.reset();
  g_procsCount = 0;

  for (int i = 0; i < count; i++) {
    procs[i].closeShadow();
  }
}
Esempio n. 6
0
void LightProcess::Initialize(const std::string &prefix, int count,
                              const std::vector<int> &inherited_fds) {
  if (prefix.empty() || count <= 0) {
    return;
  }

  if (Available()) {
    // already initialized
    return;
  }

  g_procs.reset(new LightProcess[count]);
  g_procsCount = count;

  for (int i = 0; i < count; i++) {
    if (!g_procs[i].initShadow(prefix, i, inherited_fds)) {
      for (int j = 0; j < i; j++) {
        g_procs[j].closeShadow();
      }
      g_procs.reset();
      g_procsCount = 0;
      break;
    }
  }

  if (!s_handlerInited) {
    struct sigaction sa;
    struct sigaction old_sa;
    sa.sa_sigaction = &LightProcess::SigChldHandler;
    sa.sa_flags = SA_SIGINFO | SA_NOCLDSTOP;
    if (sigaction(SIGCHLD, &sa, &old_sa) != 0) {
      Logger::Error("Couldn't install SIGCHLD handler");
      abort();
    }
    s_handlerInited = true;
  }
}
Esempio n. 7
0
File: log.cpp Progetto: alogg/dolfin
// Buffer allocation
void allocate_buffer(std::string msg)
{
  // va_list, start, end require a char pointer of fixed size so we
  // need to allocate the buffer here. We allocate twice the size of
  // the format string and at least DOLFIN_LINELENGTH. This should be
  // ok in most cases.
  unsigned int new_size = std::max(static_cast<unsigned int>(2*msg.size()),
                                   static_cast<unsigned int>(DOLFIN_LINELENGTH));
  //static_cast<unsigned int>(DOLFIN_LINELENGTH));
  if (new_size > buffer_size)
  {
    buffer.reset(new char[new_size]);
    buffer_size = new_size;
  }
}
Esempio n. 8
0
void LightProcess::Initialize(const std::string &prefix, int count) {
  if (prefix.empty() || count <= 0) {
    return;
  }

  if (Available()) {
    // already initialized
    return;
  }

  g_procs.reset(new LightProcess[count]);
  g_procsCount = count;

  for (int i = 0; i < count; i++) {
    if (!g_procs[i].initShadow(prefix, i)) {
      for (int j = 0; j < i; j++) {
        g_procs[j].closeShadow();
      }
      g_procs.reset();
      g_procsCount = 0;
      break;
    }
  }
}
Esempio n. 9
0
HRESULT CKeyTransformBCrypt::_InitBCrypt(BCRYPT_ALG_HANDLE& hAes, BCRYPT_KEY_HANDLE& hKey,
	boost::scoped_array<UCHAR>& pKeyObj, const BYTE* pbKey32)
{
	if(m_lpBCryptOpenAlgorithmProvider(&hAes, BCRYPT_AES_ALGORITHM, NULL, 0) != 0)
	{
		ASSERT(FALSE);
		return E_FAIL;
	}

	DWORD dwKeyObjLen = 0;
	ULONG uResult = 0;
	if(m_lpBCryptGetProperty(hAes, BCRYPT_OBJECT_LENGTH, (PUCHAR)&dwKeyObjLen,
		sizeof(DWORD), &uResult, 0) != 0) KTBC_FAIL;
	if(dwKeyObjLen == 0) KTBC_FAIL;

	pKeyObj.reset(new UCHAR[dwKeyObjLen]);

	if(m_lpBCryptSetProperty(hAes, BCRYPT_CHAINING_MODE, (PUCHAR)BCRYPT_CHAIN_MODE_ECB,
		static_cast<ULONG>((wcslen(BCRYPT_CHAIN_MODE_ECB) + 1) * sizeof(wchar_t)), 0) != 0)
		KTBC_FAIL;

	BCRYPT_KEY_DATA_BLOB_32 keyBlob;
	ZeroMemory(&keyBlob, sizeof(BCRYPT_KEY_DATA_BLOB_32));
	keyBlob.dwMagic = BCRYPT_KEY_DATA_BLOB_MAGIC;
	keyBlob.dwVersion = BCRYPT_KEY_DATA_BLOB_VERSION1;
	keyBlob.cbKeyData = 32;
	memcpy(keyBlob.pbData, pbKey32, 32);

	// if(m_lpBCryptGenerateSymmetricKey(hAes, &hKey, (PUCHAR)pKeyObj.get(),
	//	dwKeyObjLen, const_cast<PUCHAR>(pbKey32), 32, 0) != 0) KTBC_FAIL;
	if(m_lpBCryptImportKey(hAes, NULL, BCRYPT_KEY_DATA_BLOB, &hKey,
		pKeyObj.get(), dwKeyObjLen, (PUCHAR)&keyBlob,
		sizeof(BCRYPT_KEY_DATA_BLOB_32), 0) != 0) KTBC_FAIL;

#ifdef _DEBUG
	DWORD dwKeyLen = 0;
	VERIFY(m_lpBCryptGetProperty(hKey, BCRYPT_KEY_STRENGTH, (PUCHAR)&dwKeyLen,
		sizeof(DWORD), &uResult, 0) == 0);
	VERIFY(dwKeyLen == 256);

	BCRYPT_ALG_HANDLE hRef = NULL;
	VERIFY(m_lpBCryptGetProperty(hKey, BCRYPT_PROVIDER_HANDLE, (PUCHAR)&hRef,
		sizeof(BCRYPT_ALG_HANDLE), &uResult, 0) == 0);
	VERIFY(hRef == hAes);
#endif

	return S_OK;
}
void CassandraStressClient::Setup(std::string const& server_ip) {
  success_count_ = 0;
  latencies_.reset(new double[FLAGS_operation_count/FLAGS_thread_count]);
  try {
    boost::shared_ptr<TTransport> socket =
        boost::shared_ptr<TSocket>(new TSocket(server_ip, 9160));
    transport_ = boost::shared_ptr<TFramedTransport>(
        new TFramedTransport(socket));
    boost::shared_ptr<TProtocol> protocol =
        boost::shared_ptr<TBinaryProtocol>(new TBinaryProtocol(transport_));
    client_.reset(new CassandraClient(protocol));
    transport_->open();
    std::string query = "USE offline_keyspace";
    CqlResult result;
    client_->execute_cql3_query(result, query, Compression::NONE,
                                ConsistencyLevel::ONE);
  } catch (TTransportException& te) {
    printf("Exception: %s [%d]\n", te.what(), te.getType());
  } catch (InvalidRequestException& ire) {
    printf("Exception: %s [%s]\n", ire.what(), ire.why.c_str());
  }
}
Esempio n. 11
0
bool volume_generator_checkerboard::generate_float_volume(unsigned dim_x,
                                                          unsigned dim_y,
                                                          unsigned dim_z,
                                                          unsigned components,
                                                          boost::scoped_array<float>& buffer)

{
    if (dim_x < 1 || dim_y < 1 || dim_z < 1 || components < 1) {
        return (false);
    }

    try {
        buffer.reset(new float[dim_x * dim_y * dim_z * components]);
    }
    catch (std::bad_alloc&) {
        return (false);
    }

    float val;
    unsigned offset_dst;

    for (unsigned z = 0; z < dim_z; z++) {
        for (unsigned y = 0; y < dim_y; y++) {
            for (unsigned x = 0; x < dim_x; x++) {
                val = float(scm::math::sign(-int((x+y+z) % 2)));
                offset_dst =   x * components
                             + y * dim_x * components
                             + z * dim_x * dim_y * components;

                for (unsigned c = 0; c < components; c++) {
                    buffer[offset_dst + c] = val;
                }
            }
        }
    }

    return (true);
}
Esempio n. 12
0
 static type build(const Graph& g, const IndexMap& index, boost::scoped_array<Value>& array_holder) {
   array_holder.reset(new Value[num_vertices(g)]);
   std::fill(array_holder.get(), array_holder.get() + num_vertices(g), Value());
   return make_iterator_property_map(array_holder.get(), index);
 }