Ejemplo n.º 1
0
   asset fee_schedule::calculate_fee( const operation& op, const price& core_exchange_rate )const
   {
      auto base_value = op.visit( calc_fee_visitor( *this, op ) );
      auto scaled = fc::uint128(base_value) * scale;
      scaled /= GRAPHENE_100_PERCENT;
      FC_ASSERT( scaled <= GRAPHENE_MAX_SHARE_SUPPLY );
      //idump( (base_value)(scaled)(core_exchange_rate) );
      auto result = asset( scaled.to_uint64(), asset_id_type(0) ) * core_exchange_rate;
      //FC_ASSERT( result * core_exchange_rate >= asset( scaled.to_uint64()) );

      while( result * core_exchange_rate < asset( scaled.to_uint64()) )
        result.amount++;

      FC_ASSERT( result.amount <= GRAPHENE_MAX_SHARE_SUPPLY );
      return result;
   }
Ejemplo n.º 2
0
	Data UInt64Parser::convert(string data_str){
		// simple convert using atoi 
		Data data(DATA_UINT64);
		uint64* val = new uint64;
		*val = to_uint64(data_str);
		data.set_data((void*)val);
		return data;
	}
Ejemplo n.º 3
0
bool
pair_t::to_uint64 (u_int64_t *v) const
{
  vec<u_int64_t> *p = to_uint64 ();
  if (p && p->size () > 0) {
    *v = (*p)[0];
    return true;
  }
  return false;
}
Ejemplo n.º 4
0
 static inline boost::uint64_t to_uint64(T1 high, T2 mid1, T3 mid2, T4 mid3, T5 mid4, T6 mid5, T7 mid6, T8 low) {
     return to_uint64(static_cast<unsigned char>(high),
                      static_cast<unsigned char>(mid1),
                      static_cast<unsigned char>(mid2),
                      static_cast<unsigned char>(mid3),
                      static_cast<unsigned char>(mid4),
                      static_cast<unsigned char>(mid5),
                      static_cast<unsigned char>(mid6),
                      static_cast<unsigned char>(low));
 }
Ejemplo n.º 5
0
   asset fee_schedule::calculate_fee( const operation& op, const price& core_exchange_rate )const
   {
      //idump( (op)(core_exchange_rate) );
      fee_parameters params; params.set_which(op.which());
      auto itr = parameters.find(params);
      if( itr != parameters.end() ) params = *itr;
      auto base_value = op.visit( calc_fee_visitor( params ) );
      auto scaled = fc::uint128(base_value) * scale;
      scaled /= GRAPHENE_100_PERCENT;
      FC_ASSERT( scaled <= GRAPHENE_MAX_SHARE_SUPPLY );
      //idump( (base_value)(scaled)(core_exchange_rate) );
      auto result = asset( scaled.to_uint64(), asset_id_type(0) ) * core_exchange_rate;
      //FC_ASSERT( result * core_exchange_rate >= asset( scaled.to_uint64()) );

      while( result * core_exchange_rate < asset( scaled.to_uint64()) )
        result.amount++;

      FC_ASSERT( result.amount <= GRAPHENE_MAX_SHARE_SUPPLY );
      return result;
   }
