// -----------------------------------------------------------------------------
// CActiveCaller::ConstructL
// 
// -----------------------------------------------------------------------------
//
void CActiveCaller::ConstructL()
    {
    WLOG("CActiveCaller::ConstructL >");
	User::LeaveIfError( iTimer.CreateLocal() );
	CActiveScheduler::Add( this );
	WLOG("CActiveCaller::ConstructL <");
    }
Пример #2
0
 TYPE& TArray2D<TYPE>::indexOf(Uint32 row, Uint32 column)
 {
   if(row < mRows && column < mColumns)
   {
     return mArray[row*mColumns + column];
   }
   else if(column < mColumns && mRows > 0)
   {
     WLOG() << "TArray2D:indexOf(" << row << "," << column
       << ") row provided exceeds maximum rows of "
       << mRows << std::endl;
     return mArray[(mRows-1)*mColumns + column]; 
   }
   else if(row < mRows && mColumns > 0)
   {
     WLOG() << "TArray2D:indexOf(" << row << "," << column
       << ") column provided exceeds maximum columns of "
       << mColumns << std::endl;
     return mArray[row*mColumns + (mColumns-1)];
   }
   else if(mRows > 0 && mColumns > 0)
   {
     WLOG() << "TArray2D:indexOf(" << row << "," << column
       << ") row and column provided exceeds maximum row of "
       << mRows << " and column of " << mColumns << std::endl;
     return mArray[(mRows-1)*mColumns + (mColumns-1)];
   }
   else
   {
     ELOG() << "TArray2D:indexOf(" << row << "," << column
       << ") array is empty (no rows or columns)" << std::endl;
     return mArray[0];
   }
 }
// -----------------------------------------------------------------------------
// Destructor
// 
// -----------------------------------------------------------------------------
//
CActiveCaller::~CActiveCaller()
    {
    WLOG("CActiveCaller::~CActiveCaller >");
 	Cancel();
	iTimer.Close();
	WLOG("CActiveCaller::~CActiveCaller <");
    }
