当前位置: 首页>>代码示例>>C++>>正文


C++ Available函数代码示例

本文整理汇总了C++中Available函数的典型用法代码示例。如果您正苦于以下问题:C++ Available函数的具体用法?C++ Available怎么用?C++ Available使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Available函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: assert

void test::TestEntityPool() {
    auto entities = new stoked::EntityPool(4);

    auto e1 = entities->Create();
    auto e2 = entities->Create();
    auto e3 = entities->Create();
    auto e4 = entities->Create();

    assert(e1 != nullptr);
    assert(e2 != nullptr);
    assert(e3 != nullptr);
    assert(e4 != nullptr);

    assert(e1->GetID() < entities->GetCapacity());
    assert(e2->GetID() < entities->GetCapacity());
    assert(e3->GetID() < entities->GetCapacity());
    assert(e4->GetID() < entities->GetCapacity());

    assert(entities->Empty() && !entities->Available());

    entities->FreeAll();

    assert(!entities->Empty() && entities->Available());

    e1 = entities->Create();
    bool freeResult = entities->Free(e1);
    assert(freeResult == true);

    delete entities;

    PASSED();
}
开发者ID:cdave1,项目名称:stoked,代码行数:32,代码来源:test.cpp

示例2: EnsureBuffer

nsresult
Http2PushTransactionBuffer::WriteSegments(nsAHttpSegmentWriter *writer,
        uint32_t count, uint32_t *countWritten)
{
    if ((mBufferedHTTP1Size - mBufferedHTTP1Used) < 20480) {
        EnsureBuffer(mBufferedHTTP1,mBufferedHTTP1Size + kDefaultBufferSize,
                     mBufferedHTTP1Used, mBufferedHTTP1Size);
    }

    count = std::min(count, mBufferedHTTP1Size - mBufferedHTTP1Used);
    nsresult rv = writer->OnWriteSegment(mBufferedHTTP1 + mBufferedHTTP1Used,
                                         count, countWritten);
    if (NS_SUCCEEDED(rv)) {
        mBufferedHTTP1Used += *countWritten;
    }
    else if (rv == NS_BASE_STREAM_CLOSED) {
        mIsDone = true;
    }

    if (Available() || mIsDone) {
        Http2Stream *consumer = mPushStream->GetConsumerStream();

        if (consumer) {
            LOG3(("Http2PushTransactionBuffer::WriteSegments notifying connection "
                  "consumer data available 0x%X [%u] done=%d\n",
                  mPushStream->StreamID(), Available(), mIsDone));
            mPushStream->ConnectPushedStream(consumer);
        }
    }

    return rv;
}
开发者ID:Jar-win,项目名称:Waterfox,代码行数:32,代码来源:Http2Push.cpp

示例3: s_assert

 void EGLWindow::Initialize(const WindowConfig &config)
 {
     s_assert(!Available());
     mConfig = config;
     mEGLDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
     s_assert(Available());
     s_assert(eglGetError() == EGL_SUCCESS);
     if (!eglInitialize(mEGLDisplay, nullptr, nullptr)) {
         s_error("Initialize EGL failed!\n");
         return;
     }
 }
开发者ID:leafnsand,项目名称:SamEngine,代码行数:12,代码来源:EGLWindow.cpp

示例4: Put

void cVideoBufferFile::Put(uint8_t *buf, unsigned int size)
{
  if (Available() + MARGIN >= m_BufferSize)
  {
    return;
  }

  if ((m_BufferSize - m_WritePtr) <= size)
  {
    int bytes = m_BufferSize - m_WritePtr;

    int p = 0;
    off_t ptr = m_WritePtr;
    while(bytes > 0)
    {
      p = pwrite(m_Fd, buf, bytes, ptr);
      if (p < 0)
      {
        ERRORLOG("Could not write to file: %s", (const char*)m_Filename);
        return;
      }
      size -= p;
      bytes -= p;
      buf += p;
      ptr += p;
    }
    cMutexLock lock(&m_Mutex);
    m_WritePtr = 0;
  }

  off_t ptr = m_WritePtr;
  int bytes = size;
  int p;
  while(bytes > 0)
  {
    p = pwrite(m_Fd, buf, bytes, ptr);
    if (p < 0)
    {
      ERRORLOG("Could not write to file: %s", (const char*)m_Filename);
      return;
    }
    bytes -= p;
    buf += p;
    ptr += p;
  }

  cMutexLock lock(&m_Mutex);

  m_WritePtr += size;
  if (!m_BufferFull)
  {
    if ((m_WritePtr + 2*MARGIN) > m_BufferSize)
    {
      m_BufferFull = true;
      time(&m_bufferWrapTime);
    }
  }

  time(&m_bufferEndTime);
}
开发者ID:FutureCow,项目名称:xbmc-pvr-addons,代码行数:60,代码来源:videobuffer.c