Ejemplo n.º 6
0
uint64_t get_tick_count()
{
	unsigned long tick_lo = ::GetTickCount();

	lock_scope<spin_mutex> lock(tick_count_mutex_);
	if (tick_lo < tick_count_prev_.LowPart) {
		++tick_count_prev_.HighPart;
	}
	tick_count_prev_.LowPart = tick_lo;
	return to_uint64(tick_count_prev_);
}
Ejemplo n.º 7
0
uint64_t get_idle_time()
{
	const size_t buffer_length = 328;
	vector<char> buffer(buffer_length);
	PSYSTEM_PERFORMANCE_INFORMATION spi = reinterpret_cast<PSYSTEM_PERFORMANCE_INFORMATION>(&*buffer.begin());

	NTSTATUS status = ::NtQuerySystemInformation(SystemPerformanceInformation, spi, buffer_length, NULL);
	if (!NT_SUCCESS(status)) {
		throw winnt_exception(status);
	}

	return to_uint64(reinterpret_cast<ULARGE_INTEGER &>(spi->IdleProcessTime));
}
Ejemplo n.º 8
0
uint64_t variant::as_uint64()const
{ try {
   switch( get_type() )
   {
      case string_type:
          return to_uint64(**reinterpret_cast<const const_string_ptr*>(this)); 
      case double_type:
          return static_cast<uint64_t>(*reinterpret_cast<const double*>(this));
      case int64_type:
          return static_cast<uint64_t>(*reinterpret_cast<const int64_t*>(this));
      case uint64_type:
          return *reinterpret_cast<const uint64_t*>(this);
      case bool_type:
          return static_cast<uint64_t>(*reinterpret_cast<const bool*>(this));
      case null_type:
          return 0;
      default:
         FC_THROW_EXCEPTION( bad_cast_exception,"Invalid cast from ${type} to uint64", ("type",get_type()));
   }
} FC_CAPTURE_AND_RETHROW( (*this) ) }
Ejemplo n.º 9
0
   variant number_from_stream( T& in )
   {
      fc::stringstream ss;

      bool  dot = false;
      bool  neg = false;
      if( in.peek() == '-')
      {
        neg = true;
        ss.put( in.get() );
      }
      bool done = false;

      try
      {
        char c;
        while((c = in.peek()) && !done)
        {

          switch( c )
          {
              case '.':
                 if (dot)
                    FC_THROW_EXCEPTION(parse_error_exception, "Can't parse a number with two decimal places");
                 dot = true;
                 FALLTHROUGH
              case '0':
              case '1':
              case '2':
              case '3':
              case '4':
              case '5':
              case '6':
              case '7':
              case '8':
              case '9':
                 ss.put( in.get() );
                 break;
              default:
                 if( isalnum( c ) )
                 {
                    return ss.str() + stringFromToken( in );
                 }
                done = true;
                break;
          }
        }
      }
      catch (fc::eof_exception&)
      { // EOF ends the loop
      }
      catch (const std::ios_base::failure&)
      { // read error ends the loop
      }
      std::string str = ss.str();
      if (str == "-." || str == "." || str == "-") // check the obviously wrong things we could have encountered
        FC_THROW_EXCEPTION(parse_error_exception, "Can't parse token \"${token}\" as a JSON numeric constant", ("token", str));
      if( dot )
        return
#ifdef WITH_EXOTIC_JSON_PARSERS
              parser_type == json::legacy_parser_with_string_doubles ? variant(str) :
#endif
                  variant(to_double(str));
      if( neg )
        return to_int64(str);
      return to_uint64(str);
   }