Пример #4
0
Throttler::Throttler(double avgRateBytesPerSec, double peakRateBytesPerSec,
                     double bucketLimitBytes, int64_t throttlerLogTimeMillis)
    : avgRateBytesPerSec_(avgRateBytesPerSec) {
  bucketRateBytesPerSec_ = peakRateBytesPerSec;
  bytesTokenBucketLimit_ =
      kTimeMultiplier * kBucketMultiplier * bucketRateBytesPerSec_;
  /* We keep the number of tokens generated as zero initially
   * It could be argued that we keep this filled when we created the
   * bucket. However the startTime is passed in this case and the hope is
   * that we will have enough number of tokens by the time we send the data
   */
  bytesTokenBucket_ = 0;
  if (bucketLimitBytes > 0) {
    bytesTokenBucketLimit_ = bucketLimitBytes;
  }
  if (avgRateBytesPerSec > 0) {
    WLOG(INFO) << "Average rate " << avgRateBytesPerSec_ / kMbToB
               << " Mbytes/sec";
  } else {
    WLOG(INFO) << "No average rate specified";
  }
  if (bucketRateBytesPerSec_ > 0) {
    WLOG(INFO) << "Peak rate " << bucketRateBytesPerSec_ / kMbToB
               << " Mbytes/sec.  Bucket limit "
               << bytesTokenBucketLimit_ / kMbToB << " Mbytes.";
  } else {
    WLOG(INFO) << "No peak rate specified";
  }
  throttlerLogTimeMillis_ = throttlerLogTimeMillis;
}
Пример #5
0
static void controller_cb_in(struct loop_fd *fd, int revents) {
	struct controller *controller = container_of(fd, struct controller, in);
	int result;

	VLOG("controller %p in %d", controller, revents);
	if (revents & (POLLHUP | POLLERR)) {
		ELOG("controller %p has error on stdin", controller);
		controller->in.poll_flags = 0;
		exit(0);
	}

	if (revents & (POLLIN | POLLPRI)) {
		/* read from buffer */
		char bytes[1024];
		result = read(controller->in.fd, bytes, sizeof(bytes));
		VLOG("read %d bytes from controller", result);
		if (result < 0) {
			WLOG("error reading controller %p %d %d", controller, result, errno);
		} else {
			result = controller_handle_metakey(result, bytes);
			if (result > 0) {
				result = buffer_output(current_buf, result, bytes);
				if (result != 0) {
					WLOG("buffer ran out of space! dropping chars");
				}
			}
		}
	}
}
Пример #6
0
int WdtSocket::readWithTimeout(char *buf, int nbyte, int timeoutMs,
                               bool tryFull) {
  WDT_CHECK_GT(nbyte, 0);
  if (readErrorCode_ != OK && readErrorCode_ != WDT_TIMEOUT) {
    WLOG(ERROR) << "Socket read failed before, not trying to read again "
                << port_;
    return -1;
  }
  readErrorCode_ = OK;
  int numRead = 0;
  readEncryptionSettingsOnce(timeoutMs);
  if (supportUnencryptedPeer_ && readErrorCode_ == UNEXPECTED_CMD_ERROR) {
    WLOG(WARNING)
        << "Turning off encryption since the other side does not support "
           "encryption "
        << port_;
    readErrorCode_ = OK;
    buf[0] = buf_[0];
    numRead = 1;
    // also turn off encryption
    encryptionParams_.erase();
  } else if (readErrorCode_ != OK) {
    return -1;
  }
  if (nbyte == numRead) {
    return nbyte;
  }
  bool encrypt = encryptionParams_.isSet();
  int ret = readInternal(buf + numRead, nbyte - numRead, timeoutMs, tryFull);
  if (ret >= 0) {
    numRead += ret;
  } else {
    return (numRead > 0 ? numRead : -1);
  }
  if (!encrypt) {
    return numRead;
  }
  int numDecrypted = 0;
  if (ctxSaveOffset_ >= 0) {
    if (ctxSaveOffset_ <= numRead) {
      if (!decryptor_.decrypt(buf, ctxSaveOffset_, buf)) {
        readErrorCode_ = ENCRYPTION_ERROR;
        return -1;
      }
      decryptor_.saveContext();
      numDecrypted = ctxSaveOffset_;
      ctxSaveOffset_ = CTX_SAVED;
    } else {
      ctxSaveOffset_ -= numRead;
    }
  }
  // have to decrypt data
  if (!decryptor_.decrypt((buf + numDecrypted), (numRead - numDecrypted),
                          (buf + numDecrypted))) {
    readErrorCode_ = ENCRYPTION_ERROR;
    return -1;
  }
  return numRead;
}
// -----------------------------------------------------------------------------
// Destructor
//
// -----------------------------------------------------------------------------
//
CStatusPaneHandler::~CStatusPaneHandler()
    {
    WLOG("CStatusPaneHandler::~CStatusPaneHandler >");
    TRAP_IGNORE( RestoreOriginalTitleL() );
    
    delete iNaviPaneHandler;
    WLOG("CStatusPaneHandler::~CStatusPaneHandler <");
    }