示例5: LOG

void
MediaSourceInputAdapter::NotifyListener()
{
  if (!mCallback) {
    return;
  }
  // Don't notify unless more data is available than the threshold, except
  // in the case that there's no more data coming.
  if (Available() < mNotifyThreshold && !mClosed && !mMediaSource->AppendDone()) {
    return;
  }
  nsCOMPtr<nsIInputStreamCallback> callback;
  if (mCallbackTarget) {
    callback = NS_NewInputStreamReadyEvent(mCallback, mCallbackTarget);
  } else {
    callback = mCallback;
  }
  MOZ_ASSERT(callback);
  mCallback = nullptr;
  mCallbackTarget = nullptr;
  mNotifyThreshold = 0;
  LOG(PR_LOG_DEBUG, ("%p IA::NotifyListener", this));
  callback->OnInputStreamReady(this);

}
开发者ID:Incognito,项目名称:mozilla-central,代码行数:25,代码来源:MediaSourceInputAdapter.cpp

示例6: Put

void cVideoBufferRAM::Put(uint8_t *buf, unsigned int size)
{
  if (Available() + MARGIN >= m_BufferSize)
  {
    ERRORLOG("------------- skipping data");
    return;
  }

  if ((m_BufferSize - m_WritePtr) <= size)
  {
    int bytes = m_BufferSize - m_WritePtr;
    memcpy(m_BufferPtr+m_WritePtr, buf, bytes);
    size -= bytes;
    buf += bytes;
    cMutexLock lock(&m_Mutex);
    m_WritePtr = 0;
  }

  memcpy(m_BufferPtr+m_WritePtr, buf, size);

  cMutexLock lock(&m_Mutex);

  m_WritePtr += size;
  if (!m_BufferFull)
  {
    if ((m_WritePtr + 2*MARGIN) > m_BufferSize)
    {
      m_BufferFull = true;
      time(&m_bufferWrapTime);
    }
  }

  time(&m_bufferEndTime);
}
开发者ID:Alloyed,项目名称:xbmc-pvr-addons,代码行数:34,代码来源:videobuffer.c

示例7: pclose

int LightProcess::pclose(FILE *f) {
  if (!Available()) {
    return ::pclose(f);
  }

  int id = GetId();
  Lock lock(g_procs[id].m_procMutex);

  std::map<int64_t, int64_t>::iterator it = g_procs[id].m_popenMap.find((int64_t)f);
  if (it == g_procs[id].m_popenMap.end()) {
    // try to close it with normal pclose
    return ::pclose(f);
  }

  int64_t f2 = it->second;
  g_procs[id].m_popenMap.erase((int64_t)f);
  fclose(f);

  lwp_write(g_procs[id].m_afdt_fd, "pclose");
  lwp_write_int64(g_procs[id].m_afdt_fd, f2);

  int ret = -1;
  lwp_read_int32(g_procs[id].m_afdt_fd, ret);
  if (ret < 0) {
    lwp_read_int32(g_procs[id].m_afdt_fd, errno);
  }
  return ret;
}
开发者ID:craigcarnell,项目名称:hhvm,代码行数:28,代码来源:light-process.cpp

示例8: Get

 const char *Peek(size_t *len) {
   if (Available() > 0 && buf_size_ == 0) {
     Get();
   }
   *len = buf_size_;
   return buf_begin_;
 }
开发者ID:shaform,项目名称:snappycat,代码行数:7,代码来源:snappycat.cpp

示例9: waitpid

pid_t LightProcess::waitpid(pid_t pid, int *stat_loc, int options,
                            int timeout) {
  if (!Available()) {
    // light process is not really there
    return ::waitpid(pid, stat_loc, options);
  }

  int id = GetId();
  Lock lock(g_procs[id].m_procMutex);

  auto fout = g_procs[id].m_afdt_fd;
  lwp_write(fout, "waitpid");
  lwp_write_int64(fout, (int64_t)pid);
  lwp_write_int32(fout, options);
  lwp_write_int32(fout, timeout);

  int64_t ret;
  int stat;
  auto fin = g_procs[id].m_afdt_fd;
  lwp_read_int64(fin, ret);
  lwp_read_int32(fin, stat);

  *stat_loc = stat;
  if (ret < 0) {
    lwp_read_int32(fin, errno);
  }
  return (pid_t)ret;
}
开发者ID:craigcarnell,项目名称:hhvm,代码行数:28,代码来源:light-process.cpp