Ejemplo n.º 10
0
inline bool to_uint64(string const & s, uint64_t & i) { return to_uint64(s.c_str(), i); }
Ejemplo n.º 11
0
TermSession::TermSession(Logger &logger, PtLoginRequest *msg, TermConnection *tconn, LoginError *error)
    : ca_session_(0), term_conn_(tconn)
    , user_info_(msg->user_info_desc_.user_info_)
    , odclib_desc_(msg->odclib_desc_)
    , user_info_desc_(msg->user_info_desc_)
    , cert_data_desc_(msg->cert_data_desc_)
    , terminal_info_desc_(msg->terminal_info_desc_)
    , id_(0),caid_(0),valid_(false)
    , logger_(logger)
{
    // 描述符合法性验证
    if (!odclib_desc_.valid_) {
        *error = LoginOdcLibDescIncompleted;
        logger_.Warn("[Terminal Login Valid] OdcLib Descriptor incompleted");
        return;
    }
    if (!user_info_desc_.valid_) {
        *error = LoginUserInfoDescIncompleted;
        logger_.Warn("[Terminal Login Valid] UserInfo Descriptor incompleted");
        return;
    }
    if (!cert_data_desc_.valid_) {
        *error = LoginCertDataDescIncompleted;
        logger_.Warn("[Terminal Login Valid] CertData Descriptor incompleted");
        return;
    }
    if (!terminal_info_desc_.valid_) {
        *error = LoginTerminalInfoDescIncompleted;
        logger_.Warn("[Terminal Login Valid] Terminal Info Descriptor incompleted");
        return;
    }

    // 判断TerminalInfoDescriptor内容的正确性
    if (!IsValidTermInfoDesc(terminal_info_desc_)) {
        *error = LoginTerminalInfoInvalided;
        logger_.Warn("[Terminal Login Valid] TerminalInfo Descriptor Context Invalided, terminalinfo:"
                "\n\tclass: %s, \n\tsubclass: %s, \n\tmodel: %s, \n\tname: %s, \n\tcurr url: %s", 
                kTerminalClassName[terminal_info_desc_.terminal_class_ - 1].c_str(),
                kSubClassName[terminal_info_desc_.terminal_class_ - 1][terminal_info_desc_.terminal_sub_class_ - 1].c_str(),
                terminal_info_desc_.terminal_model_.c_str(),
                terminal_info_desc_.terminal_name_.c_str(),
                terminal_info_desc_.business_url_.c_str());
        return;
    }

    if (!user_info_.valid()) {
        *error = LoginUserInfoInvalided;
        logger_.Error("[Terminal Login Valid] UserInfo Invalided, userinfo: \n\t%s", msg->user_info_desc_.user_info_.c_str());
        return;
    }
    
    

    //get ca card id.
    bool cast_ok;
    caid_t caid = to_uint64(user_info_.card_id, &cast_ok);
    if (!cast_ok) {
        *error = LoginCastCAIdFailed;
        logger_.Error("[Terminal Login Valid] new TermSession convert string(%s) to uint64_t(caid) failure", 
                user_info_.card_id.c_str());
        return;
    }

    caid_ = caid;
    
    //cert.

    valid_ = true;
    *error = LoginOK;

    logger_.Trace("[Terminal Login Valid] new TermSession userinfo:"
        "\n\tuser id: %s, \n\tcaid: %s, \n\tterminal id: %s, \n\tmac addr: %s", 
        user_info_.id.c_str(), user_info_.card_id.c_str(), 
        user_info_.term_id.c_str(), user_info_.mac_addr.c_str());

    logger_.Trace("Terminal Login Valid] new TermSession terminalinfo:"
        "\n\tclass: %s, \n\tsubclass: %s, \n\tmodel: %s, \n\tname: %s, \n\tcurr url: %s", 
        kTerminalClassName[terminal_info_desc_.terminal_class_ - 1].c_str(),
        kSubClassName[terminal_info_desc_.terminal_class_ - 1][terminal_info_desc_.terminal_sub_class_ - 1].c_str(),
        terminal_info_desc_.terminal_model_.c_str(),
        terminal_info_desc_.terminal_name_.c_str(),
        terminal_info_desc_.business_url_.c_str());
}
Ejemplo n.º 12
0
int main(int argc, char *argv[])
{
    struct option long_opts[] = {
        { "async",         no_argument,       NULL, 'a' },
        { "break",         no_argument,       NULL, 'b' },
        { "disk",          required_argument, NULL, 'd' },
        { "get-status",    no_argument,       NULL, 'G' },
        { "help",          no_argument,       NULL, 'h' },
        { "list-statuses", no_argument,       NULL, 'L' },
        { "offset",        required_argument, NULL, 'o' },
/*      { "random",        no_argument,       NULL, 'r' }, */
        { "size",          required_argument, NULL, 's' },
        { "set-status",    required_argument, NULL, 'S' },
        { "write",         no_argument,       NULL, 'w' },
        { NULL,            0,                 NULL, '\0' }
    };
    int long_idx;
    int opt;
    enum {
        OP_IO,
        OP_LIST_STATUSES,
        OP_GET_STATUS,
        OP_SET_STATUS,
        OP_DEACTIVATE_DEVICE
    } op = OP_IO;
    char *disk_path = NULL;
/*     bool random = false; */
    bool async = false;
    bool write = false;
    uint64_t size_in_bytes = 0;
    uint64_t offset = 0;
    char status_str[256] = "";
    int err;

#ifdef WIN32
    os_windows_disable_crash_popup();
#endif

    program = argv[0];

    if (argc == 1)
    {
	fprintf(stderr, "%s: no option given\nType %s --help for usage help\n",
                program, program);
	return -1;
    }

    while (true)
    {
	opt = os_getopt_long(argc, argv, "ad:bGhLo:r:s:wS:", long_opts, &long_idx);
        /* Missing argument, quit right away (os_getopt_long() takes care of
         * printing an error message) */
        if (opt == ':' || opt == '?')
            return 1;

        if (opt == -1)
            break;

	switch (opt)
	{
	case 'a':
	    async = true;
	    break;

	case 'b':
	    op = OP_DEACTIVATE_DEVICE;
	    break;

	case 'd':
	    disk_path = optarg;
	    break;

        case 'G':
            op = OP_GET_STATUS;
            break;

	case 'h':
	    usage();
	    break;

        case 'L':
            op = OP_LIST_STATUSES;
            break;

	case 'o':
            if (to_uint64(optarg, &offset) != EXA_SUCCESS)
            {
                fprintf(stderr, "invalid offset\n");
                exit(1);
            }
	    break;

/* 	case 'r': */
/* 	    random = true; */
/* 	    break; */

	case 's':
            if (to_uint64(optarg, &size_in_bytes) != EXA_SUCCESS)
            {
                fprintf(stderr, "invalid size\n");
                exit(1);
            }
	    break;

	case 'w':
	    write = true;
	    break;

        case 'S':
            op = OP_SET_STATUS;
            strlcpy(status_str, optarg, sizeof(status_str));
            break;
	}
    }

    if (optind < argc)
    {
        fprintf(stderr, "%s: too many arguments\nType %s --help for usage help\n",
                program, program);
        return 1;
    }

    err = exa_rdev_static_init(RDEV_STATIC_GET);
    if (err != 0)
    {
        fprintf(stderr, "failed initializating RDEV statics: error %d\n", err);
        fprintf(stderr, "\tExanodes is probably not running on this node.\n");
        return 1;
    }

    if (disk_path == NULL && op != OP_LIST_STATUSES)
    {
        fprintf(stderr, "no disk path specified\n");
        err = -1;
        goto done;
    }

    switch (op)
    {
    case OP_IO:
        err = do_io(disk_path, async, write, offset, size_in_bytes);
        break;

    case OP_LIST_STATUSES:
        err = list_statuses();
        break;

    case OP_GET_STATUS:
        err = do_status(disk_path, 'g', NULL);
        break;

    case OP_SET_STATUS:
        err = do_status(disk_path, 's', status_str);
        break;

    case OP_DEACTIVATE_DEVICE:
	err = deactivate_device(disk_path);
	break;
    }

done:
    exa_rdev_static_clean(RDEV_STATIC_RELEASE);
    return err ? 1 : 0;
}
Ejemplo n.º 13
0
int main(int argc, char *argv[])
{
  bool static_init_ok = false;
  const char *action;
  int err = 0;

  self = os_program_name(argv[0]);

  if (argc <= 1)
  {
      usage();
      err = 1;
      goto done;
  }

  err = examsg_static_init(EXAMSG_STATIC_GET);
  if (err != 0)
  {
      fprintf(stderr, "examsg_static_init failed: %s (%d)\n", exa_error_msg(-err), err);
      goto done;
  }
  static_init_ok = true;

  mh = examsgInit(EXAMSG_TEST_ID);
  if (!mh)
  {
      fprintf(stderr, "examsgInit failed\n");
      goto done;
  }

  err = examsgAddMbox(mh, examsgOwner(mh), 3, EXAMSG_MSG_MAX);
  if (err != 0)
  {
      fprintf(stderr, "examsgAddMbox failed: %s (%d)\n", exa_error_msg(-err), err);
      goto done;
  }

  action = argv[1];
  if (strcmp(action, "is_fs_mounted") == 0)
  {
      int m;

      if (argc != 3)
      {
          usage();
          goto done;
      }

      m = fsd_is_fs_mounted(mh, argv[2]);
      if (m < 0)
          err = m;
  }
  else if (strcmp(action, "is_mountpoint_used") == 0)
  {
      int u;

      if (argc != 3)
      {
          usage();
          goto done;
      }

      u = fsd_is_mountpoint_used(mh, argv[2]);
      if (u < 0)
          err = u;
  }
  else if (strcmp(action, "prepare_gfs") == 0)
  {
      fs_data_t fs;
      size_t sz;

      if (argc != 3)
      {
          usage();
          goto done;
      }

      COMPILE_TIME_ASSERT(sizeof("sfs") <= sizeof(fs.fstype));
      os_strlcpy(fs.fstype, "sfs", sizeof(fs.fstype));

      sz = os_strlcpy(fs.clustered.gfs.lock_protocol, argv[2],
                      sizeof(fs.clustered.gfs.lock_protocol));
      if (sz >= sizeof(fs.clustered.gfs.lock_protocol))
      {
          fprintf(stderr, "Invalid lock protocol: '%s' (too long)\n", argv[2]);
          goto done;
      }

      err = fsd_prepare(mh, &fs);
  }
  else if (strcmp(action, "mount") == 0)
  {
      fs_data_t fs;
      size_t sz;

      if (argc != 7)
      {
          usage();
          goto done;
      }

      sz = os_strlcpy(fs.fstype, argv[2], sizeof(fs.fstype));
      if (sz >= sizeof(fs.fstype))
      {
          fprintf(stderr, "Invalid fs type: '%s' (too long)\n", argv[2]);
          goto done;
      }

      sz = os_strlcpy(fs.mountpoint, argv[3], sizeof(fs.mountpoint));
      if (sz >= sizeof(fs.mountpoint))
      {
          fprintf(stderr, "Invalid mountpoint: '%s' (too long)\n", argv[3]);
          goto done;
      }

      sz = os_strlcpy(fs.devpath, argv[4], sizeof(fs.devpath));
      if (sz >= sizeof(fs.devpath))
      {
          fprintf(stderr, "Invalid dev path: '%s' (too long)\n", argv[4]);
          goto done;
      }

      err = fsd_mount(mh, &fs, 1 , 0, argv[5], argv[6]);
  }
  else if (strcmp(action, "umount") == 0)
  {
      fs_data_t fs;
      size_t sz;

      if (argc != 6)
      {
          usage();
          goto done;
      }

      sz = os_strlcpy(fs.mountpoint, argv[2], sizeof(fs.mountpoint));
      if (sz >= sizeof(fs.mountpoint))
      {
          fprintf(stderr, "Invalid mountpoint: '%s' (too long)\n", argv[2]);
          goto done;
      }

      sz = os_strlcpy(fs.devpath, argv[3], sizeof(fs.devpath));
      if (sz >= sizeof(fs.devpath))
      {
          fprintf(stderr, "Invalid dev path: '%s' (too long)\n", argv[3]);
          goto done;
      }

      err = fsd_umount(mh, &fs, argv[5], argv[6]);
  }
  else if (strcmp(action, "unload") == 0)
  {
      fs_data_t fs;
      size_t sz;

      if (argc != 3)
      {
          usage();
          goto done;
      }

      sz = os_strlcpy(fs.fstype, argv[2], sizeof(fs.fstype));
      if (sz >= sizeof(fs.fstype))
      {
          fprintf(stderr, "Invalid fs type: '%s' (too long)\n", argv[2]);
          goto done;
      }

      err = fsd_unload(mh, &fs);
  }
  else if (strcmp(action, "create_local") == 0)
  {
      if (argc != 4)
      {
          usage();
          goto done;
      }

      err = fsd_fs_create_local(mh, argv[2], argv[3]);
  }
  else if (strcmp(action, "create_gfs") == 0)
  {
      fs_data_t fs;
      size_t sz;

      if (argc != 7)
      {
          usage();
          goto done;
      }

      COMPILE_TIME_ASSERT(sizeof("sfs") <= sizeof(fs.fstype))
      sz = os_strlcpy(fs.fstype, "sfs", sizeof(fs.fstype));

      sz = os_strlcpy(fs.devpath, argv[2], sizeof(fs.devpath));
      if (sz >= sizeof(fs.devpath))
      {
          fprintf(stderr, "Invalid dev path: '%s' (too long)\n", argv[2]);
          goto done;
      }

      sz = os_strlcpy(fs.clustered.gfs.lock_protocol, argv[3],
                      sizeof(fs.clustered.gfs.lock_protocol));
      if (sz >= sizeof(fs.clustered.gfs.lock_protocol))
      {
          fprintf(stderr, "Invalid lock protocol: '%s' (too long)\n", argv[3]);
          goto done;
      }

      if (to_uint64(argv[4], &fs.sizeKB) != EXA_SUCCESS)
      {
          fprintf(stderr, "Invalid size: '%s'\n", argv[4]);
          goto done;
      }

      sz = os_strlcpy(fs.clustered.gfs.uuid, argv[5], sizeof(fs.clustered.gfs.uuid));
      if (sz >= sizeof(fs.clustered.gfs.uuid))
      {
          fprintf(stderr, "Invalid GFS uuid: '%s' (too long)\n", argv[5]);
          goto done;
      }

      if (to_uint64(argv[6], &fs.clustered.gfs.nb_logs) != EXA_SUCCESS)
      {
          fprintf(stderr, "Invalid number of logs: '%s'\n", argv[6]);
          goto done;
      }

      err = fsd_fs_create_gfs(mh, &fs);
  }
  else if (strcmp(action, "dfinfo") == 0)
  {
      struct fsd_capa buf;

      if (argc != 3)
      {
          usage();
          goto done;
      }

      err = fsd_df(mh, argv[2], &buf);
      if (err == 0)
          printf("size=%"PRId64" bytes\n"
                 "used=%"PRId64" bytes\n"
                 "free=%"PRId64" bytes\n",
                 buf.size, buf.used, buf.free);
  }
  else if (strcmp(action, "resize") == 0)
  {
      uint64_t size_kb;

      if (argc != 6)
      {
          usage();
          goto done;
      }

      if (to_uint64(argv[5], &size_kb) != EXA_SUCCESS)
      {
          fprintf(stderr, "Invalid new size: '%s'\n", argv[5]);
          goto done;
      }

      err = fsd_resize(mh, argv[2], argv[3], argv[4], size_kb);
  }
  else if (strcmp(action, "prepare_resize") == 0)
  {
      if (argc != 4)
      {
          usage();
          goto done;
      }

      err = fsd_prepare_resize(mh, argv[2], argv[3]);
  }
  else if (strcmp(action, "read_shm") == 0)
  {
      read_shm();
  }
  else if (strcmp(action, "add_logs") == 0)
  {
      fs_data_t fs;
      int num_logs, actual_num_logs;
      size_t sz;

      if (argc != 4)
      {
          usage();
          goto done;
      }

      COMPILE_TIME_ASSERT(sizeof("sfs") <= sizeof(fs.fstype));
      os_strlcpy(fs.fstype, "sfs", sizeof(fs.fstype));

      sz = os_strlcpy(fs.devpath, argv[2], sizeof(fs.devpath));
      if (sz >= sizeof(fs.devpath))
      {
          fprintf(stderr, "Invalid dev path: '%s' (too long)\n", argv[2]);
          goto done;
      }

      if (to_int(argv[3], &num_logs) != EXA_SUCCESS)
      {
          fprintf(stderr, "Invalid number of logs: '%s'\n", argv[3]);
          goto done;
      }

      actual_num_logs = fsd_set_gfs_logs(mh, &fs, num_logs);
      if (actual_num_logs < 0)
          err = actual_num_logs;
      else
      {
	  examsgDelMbox(mh, EXAMSG_TEST_ID);
	  printf("Number of logs after the operation: %d\n", actual_num_logs);
      }
  }
  else
      usage();

  if (err != 0)
      fprintf(stderr, "Action finished with error %d: %s\n", err,
              exa_error_msg(-err));

done:

  examsgDelMbox(mh, EXAMSG_TEST_ID);

  if (mh != NULL)
      examsgExit(mh);

  if (static_init_ok)
      examsg_static_clean(EXAMSG_STATIC_RELEASE);

  return err == 0 ? 0 : 1;
}
Ejemplo n.º 14
0
 static inline boost::uint64_t to_uint64(const Byte *buf) {
     return to_uint64(buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]);
 }