Пример #8
0
void UserSettings::FromXml(TiXmlElement* xml) {
  for (TiXmlElement* element = xml->FirstChildElement(); element; element = element->NextSiblingElement()) {
    wxString elementName = wxString(element->Value(), wxConvUTF8);

    if (elementName != _T("Setting")) {
      WLOG(wxString::Format(_T("UserSettings::FromXml: Unknown element: %s"), elementName));
      continue;
    }

    const char* cSettingName = element->Attribute("name");
    if (!cSettingName) {
      WLOG(_T("UserSettings::FromXml: setting doesn't have a name"));
      continue;
    }

    const char* cSettingValue = element->GetText();
    
    wxString n = wxString(cSettingName, wxConvUTF8);
    wxString v;
    if (!cSettingValue) {
      v = wxEmptyString;
    } else {
      v = wxString(cSettingValue, wxConvUTF8);
    }

    v.Trim(true).Trim(false);

    if (n == _T("IconSize")) AssignSettingValue(IconSize, v);
    if (n == _T("Locale")) Locale = v;
    if (n == _T("PortableAppsPath")) PortableAppsPath = v;
    if (n == _T("DocumentsPath")) DocumentsPath = v;
    if (n == _T("MusicPath")) MusicPath = v;
    if (n == _T("PicturesPath")) PicturesPath = v;
    if (n == _T("VideosPath")) VideosPath = v;
    if (n == _T("Skin")) Skin = v;
    if (n == _T("Rotated")) Rotated = ParseBoolean(v);
    if (n == _T("NextUpdateCheckTime")) {
      const wxChar* c = NextUpdateCheckTime.ParseFormat(v, ISO_DATE_FORMAT);
      if (!c) NextUpdateCheckTime = wxDateTime::Now();
    }
    if (n == _T("AlwaysOnTop")) AlwaysOnTop = ParseBoolean(v);
    if (n == _T("AutoHideApplication")) AutoHideApplication = ParseBoolean(v);
    if (n == _T("UniqueApplicationInstance")) UniqueApplicationInstance = ParseBoolean(v);
    if (n == _T("ShowDeleteIconMessage")) ShowDeleteIconMessage = ParseBoolean(v);
    if (n == _T("ShowEjectDriveMessage")) ShowEjectDriveMessage = ParseBoolean(v);
    if (n == _T("RunMultiLaunchOnStartUp")) RunMultiLaunchOnStartUp = ParseBoolean(v);
    if (n == _T("HotKeyControl")) HotKeyControl = ParseBoolean(v);
    if (n == _T("HotKeyAlt")) HotKeyAlt = ParseBoolean(v);
    if (n == _T("HotKeyShift")) HotKeyShift = ParseBoolean(v);
    if (n == _T("HotKeyKey")) AssignSettingValue(HotKeyKey, v);
    if (n == _T("CloseAppsOnEject")) CloseAppsOnEject = ParseBoolean(v);
    if (n == _T("MinimizeOnClose")) MinimizeOnClose = ParseBoolean(v);
    if (n == _T("ShowMinimizeMessage")) ShowMinimizeMessage = ParseBoolean(v);

  }

}
Пример #9
0
void WdtBase::configureThrottler() {
  WDT_CHECK(!throttler_);
  WVLOG(1) << "Configuring throttler options";
  throttler_ = Throttler::makeThrottler(options_);
  if (throttler_) {
    WLOG(INFO) << "Enabling throttling " << *throttler_;
  } else {
    WLOG(INFO) << "Throttling not enabled";
  }
}
Пример #10
0
bool mosq_setup(struct _squash *st)
{
	mosquitto_lib_init();

	DLOG("mosquitto -> (re)connecting\n");
	st->mosq = mosquitto_new(NULL, true, st);
	mosquitto_log_callback_set(st->mosq, mosq_logger);
	mosquitto_message_callback_set(st->mosq, st->msg_handler);
	int rc = mosquitto_connect(st->mosq, st->mq_host, 1883, 60);
	if (MOSQ_ERR_SUCCESS != rc) {
		WLOG("Failed to connect: %s\n", strerror(errno));
		rc = -1;
		goto unwind;
	}

	int mosq_fd = mosquitto_socket(st->mosq);
	if (evutil_make_socket_nonblocking(mosq_fd)) {
		WLOG("Failed to make non-blocking: fd = %d, possibly ok\n", mosq_fd);
	}
	st->mosq_readidle = event_new(st->base, mosq_fd, EV_READ|EV_PERSIST, mosq_ev_io, st);
	if (st->mosq_readidle == NULL) {
		WLOG("Failed to create mosquitto read/idle watcher\n");
		rc = -1;
		goto unwind_readidle;
	}
	st->mosq_write = event_new(st->base, mosq_fd, EV_WRITE, mosq_ev_io, st);
	if (st->mosq_write == NULL) {
		WLOG("Failed to create mosquitto write watcher\n");
		rc = -1;
		goto unwind_write;
	}
	if (mosquitto_want_write(st->mosq)) {
		event_add(st->mosq_write, NULL);
	}

	struct timeval mosq_idle_loop_time = { 0, 100 * 1000 };
	if (event_add(st->mosq_readidle, &mosq_idle_loop_time) < 0) {
		WLOG("Failed to activate mosquitto watcher\n");
		rc = -1;
		goto unwind_write;
	}
	goto out;

unwind_write:
	event_free(st->mosq_write);
unwind_readidle:
	event_free(st->mosq_readidle);
unwind:
	mosquitto_destroy(st->mosq);
	mosquitto_lib_cleanup();

out:
	return rc == 0;
}
Пример #11
0
void WdtBase::negotiateProtocol() {
  int protocol = transferRequest_.protocolVersion;
  WDT_CHECK(protocol > 0) << "Protocol version can't be <= 0 " << protocol;
  int negotiatedPv = Protocol::negotiateProtocol(protocol);
  if (negotiatedPv != protocol) {
    WLOG(WARNING) << "Negotiated protocol version " << protocol << " -> "
                  << negotiatedPv;
  }
  transferRequest_.protocolVersion = negotiatedPv;
  WLOG(INFO) << "using wdt protocol version "
             << transferRequest_.protocolVersion;
}
// -----------------------------------------------------------------------------
// CStatusPaneHandler::StrCopy
//
// -----------------------------------------------------------------------------
//
void CStatusPaneHandler::StrCopy( TDes& aTarget, const TDesC& aSource )
    {
    WLOG("CStatusPaneHandler::StrCopy >");
    TInt len = aTarget.MaxLength();
    if( len < aSource.Length() ) 
        {
        aTarget.Copy( aSource.Left(len) );
        return;
        }
    aTarget.Copy( aSource );
    WLOG("CStatusPaneHandler::StrCopy <");
    }