示例10: waitpid

pid_t LightProcess::waitpid(pid_t pid, int *stat_loc, int options,
                            int timeout) {
  if (!Available()) {
    // light process is not really there
    return ::waitpid(pid, stat_loc, options);
  }

  int id = GetId();
  Lock lock(g_procs[id].m_procMutex);

  fprintf(g_procs[id].m_fout, "waitpid\n%" PRId64 " %d %d\n", (int64_t)pid, options,
          timeout);
  fflush(g_procs[id].m_fout);

  char buf[BUFFER_SIZE];
  read_buf(g_procs[id].m_fin, buf);
  if (!buf[0]) return -1;
  int64_t ret;
  int stat;
  sscanf(buf, "%" PRId64 " %d", &ret, &stat);
  *stat_loc = stat;
  if (ret < 0) {
    read_buf(g_procs[id].m_fin, buf);
    sscanf(buf, "%d", &errno);
  }
  return (pid_t)ret;
}
开发者ID:Alienfeel,项目名称:hhvm,代码行数:27,代码来源:light-process.cpp

示例11: pclose

int LightProcess::pclose(FILE *f) {
  if (!Available()) {
    return ::pclose(f);
  }

  int id = GetId();
  Lock lock(g_procs[id].m_procMutex);

  std::map<int64_t, int64_t>::iterator it = g_procs[id].m_popenMap.find((int64_t)f);
  if (it == g_procs[id].m_popenMap.end()) {
    // try to close it with normal pclose
    return ::pclose(f);
  }

  int64_t f2 = it->second;
  g_procs[id].m_popenMap.erase((int64_t)f);
  fclose(f);
  fprintf(g_procs[id].m_fout, "pclose\n%" PRId64 "\n", f2);
  fflush(g_procs[id].m_fout);

  char buf[BUFFER_SIZE];
  read_buf(g_procs[id].m_fin, buf);
  int ret = -1;
  sscanf(buf, "%d", &ret);
  if (ret < 0) {
    read_buf(g_procs[id].m_fin, buf);
    sscanf(buf, "%d", &errno);
  }
  return ret;
}
开发者ID:Alienfeel,项目名称:hhvm,代码行数:30,代码来源:light-process.cpp

示例12: s_assert

 void Graphics::Finalize()
 {
     s_assert(Available());
     mConfig = GraphicsConfig();
     mRenderer->Finalize();
     mCanvas->Finalize();
     mResourceManager->Finalize();
     mRenderer = nullptr;
 }
开发者ID:leafnsand,项目名称:SamEngine,代码行数:9,代码来源:Graphics.cpp

示例13: Available

void FileInputStream::Skip(int64_t skip)
{
	if (skip <= 0) {
		return;
	}

	int r = skip;

	if (skip > Available()) {
		r = Available();
	}

	char *tmp = new char[r];

	r = _file->Read((char *)tmp, r);

	delete [] tmp;
}
开发者ID:beaver999,项目名称:mygoodjob,代码行数:18,代码来源:jfileinputstream.cpp

示例14: Initialize

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;
  }
}
开发者ID:craigcarnell,项目名称:hhvm,代码行数:56,代码来源:light-process.cpp

示例15: AppendElements

  // Append aLength bytes from aSrc to the buffer.  Caller must check that
  // sufficient space is available.
  void AppendElements(const uint8_t* aSrc, uint32_t aLength) {
    NS_ABORT_IF_FALSE(mBuffer && mCapacity, "Buffer not initialized.");
    NS_ABORT_IF_FALSE(aLength <= Available(), "Buffer full.");

    uint32_t end = (mStart + mCount) % mCapacity;

    uint32_t toCopy = std::min(mCapacity - end, aLength);
    memcpy(&mBuffer[end], aSrc, toCopy);
    memcpy(&mBuffer[0], aSrc + toCopy, aLength - toCopy);
    mCount += aLength;
  }
开发者ID:TelefonicaPushServer,项目名称:mozilla-central,代码行数:13,代码来源:AudioStream.cpp


注:本文中的Available函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。