Ejemplo n.º 15
0
/**
 *  This function is for the counter thread.
 *
 *  @param t argument
 *
 *  @return SUCCESS or FAIL
 */
static void *counter(void *t)
{
    int counter_id = assign_counter_id();
    int s = ALDER_STATUS_SUCCESS;
    alder_kmer_thread7_t *a = (alder_kmer_thread7_t*)t;
    assert(a != NULL);
    alder_log2("counter(%d)[%llu]: START", counter_id, a->i_ni);
    
    /* Numbers for decoding kmers. */
    alder_encode_number_t *m = alder_encode_number_create_for_kmer(a->k);
    alder_encode_number2_t *m2 = alder_encode_number2_createWithKmer(a->k);
    uint64_t *res_key = malloc(sizeof(*res_key) * m->s);
    if (m == NULL || m2 == NULL || res_key == NULL) {
        alder_loge(ALDER_ERR_MEMORY, "Fatal - counter(): not enough memory");
        pthread_exit(NULL);
    }
    memset(res_key, 0, sizeof(*res_key) * m->s);
    size_t ib = m2->b / 8;
    size_t jb = m2->b % 8;
    
#if !defined(NDEBUG)
    size_t debug_counter = 0;
#endif
    
    /* Let's read inputs, and skip writing table files. */
    size_t c_table = 1;
    uint64_t i_np = a->n_np;
    while (1) {
        
        ///////////////////////////////////////////////////////////////////////
        // Writer
        ///////////////////////////////////////////////////////////////////////
        if (c_table < 1) {
            s = write_tabfile(a, c_table, i_np);
            if (s != ALDER_STATUS_SUCCESS) {
                alder_loge(ALDER_ERR_FILE, "failed to write to the table");
                break;
            }
            c_table = 1;
        }
        
        /* Check if this is the final. */
        if (a->n_blockByReader[a->n_np] == a->n_blockByCounter[a->n_np]) {
            /* Exit! */
            break;
        }
        
        ///////////////////////////////////////////////////////////////////////
        // Reader
        ///////////////////////////////////////////////////////////////////////
        s = read_parfile(a, counter_id);
        if (s == NO_READ) {
            break;
        }
        
        ///////////////////////////////////////////////////////////////////////
        // Counter
        ///////////////////////////////////////////////////////////////////////
        assert(c_table == a->n_ht);
        
        /* setup of inbuf */
        uint8_t *inbuf = a->inbuf + counter_id * a->size_subinbuf;
        i_np = to_uint64(inbuf,INBUFFER_I_NP);
        size_t lenbuf = to_size(inbuf,INBUFFER_LENGTH);
        uint8_t *inbuf_body = inbuf + INBUFFER_BODY;
        
        while (a->main_i_np < i_np) {
            asm("");
        }
        if (lenbuf > 0) {
            assert(a->main_i_np == i_np);
        }
        
        /* setup of table */
        alder_hashtable_mcas_t *c_ht = NULL;
        c_table = 0;
        
        assert(c_table < a->n_ht);
        c_ht = a->ht[c_table];
        assert(lenbuf % m2->b == 0);
        uint64_t n_kmer = lenbuf / m2->b;
        size_t x = 0;
        for (uint64_t i_kmer = 0; i_kmer < n_kmer; i_kmer++) {
            a->n_i_kmer[counter_id]++;
            
#if !defined(NDEBUG)
            debug_counter++;
#endif
            
            /*****************************************************************/
            /*                         OPTIMIZATION                          */
            /*****************************************************************/
            /* Decode a kmer. */
            uint64_t *inbuf_body_uint64 = (uint64_t*)(inbuf_body + x);
            for (size_t i = 0; i < ib; i++) {
                m->n[i] = inbuf_body_uint64[i];
            }
            x += (8 * ib);
            if (jb > 0) {
                for (size_t j = 0; j < jb; j++) {
                    m2->n[ib].key8[j] = inbuf_body[x++];
                }
                m->n[ib] = m2->n[ib].key64;
            }
            /*****************************************************************/
            /*                         OPTIMIZATION                          */
            /*****************************************************************/
            
            s = alder_hashtable_mcas_increment(c_ht, m->n, res_key,
                                               a->isMultithreaded);
            
            if (s != ALDER_STATUS_SUCCESS) {
                alder_loge(ALDER_ERR, "Fatal - table is full!");
                assert(0);
                abort();
            }
        }
        assert(x == lenbuf);
        
        if (lenbuf > 0) {
            alder_kmer_thread7_increment_n_block(a, i_np);
            
            if (a->n_blockByCounter[i_np] == a->n_blockByReader[i_np]) {
                // No code.
                a->n_blockByCounter[a->n_np] += a->n_blockByCounter[i_np];
            } else {
                // Not the last bock, so won't write to a table file.
                c_table = a->n_ht;
            }
        } else {
            c_table = a->n_ht;
        }
        
        /* When parfile is zero... */
        if (a->n_blockByReader[i_np] == 0) { // && counter_id == 0) {
            int oval = a->n_blockByReader[i_np];
            int cval = oval + 1;
            cval = __sync_val_compare_and_swap(a->n_blockByReader + i_np,
                                               (int)oval, (int)cval);
            if (a->n_blockByReader[i_np] == 1) {
                a->main_i_np++;
            }
        }
    }
    XFREE(res_key);
    alder_encode_number_destroy(m);
    alder_encode_number2_destroy(m2);
    alder_log2("counter(%d)[%llu]: END", counter_id, a->i_ni);
    pthread_exit(NULL);
}
Ejemplo n.º 16
0
/**
 *  This function reads a block of partition files.
 *
 *  @param a          counter
 *  @param counter_id counter id
 *
 *  @return SUCCESS or FAIL or ALDER_KMER_THREAD7_NO_READ
 */