Пример #13
0
int64_t WdtSocket::ioWithAbortCheck(F readOrWrite, T tbuf, int64_t numBytes,
                                    int timeoutMs, bool tryFull) {
  WDT_CHECK(threadCtx_.getAbortChecker() != nullptr)
      << "abort checker can not be null";
  bool checkAbort = (threadCtx_.getOptions().abort_check_interval_millis > 0);
  auto startTime = Clock::now();
  int64_t doneBytes = 0;
  int retries = 0;
  while (doneBytes < numBytes) {
    const int64_t ret =
        readOrWrite(fd_, tbuf + doneBytes, numBytes - doneBytes);
    if (ret < 0) {
      // error
      if (errno != EINTR && errno != EAGAIN) {
        PLOG(ERROR) << "non-retryable error encountered during socket io "
                    << fd_ << " " << doneBytes << " " << retries;
        return (doneBytes > 0 ? doneBytes : ret);
      }
    } else if (ret == 0) {
      // eof
      WVLOG(1) << "EOF received during socket io. fd : " << fd_
               << ", finished bytes : " << doneBytes
               << ", retries : " << retries;
      return doneBytes;
    } else {
      // success
      doneBytes += ret;
      if (!tryFull) {
        // do not have to read/write entire data
        return doneBytes;
      }
    }
    if (checkAbort && threadCtx_.getAbortChecker()->shouldAbort()) {
      WLOG(ERROR) << "transfer aborted during socket io " << fd_ << " "
                  << doneBytes << " " << retries;
      return (doneBytes > 0 ? doneBytes : -1);
    }
    if (timeoutMs > 0) {
      int duration = durationMillis(Clock::now() - startTime);
      if (duration >= timeoutMs) {
        WLOG(INFO) << "socket io timed out after " << duration
                   << " ms, retries " << retries << " fd " << fd_
                   << " doneBytes " << doneBytes;
        return (doneBytes > 0 ? doneBytes : -1);
      }
    }
    retries++;
  }
  WVLOG_IF(1, retries > 1) << "socket io for " << doneBytes << " bytes took "
                           << retries << " retries";
  return doneBytes;
}
Пример #14
0
static int get_usb_mass_storage_status(libusb_device_handle *handle, uint8_t endpoint, uint32_t *tag)
{
    unsigned char csw[13];
    memset(csw, 0, sizeof(csw));
    int transferred;
    int ret;
    int try = 0;
    do {
        ret = libusb_bulk_transfer(handle, endpoint, (unsigned char *)&csw, sizeof(csw),
                &transferred, SG_TIMEOUT_MSEC);
        if (ret == LIBUSB_ERROR_PIPE) {
            libusb_clear_halt(handle, endpoint);
        }
        try++;
    } while ((ret == LIBUSB_ERROR_PIPE) && (try < 3));
    if (ret != LIBUSB_SUCCESS) {
        WLOG("%s: receiving failed: %d\n", __func__, ret);
        return -1;
    }
    if (transferred != sizeof(csw)) {
        WLOG("%s: received unexpected amount: %d\n", __func__, transferred);
        return -1;
    }

    uint32_t rsig = read_uint32(csw, 0);
    uint32_t rtag = read_uint32(csw, 4);
    /* uint32_t residue = read_uint32(csw, 8); */
#define USB_CSW_SIGNATURE 0x53425355  // 'U' 'S' 'B' 'S' (reversed)
    if (rsig != USB_CSW_SIGNATURE) {
        WLOG("status signature was invalid: %#x\n", rsig);
        return -1;
    }
    *tag = rtag;
    uint8_t rstatus = csw[12];
    return rstatus;
}

