void clIndexerRequest::fromBinary(char* data) { UNPACK_INT(m_cmd, data); UNPACK_STD_STRING(m_ctagOptions, data); UNPACK_STD_STRING(m_databaseFileName, data); // read the number of files size_t numFiles(0); UNPACK_INT(numFiles, data); m_files.clear(); for (size_t i=0; i<numFiles; i++) { std::string file_name; UNPACK_STD_STRING(file_name, data); m_files.push_back(file_name); } }
static void do_get(void* arg) { PortState* state = (PortState*)arg; // Unpack key from work buffer // table - 8 bytes // keysz - 1 byte // key - variable ib_id_t table ; UNPACK_INT(state->work_buffer, 0, &table); unsigned char keysz = UNPACK_BYTE(state->work_buffer, sizeof(table)); char* key = UNPACK_BLOB(state->work_buffer, sizeof(table)+1); ib_trx_t txn = ib_trx_begin(IB_TRX_REPEATABLE_READ); ib_crsr_t cursor; FAIL_ON_ERROR(ib_cursor_open_table_using_id(table, txn, &cursor), ROLLBACK_RETURN(txn)); ib_tpl_t key_tuple = ib_clust_search_tuple_create(cursor); ib_col_set_value(key_tuple, KEY_COL, key, keysz); int searchloc; ib_err_t error = ib_cursor_moveto(cursor, key_tuple, IB_CUR_GE, &searchloc); // Drop the key tuple -- cursor is at desired location ib_tuple_delete(key_tuple); // If we encountered an error, bail if (error != DB_SUCCESS && error != DB_RECORD_NOT_FOUND && error != DB_END_OF_INDEX) { ib_cursor_close(cursor); send_error_str(state, ib_strerror(error)); ROLLBACK_RETURN(txn); } // Found it, read the value and send back to caller if (searchloc == 0) { ib_tpl_t tuple = ib_clust_read_tuple_create(cursor); // TODO: May need better error handling here FAIL_ON_ERROR(ib_cursor_read_row(cursor, tuple), { ib_tuple_delete(tuple); ib_cursor_close(cursor); ROLLBACK_RETURN(txn); });
SEXP do_rtruncnorm(SEXP s_n, SEXP s_a, SEXP s_b, SEXP s_mean, SEXP s_sd) { R_len_t i, nn; UNPACK_INT(s_n, n); if (NA_INTEGER == n) error("n is NA - aborting."); UNPACK_REAL_VECTOR(s_a, a, n_a); UNPACK_REAL_VECTOR(s_b, b, n_b); UNPACK_REAL_VECTOR(s_mean, mean, n_mean); UNPACK_REAL_VECTOR(s_sd, sd, n_sd); nn = MAX(n, MAX(MAX(n_a, n_b), MAX(n_mean, n_sd))); ALLOC_REAL_VECTOR(s_ret, ret, nn); GetRNGstate(); for (i = 0; i < nn; ++i) { const double ca = a[i % n_a]; const double cb = b[i % n_b]; const double cmean = mean[i % n_mean]; const double csd = sd[i % n_sd]; if (R_FINITE(ca) && R_FINITE(cb)) { ret[i] = r_truncnorm(ca, cb, cmean, csd); } else if (R_NegInf == ca && R_FINITE(cb)) { ret[i] = r_righttruncnorm(cb, cmean, csd); } else if (R_FINITE(ca) && R_PosInf == cb) { ret[i] = r_lefttruncnorm(ca, cmean, csd); } else if (R_NegInf == ca && R_PosInf == cb) { ret[i] = rnorm(cmean, csd); } else { ret[i] = NA_REAL; } R_CheckUserInterrupt(); } PutRNGstate(); UNPROTECT(1); /* s_ret */ return s_ret; }
static void do_set_cfg(void* arg) { PortState* state = (PortState*)arg; erl_drv_mutex_lock(G_ENGINE_STATE_LOCK); if (G_ENGINE_STATE == ENGINE_STOPPED) { char* key = UNPACK_STRING(state->work_buffer, 0); const char* value = UNPACK_STRING(state->work_buffer, strlen(key)+1); if (strcmp(key, "error_log") == 0) { if (set_log_file(value) == 0) { send_ok(state); } else { send_error_atom(state, "einval"); } } else { // Check the expected type of the provided key so as to 1. validate it's a good key // and 2. know what setter to use. ib_cfg_type_t key_type; ib_err_t error = ib_cfg_var_get_type(key, &key_type); if (error == DB_SUCCESS) { if (key_type == IB_CFG_TEXT) { // HACK: Semantics of setting a text configuration value for innodb changed // to be pointer assignment (from copy) for vsn 1.0.6.6750. So, we strdup the // value to ensure everything works as expected. // TODO: Setup some sort of list of strdup'd values to ensure they all get // cleaned up properly. In typical usage, this isn't going to be a problem // as you only initialize once per run, but it bothers me just the same. error = ib_cfg_set(key, strdup(value)); } else { ErlDrvUInt value_i; UNPACK_INT(state->work_buffer, strlen(key)+1, &value_i); error = ib_cfg_set(key, value_i); } } if (error == DB_SUCCESS) { send_ok(state); } else { send_error_str(state, ib_strerror(error)); } } } else { send_error_atom(state, "starting"); } erl_drv_mutex_unlock(G_ENGINE_STATE_LOCK); }
int bdberl_stats_control(PortData* d, unsigned int cmd, char* inbuf, int inbuf_sz, char** outbuf, int outbuf_sz) { switch(cmd) { case CMD_DB_STAT: { FAIL_IF_ASYNC_PENDING(d, outbuf); // Inbuf is << DbRef:32, Flags:32 >> int dbref = UNPACK_INT(inbuf, 0); // Make sure this port currently has dbref open -- if it doesn't, error out. Of note, // if it's in our list, we don't need to grab the RWLOCK, as we don't have to worry about // the underlying handle disappearing since we have a reference. if (bdberl_has_dbref(d, dbref)) { // Mark the port as busy and then schedule the appropriate async operation d->async_dbref = dbref; d->async_op = cmd; d->async_flags = UNPACK_INT(inbuf, 4); bdberl_general_tpool_run(&do_async_stat, d, 0, &d->async_job); // Let caller know that the operation is in progress // Outbuf is: <<0:32>> RETURN_INT(0, outbuf); } else { // Invalid dbref RETURN_INT(ERROR_INVALID_DBREF, outbuf); } } case CMD_DB_STAT_PRINT: { FAIL_IF_ASYNC_PENDING(d, outbuf); // Inbuf is << DbRef:32, Flags:32 >> int dbref = UNPACK_INT(inbuf, 0); // Make sure this port currently has dbref open -- if it doesn't, error out. Of note, // if it's in our list, we don't need to grab the RWLOCK, as we don't have to worry about // the underlying handle disappearing since we have a reference. if (bdberl_has_dbref(d, dbref)) { DB* db = bdberl_lookup_dbref(dbref); unsigned int flags = UNPACK_INT(inbuf, 4); // Outbuf is <<Rc:32>> // Run the command on the VM thread - this is for debugging only, // any real monitoring int rc = db->stat_print(db, flags); RETURN_INT(rc, outbuf); } else { // Invalid dbref RETURN_INT(ERROR_INVALID_DBREF, outbuf); } } case CMD_ENV_STAT_PRINT: { FAIL_IF_ASYNC_PENDING(d, outbuf); // Inbuf is << Flags:32 >> unsigned int flags = UNPACK_INT(inbuf, 0); // Outbuf is <<Rc:32>> int rc = bdberl_db_env()->stat_print(bdberl_db_env(), flags); RETURN_INT(rc, outbuf); } case CMD_LOCK_STAT: { FAIL_IF_ASYNC_PENDING(d, outbuf); // Mark the port as busy and then schedule the appropriate async operation d->async_op = cmd; d->async_flags = UNPACK_INT(inbuf, 0); bdberl_general_tpool_run(&do_async_lock_stat, d, 0, &d->async_job); // Let caller know that the operation is in progress // Outbuf is: <<0:32>> RETURN_INT(0, outbuf); } case CMD_LOCK_STAT_PRINT: { FAIL_IF_ASYNC_PENDING(d, outbuf); // Inbuf is << Flags:32 >> unsigned int flags = UNPACK_INT(inbuf, 0); // Outbuf is <<Rc:32>> // Run the command on the VM thread - this is for debugging only, // any real monitoring will use the async lock_stat int rc = bdberl_db_env()->lock_stat_print(bdberl_db_env(), flags); RETURN_INT(rc, outbuf); } case CMD_LOG_STAT: { FAIL_IF_ASYNC_PENDING(d, outbuf); // Inbuf is <<Flags:32 >> // Mark the port as busy and then schedule the appropriate async operation d->async_op = cmd; d->async_flags = UNPACK_INT(inbuf, 0); bdberl_general_tpool_run(&do_async_log_stat, d, 0, &d->async_job); // Let caller know that the operation is in progress // Outbuf is: <<0:32>> RETURN_INT(0, outbuf); } case CMD_LOG_STAT_PRINT: { FAIL_IF_ASYNC_PENDING(d, outbuf); // Inbuf is << Flags:32 >> unsigned int flags = UNPACK_INT(inbuf, 0); // Outbuf is <<Rc:32>> // Run the command on the VM thread - this is for debugging only, // any real monitoring will use the async lock_stat int rc = bdberl_db_env()->log_stat_print(bdberl_db_env(), flags); RETURN_INT(rc, outbuf); } case CMD_MEMP_STAT: { FAIL_IF_ASYNC_PENDING(d, outbuf); // Inbuf is <<Flags:32 >> // Mark the port as busy and then schedule the appropriate async operation d->async_op = cmd; d->async_flags = UNPACK_INT(inbuf, 0); bdberl_general_tpool_run(&do_async_memp_stat, d, 0, &d->async_job); // Let caller know that the operation is in progress // Outbuf is: <<0:32>> RETURN_INT(0, outbuf); } case CMD_MEMP_STAT_PRINT: { FAIL_IF_ASYNC_PENDING(d, outbuf); // Inbuf is << Flags:32 >> unsigned int flags = UNPACK_INT(inbuf, 0); // Outbuf is <<Rc:32>> // Run the command on the VM thread - this is for debugging only, // any real monitoring will use the async lock_stat int rc = bdberl_db_env()->memp_stat_print(bdberl_db_env(), flags); RETURN_INT(rc, outbuf); } case CMD_MUTEX_STAT: { FAIL_IF_ASYNC_PENDING(d, outbuf); // Inbuf is <<Flags:32 >> // Mark the port as busy and then schedule the appropriate async operation d->async_op = cmd; d->async_flags = UNPACK_INT(inbuf, 0); bdberl_general_tpool_run(&do_async_mutex_stat, d, 0, &d->async_job); // Let caller know that the operation is in progress // Outbuf is: <<0:32>> RETURN_INT(0, outbuf); } case CMD_MUTEX_STAT_PRINT: { FAIL_IF_ASYNC_PENDING(d, outbuf); // Inbuf is << Flags:32 >> unsigned int flags = UNPACK_INT(inbuf, 0); // Outbuf is <<Rc:32>> // Run the command on the VM thread - this is for debugging only, // any real monitoring will use the async lock_stat int rc = bdberl_db_env()->mutex_stat_print(bdberl_db_env(), flags); RETURN_INT(rc, outbuf); } case CMD_TXN_STAT: { FAIL_IF_ASYNC_PENDING(d, outbuf); // Inbuf is <<Flags:32 >> // Mark the port as busy and then schedule the appropriate async operation d->async_op = cmd; d->async_flags = UNPACK_INT(inbuf, 0); bdberl_general_tpool_run(&do_async_txn_stat, d, 0, &d->async_job); // Let caller know that the operation is in progress // Outbuf is: <<0:32>> RETURN_INT(0, outbuf); } case CMD_TXN_STAT_PRINT: { FAIL_IF_ASYNC_PENDING(d, outbuf); // Inbuf is << Flags:32 >> unsigned int flags = UNPACK_INT(inbuf, 0); // Outbuf is <<Rc:32>> // Run the command on the VM thread - this is for debugging only, // any real monitoring will use the async lock_stat int rc = bdberl_db_env()->txn_stat_print(bdberl_db_env(), flags); RETURN_INT(rc, outbuf); } default: abort(); } }