static __attribute__ ((noinline)) int
read_parfile(alder_kmer_thread7_t *a, int counter_id)
{
    int s = ALDER_STATUS_SUCCESS;
    pthread_mutex_lock(&mutex_read);
    
    if (a->reader_lenbuf == 0) {
        if (a->reader_i_parfile > 0) {
            close_parfile(a);
        }
        if (a->reader_i_parfile < a->n_np) {
            s = open_parfile(a, a->reader_i_parfile);
            if (s != ALDER_STATUS_SUCCESS) {
                return s;
            }
            a->reader_i_parfile++;
        } else {
            // No more input file to read.
            pthread_mutex_unlock(&mutex_read);
            return NO_READ;
        }
    }
    
    /* Read a block of input buffer. */
    ssize_t lenbuf = 0;
    uint8_t *inbuf = a->inbuf + counter_id * a->size_subinbuf;
    uint8_t *inbuf_body = inbuf + INBUFFER_BODY;
    size_t cur_next_lenbuf = a->next_lenbuf;
    if (a->next_lenbuf > 0) {
        memcpy(inbuf_body, a->next_inbuf, a->next_lenbuf);
        inbuf_body += a->next_lenbuf;
    }
    lenbuf = read(fileno(a->fpin), inbuf_body, a->size_readbuffer);
    assert(lenbuf == 0 || lenbuf >= a->b);
    if (lenbuf > 0 && a->b > 1) {
        assert(cur_next_lenbuf + lenbuf >= a->b);
        a->next_lenbuf = (cur_next_lenbuf + lenbuf) % a->b;
        memcpy(a->next_inbuf, inbuf_body + lenbuf - a->next_lenbuf, a->next_lenbuf);
        a->reader_lenbuf = cur_next_lenbuf + lenbuf - a->next_lenbuf;
    } else if (lenbuf > 0 && a->b == 1) {
        a->next_lenbuf = 0;
        a->reader_lenbuf = lenbuf;
    } else if (lenbuf == 0) {
        assert(cur_next_lenbuf == 0);
        a->reader_lenbuf = lenbuf;
    } else {
        // Error in reading.
        assert(0);
        abort();
    }
    assert(a->reader_i_parfile <= a->n_np);
    
    to_uint64(inbuf,INBUFFER_I_NP) = a->reader_i_parfile - 1;
    to_size(inbuf,INBUFFER_LENGTH) = a->reader_lenbuf;
    assert(a->reader_lenbuf % a->b == 0);
    
    /* Progress */
    a->n_byte += lenbuf;
    
    pthread_mutex_unlock(&mutex_read);
    return ALDER_STATUS_SUCCESS;
}
Ejemplo n.º 17
0
uint64_t base_operation::calculate_data_fee( uint64_t bytes, uint64_t price_per_kbyte )
{
   auto result = (fc::uint128(bytes) * price_per_kbyte) / 1024;
   FC_ASSERT( result <= GRAPHENE_MAX_SHARE_SUPPLY );
   return result.to_uint64();
}
Ejemplo n.º 18
0
int main(int argc, char **argv)
{
    int di;
    char *cp;
    int inFd = -1;
    int outFd = -1;
    int inCc = 0;
    int outCc;
    char *inFile;
    char *outFile;
    uint64_t blockSize, readSize;
    uint64_t size;
    uint64_t intotal;
    uint64_t outTotal;
    char *buf = NULL;
    char hex_output[16 * 2 + 1];

    self = strrchr(argv[0], '/');
    if (self == NULL)
        self = argv[0];
    else
        self++;

    /* Parse any options */
    if (argc != 5)
    {
        fprintf(stderr, "dd with md5 checksum.\n");
        fprintf(stderr, "\n");
        fprintf(stderr, "usage: %s <if> <of> <bufsize> <count>\n", self);
        fprintf(stderr, "\n");
        fprintf(stderr, "    <if>       Input file\n");
        fprintf(stderr, "    <of>       Output file\n");
        fprintf(stderr, "    <bufsize>  Size of buffer\n");
        fprintf(stderr, "    <count>    Number of bytes to copy\n");
        fprintf(stderr, "\n");
        fprintf(stderr, "NOTES:\n");
        fprintf(stderr, "  - The actual number of bytes copied may be greater"
                             " than the specified count\n"
                        "    because of the buffer size.\n");
        fprintf(stderr, "  - The computed md5 is appended to the end of the"
                             " output file (no idea why).\n");
        exit(1);
    }

    inFile  = argv[1];
    outFile = argv[2];

    if (to_uint64(argv[3], &blockSize) != EXA_SUCCESS)
    {
        error("invalid buffer size: '%s'", argv[3]);
        goto done;
    }

    if (to_uint64(argv[4], &size) != EXA_SUCCESS)
    {
        error("invalid byte count: '%s'", argv[4]);
        goto done;
    }

    if ((buf = malloc(blockSize)) == NULL)
    {
        error("alloc buffer: %s", exa_error_msg(-errno));
        goto done;
    }

    intotal  = 0;
    outTotal = 0;

    /* Open the source file*/
    inFd = open(inFile, 0);
    if (inFd < 0)
    {
        error("open input file %s: %s",inFile, exa_error_msg(-errno));
        goto done;
    }

    /* Open the dest file*/
    outFd = open(outFile, O_WRONLY | O_CREAT | O_TRUNC, 0666);
    if (outFd < 0)
    {
        error("open output file %s: %s",outFile, exa_error_msg(-errno));
        goto done;
    }

    lseek(inFd, 0, SEEK_SET);
    lseek(outFd, 0, SEEK_SET);

    readSize = blockSize;

    /* Write the file with block  */
    while (outTotal < size)
    {

        /* Read the source file */
        inCc = read(inFd, buf, readSize);
        if (inCc <= 0)
        {
            error("read: %s", exa_error_msg(-errno));
            goto done;
        }

        intotal += inCc;
        cp = buf;
        outCc = 0;

        /* Write on the dest file */
        while (outCc < inCc)
        {
            md5_state_t state;
            md5_byte_t digest[16];

            outCc = write(outFd, cp, inCc);
            if (outCc <= 0)
            {
                error("write: %s", exa_error_msg(-errno));
                goto done;
            }

            inCc -= outCc;
            outTotal += outCc;

            /* Manage the check sum */
            md5_init(&state);
            md5_append(&state, (const md5_byte_t *)cp,outCc);
            md5_finish(&state, digest);
            for (di = 0; di < 16; ++di)
                sprintf(hex_output + di * 2, "%02x", digest[di]);

            cp += outCc;
        }

        /* End of the file */
        if (size - outTotal < blockSize)
            readSize = size - outTotal;
    }

    lseek(outFd, 0,SEEK_END);
    if (write(outFd, hex_output, strlen(hex_output)) <= 0)
    {
        error("write md5: %s", exa_error_msg(-errno));
        goto done;
    }

done:
    if (inFd != -1 && close(inFd) != 0)
        error("close %s: %s", inFile, exa_error_msg(-errno));

    if (outFd != -1 && close(outFd) != 0)
        error("close %s: %s", outFile, exa_error_msg(-errno));

    sync();
    free(buf);

    return err ? 1 : 0;
}