static int dump_CDB_command(uint8_t *cdb, uint8_t cdb_len) {
    char dbugblah[100];
    char *dbugp = dbugblah;
    dbugp += sprintf(dbugp, "Sending CDB [");
    for (uint8_t i = 0; i < cdb_len; i++) {
        dbugp += sprintf(dbugp, " %#02x", (unsigned int) cdb[i]);
    }
    sprintf(dbugp, "]\n");
    DLOG(dbugblah);
    return 0;
}
Пример #15
0
void ScreenManager::processFinishDialog() {
	if (dialogFinished_) {
		std::lock_guard<std::mutex> guard(inputLock_);
		// Another dialog may have been pushed before the render, so search for it.
		Screen *caller = 0;
		for (size_t i = 0; i < stack_.size(); ++i) {
			if (stack_[i].screen != dialogFinished_) {
				continue;
			}

			stack_.erase(stack_.begin() + i);
			// The previous screen was the caller (not necessarily the topmost.)
			if (i > 0) {
				caller = stack_[i - 1].screen;
			}
		}

		if (!caller) {
			ELOG("ERROR: no top screen when finishing dialog");
		} else if (caller != topScreen()) {
			// The caller may get confused if we call dialogFinished() now.
			WLOG("Skipping non-top dialog when finishing dialog.");
		} else {
			caller->dialogFinished(dialogFinished_, dialogResult_);
		}
		delete dialogFinished_;
		dialogFinished_ = 0;
	}
}
Пример #16
0
void unregister_gl_resource_holder(GfxResourceHolder *holder) {
	if (holders) {
		holders->remove(holder);
	} else {
		WLOG("GL resource holder not initialized or already shutdown, cannot unregister resource");
	}
}
Пример #17
0
void register_gl_resource_holder(GfxResourceHolder *holder) {
	if (holders) {
		holders->push_back(holder);
	} else {
		WLOG("GL resource holder not initialized, cannot register resource");
	}
}
Пример #18
0
bool getFileInfo(const char *path, FileInfo *fileInfo)
{
	// TODO: Expand relative paths?
	fileInfo->fullName = path;

#ifdef _WIN32
	fileInfo->size = 0;
	WIN32_FILE_ATTRIBUTE_DATA attrs;
	if (GetFileAttributesExA(path, GetFileExInfoStandard, &attrs)) {
		fileInfo->size = (uint64_t)attrs.nFileSizeLow | ((uint64_t)attrs.nFileSizeHigh << 32);
	}
	fileInfo->isDirectory = (attrs.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
	fileInfo->isWritable = (attrs.dwFileAttributes & FILE_ATTRIBUTE_READONLY) == 0;
#else
	struct stat64 file_info;

	std::string copy(path);
	stripTailDirSlashes(copy);

	int result = stat64(copy.c_str(), &file_info);

	if (result < 0) {
		WLOG("IsDirectory: stat failed on %s", path);
		return false;
	}

	fileInfo->isDirectory = S_ISDIR(file_info.st_mode);
	fileInfo->isWritable = false;
	fileInfo->size = file_info.st_size;
	// HACK: approximation
	if (file_info.st_mode & 0200)
		fileInfo->isWritable = true;
#endif
	return true;
}
Пример #19
0
/**
 * drop the table based on the provided table name,
 * this operator will delete the table in the catalog as well as the table file
 *on the disk or hdfs
 *
 * @param table_name
 * @return
 */
RetCode DropTableExec::DropTable(const string& table_name) {
  RetCode ret = rSuccess;
  Catalog* local_catalog = Environment::getInstance()->getCatalog();
  if ("" == table_name) {
    ret = rNULLDropTableName;
    WLOG(ret, "the name of the table to be dropped is NULL");
    return ret;
  }
  // start to drop table
  // you need to delete the file first, and then drop the informantion in the
  // catalog
  ret = DeleteTableFiles(table_name);
  if (rSuccess != ret) {
    ELOG(ret, "failed to delete the files when dropping table" + table_name);
    return ret;
  } else {
    ret = DropTableFromCatalog(table_name);
    if (ret != rSuccess) {
      ELOG(ret,
           "failed to drop the table from the catalog, while its files have "
           "been deleted, when dropping table" +
               table_name);
      return ret;
    }
  }
}
Пример #20
0
void basicTest(bool resumption) {
  auto &opts = WdtOptions::getMutable();
  opts.skip_writes = true;
  opts.enable_download_resumption = false;
  // Tmpfile (deleted)
  FILE *tmp = tmpfile();
  EXPECT_NE(tmp, nullptr);
  // We keep the fd around
  int fd = fileno(tmp);
  WLOG(INFO) << "tmp file fd " << fd;
  fclose(tmp);
  std::string recvDir;
  folly::toAppend("/tmp/wdtTest/recv", rand32(), &recvDir);
  WdtTransferRequest req(/* start port */ 0, /* num ports */ 3, recvDir);
  Receiver r(req);
  req = r.init();
  EXPECT_EQ(OK, req.errorCode);
  EXPECT_EQ(OK, r.transferAsync());
  // Not even using the actual name (which we don't know)
  req.fileInfo.push_back(WdtFileInfo(fd, 0, "notexisting23r4"));
  Sender s(req);
  // setWdtOptions not needed if change of option happens before sender cstror
  // but this indirectly tests that API (but need to manually see
  // "entered READ_FILE_CHUNKS" in the logs) TODO: test that programatically
  opts.enable_download_resumption = resumption;
  s.setWdtOptions(opts);
  req = s.init();
  EXPECT_EQ(OK, req.errorCode);
  auto report = s.transfer();
  EXPECT_EQ(OK, report->getSummary().getErrorCode());
  struct stat dirStat;
  int sret = stat(recvDir.c_str(), &dirStat);
  EXPECT_EQ(sret, -1);
  EXPECT_EQ(errno, ENOENT);
}
Пример #21
0
 void ActionGroup::Drop(const typeActionID theActionID)
 {
   // Make sure theActionID is currently registered with this ActionGroup
   if(IsAvailable(theActionID))
   {
     std::map<const typeActionID, IAction*>::iterator anIter;
     // See if theActionID is in our active list
     anIter = mActive.find(theActionID);
     if(anIter != mActive.end())
     {
       // Erase the action from the active list
       mActive.erase(anIter);
     }
     // See if theActionID is in our disabled list
     anIter = mDisabled.find(theActionID);
     if(anIter != mDisabled.end())
     {
       // Erase the action from the disabled list
       mDisabled.erase(anIter);
     }
   }
   else
   {
     WLOG() << "ActionGroup::Drop(" << theActionID
       << ") action is not registered!" << std::endl;
   }
 }
Пример #22
0
bool getFileInfo(const char *path, FileInfo *fileInfo)
{
	// TODO: Expand relative paths?
	fileInfo->fullName = path;

#ifdef _WIN32
	DWORD attributes = GetFileAttributes(path);
	fileInfo->isDirectory = (attributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
	fileInfo->isWritable = (attributes & FILE_ATTRIBUTE_READONLY) == 0;
#else
	struct stat64 file_info;

	std::string copy(path);
	stripTailDirSlashes(copy);

	int result = stat64(copy.c_str(), &file_info);

	if (result < 0) {
		WLOG("IsDirectory: stat failed on %s", path);
		return false;
	}

	fileInfo->isDirectory = S_ISDIR(file_info.st_mode);
	fileInfo->isWritable = false;
	// HACK: approximation
	if (file_info.st_mode & 0200)
		fileInfo->isWritable = true;
#endif
	return true;
}
Пример #23
0
void VulkanRenderManager::BeginFrame() {
	VLOG("BeginFrame");
	VkDevice device = vulkan_->GetDevice();

	int curFrame = vulkan_->GetCurFrame();
	FrameData &frameData = frameData_[curFrame];

	// Make sure the very last command buffer from the frame before the previous has been fully executed.
	if (useThread_) {
		std::unique_lock<std::mutex> lock(frameData.push_mutex);
		while (!frameData.readyForFence) {
			VLOG("PUSH: Waiting for frame[%d].readyForFence = 1", curFrame);
			frameData.push_condVar.wait(lock);
		}
		frameData.readyForFence = false;
	}

	VLOG("PUSH: Fencing %d", curFrame);
	vkWaitForFences(device, 1, &frameData.fence, true, UINT64_MAX);
	vkResetFences(device, 1, &frameData.fence);

	// Must be after the fence - this performs deletes.
	VLOG("PUSH: BeginFrame %d", curFrame);
	if (!run_) {
		WLOG("BeginFrame while !run_!");
	}
	vulkan_->BeginFrame();

	insideFrame_ = true;
}
Пример #24
0
/// Make room in growing array "gap" for at least "n" items.
///
/// @param gap
/// @param n
void ga_grow(garray_T *gap, int n)
{
  if (gap->ga_maxlen - gap->ga_len >= n) {
    // the garray still has enough space, do nothing
    return;
  }

  if (gap->ga_growsize < 1) {
    WLOG("ga_growsize(%d) is less than 1", gap->ga_growsize);
  }

  // the garray grows by at least growsize
  if (n < gap->ga_growsize) {
    n = gap->ga_growsize;
  }
  int new_maxlen = gap->ga_len + n;

  size_t new_size = (size_t)(gap->ga_itemsize * new_maxlen);
  size_t old_size = (size_t)(gap->ga_itemsize * gap->ga_maxlen);

  // reallocate and clear the new memory
  char *pp = xrealloc(gap->ga_data, new_size);
  memset(pp + old_size, 0, new_size - old_size);

  gap->ga_maxlen = new_maxlen;
  gap->ga_data = pp;
}
Пример #25
0
  void ActionGroup::Add(const typeActionID theActionID)
  {
    // Make sure theActionID hasn't been previously registered with this ActionGroup
    if(IsAvailable(theActionID) == false)
    {
      if(mActionSystem != NULL)
      {
        // Get anAction matching theActionID from the ActionSystem class
        IAction* anAction = mActionSystem->GetAction(theActionID);

        // Was a valid IAction pointer returned? then add to our disabled list
        if(anAction != NULL)
        {
          // Add this IAction to our disabled list
          mDisabled.insert(std::pair<const typeActionID, IAction*>(theActionID, anAction));
        }
        else
        {
          ELOG() << "ActionGroup::Add(" << theActionID
            << ") does not exist in ActionSystem class!" << std::endl;
        }
      }
      else
      {
        ELOG() << "ActionGroup::Add(" << theActionID
          << ") missing ActionSystem pointer, please call SetActionSystem first!"
          << std::endl;
      }
    }
    else
    {
      WLOG() << "ActionGroup::Add(" << theActionID
        << ") action is already registered!" << std::endl;
    }
  }
Пример #26
0
static void controller_cb_out(struct loop_fd *fd, int revents) {
	struct controller *controller = container_of(fd, struct controller, out);
	int result;

	VLOG("controller %p out %d", controller, revents);
	if (revents & (POLLHUP | POLLERR)) {
		ELOG("controller %p has error on stdout", controller);
		controller->out.poll_flags = 0;
		exit(0);
	}

	if (revents & POLLOUT) {
		/* flush data to pty */
		result = write(controller->out.fd, controller->buf_out, controller->buf_out_used);
		VLOG("wrote %d bytes to controller %p", result, controller);
		if (result < 0) {
			WLOG("error writing controller %p %d %d", controller, result, errno);
		} else if (result == 0) {
			/* The out fd closed */
			exit(0);
		} else {
			controller->buf_out_used -= result;
			if (controller->buf_out_used == 0)
				controller->out.poll_flags &= ~POLLOUT;
		}
	}
}
Пример #27
0
VkResult VulkanContext::InitDebugMsgCallback(PFN_vkDebugReportCallbackEXT dbgFunc, int bits, void *userdata) {
	VkDebugReportCallbackEXT msg_callback;

	if (!(flags_ & VULKAN_FLAG_VALIDATE)) {
		WLOG("Not registering debug report callback - extension not enabled!");
		return VK_SUCCESS;
	}
	ILOG("Registering debug report callback");

	VkDebugReportCallbackCreateInfoEXT cb = {};
	cb.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
	cb.pNext = nullptr;
	cb.flags = bits;
	cb.pfnCallback = dbgFunc;
	cb.pUserData = userdata;
	VkResult res = dyn_vkCreateDebugReportCallbackEXT(instance_, &cb, nullptr, &msg_callback);
	switch (res) {
	case VK_SUCCESS:
		msg_callbacks.push_back(msg_callback);
		break;
	case VK_ERROR_OUT_OF_HOST_MEMORY:
		return VK_ERROR_INITIALIZATION_FAILED;
	default:
		return VK_ERROR_INITIALIZATION_FAILED;
	}
	return res;
}
Пример #28
0
TEST(DupSend, DuplicateSend) {
  auto &opts = WdtOptions::getMutable();
  opts.skip_writes = true;
  opts.enable_download_resumption = false;
  // Tmpfile (deleted)
  FILE *tmp = tmpfile();
  EXPECT_NE(tmp, nullptr);
  // We keep the fd around
  int fd = fileno(tmp);
  WLOG(INFO) << "tmp file fd " << fd;
  fclose(tmp);
  WdtTransferRequest req(/* start port */ 0, /* num ports */ 3, "/tmp/wdtTest");
  Receiver r(req);
  req = r.init();
  EXPECT_EQ(OK, req.errorCode);
  EXPECT_EQ(OK, r.transferAsync());
  // Not even using the actual name (which we don't know)
  req.fileInfo.push_back(WdtFileInfo(fd, 0, "notexisting23r4"));
  Sender s(req);
  req = s.init();
  EXPECT_EQ(OK, req.errorCode);
  ErrorCode ret1 = s.transferAsync();
  EXPECT_EQ(OK, ret1);
  ErrorCode ret2 = s.transferAsync();
  EXPECT_EQ(ALREADY_EXISTS, ret2);
  auto report = s.finish();
  EXPECT_EQ(OK, report->getSummary().getErrorCode());
}
Пример #29
0
void Receiver::progressTracker() {
  // Progress tracker will check for progress after the time specified
  // in milliseconds.
  int progressReportIntervalMillis = options_.progress_report_interval_millis;
  int throughputUpdateIntervalMillis =
      options_.throughput_update_interval_millis;
  if (progressReportIntervalMillis <= 0 || throughputUpdateIntervalMillis < 0 ||
      !isJoinable_) {
    return;
  }
  int throughputUpdateInterval =
      throughputUpdateIntervalMillis / progressReportIntervalMillis;

  int64_t lastEffectiveBytes = 0;
  std::chrono::time_point<Clock> lastUpdateTime = Clock::now();
  int intervalsSinceLastUpdate = 0;
  double currentThroughput = 0;
  WLOG(INFO) << "Progress reporter updating every "
             << progressReportIntervalMillis << " ms";
  auto waitingTime = std::chrono::milliseconds(progressReportIntervalMillis);
  int64_t totalSenderBytes = -1;
  while (true) {
    {
      std::unique_lock<std::mutex> lock(mutex_);
      conditionFinished_.wait_for(lock, waitingTime);
      if (transferStatus_ == THREADS_JOINED) {
        break;
      }
    }
    double totalTime = durationSeconds(Clock::now() - startTime_);
    TransferStats globalStats;
    for (const auto &receiverThread : receiverThreads_) {
      globalStats += receiverThread->getTransferStats();
    }
    totalSenderBytes = globalStats.getTotalSenderBytes();
    if (totalSenderBytes == -1) {
      continue;
    }
    auto transferReport = folly::make_unique<TransferReport>(
        std::move(globalStats), totalTime, totalSenderBytes);
    intervalsSinceLastUpdate++;
    if (intervalsSinceLastUpdate >= throughputUpdateInterval) {
      auto curTime = Clock::now();
      int64_t curEffectiveBytes =
          transferReport->getSummary().getEffectiveDataBytes();
      double time = durationSeconds(curTime - lastUpdateTime);
      currentThroughput = (curEffectiveBytes - lastEffectiveBytes) / time;
      lastEffectiveBytes = curEffectiveBytes;
      lastUpdateTime = curTime;
      intervalsSinceLastUpdate = 0;
    }
    transferReport->setCurrentThroughput(currentThroughput);

    progressReporter_->progress(transferReport);
    if (reportPerfSignal_.notified()) {
      logPerfStats();
    }
  }
}
Пример #30
0
void Throttler::configureOptions(double& avgRateBytesPerSec,
                                 double& peakRateBytesPerSec,
                                 double& bucketLimitBytes) {
  if (peakRateBytesPerSec < avgRateBytesPerSec && peakRateBytesPerSec >= 0) {
    WLOG(WARNING) << "Per thread peak rate should be greater "
                  << "than per thread average rate. "
                  << "Making peak rate 1.2 times the average rate";
    peakRateBytesPerSec = kPeakMultiplier * (double)avgRateBytesPerSec;
  }
  if (bucketLimitBytes <= 0 && peakRateBytesPerSec > 0) {
    bucketLimitBytes =
        kTimeMultiplier * kBucketMultiplier * peakRateBytesPerSec;
    WLOG(INFO) << "Burst limit not specified but peak "
               << "rate is configured. Auto configuring to "
               << bucketLimitBytes / kMbToB << " Mbytes";
  }
}