Skip to content

Commit

Permalink
Merge pull request #13 from OttyLab/support-t-option
Browse files Browse the repository at this point in the history
Support t option
  • Loading branch information
OttyLab authored Mar 17, 2018
2 parents a69f08d + f213a75 commit f8353d7
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 15 deletions.
6 changes: 3 additions & 3 deletions app/src/main/cpp/libcpuminer/libcpuminer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1344,8 +1344,6 @@ int init(void(*cb)(const char *format, va_list arg)) {
#endif
if (num_processors < 1)
num_processors = 1;
if (!opt_n_threads)
opt_n_threads = num_processors;

#ifdef HAVE_SYSLOG_H
if (use_syslog)
Expand All @@ -1366,7 +1364,7 @@ int is_running() {
return 0;
}

int start(const char *url, const char *user, const char *pass) {
int start(const char *url, const char *user, const char *pass, const int n_threads) {
struct thr_info *thr;
long flags;
int i;
Expand All @@ -1380,6 +1378,8 @@ int start(const char *url, const char *user, const char *pass) {
rpc_pass = strdup(pass);
}

opt_n_threads = n_threads ? n_threads : num_processors;

pthread_mutex_lock(&run_lock);
if (is_running()) {
applog(LOG_INFO, "already running: thr_info[%d].pth=%lld", i, thr_info[i].pth);
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/cpp/libcpuminer/libcpuminer.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ extern "C"{

int init(void(*cb)(const char *format, va_list arg));
int is_running();
int start(const char* url, const char* user, const char* pass);
int start(const char* url, const char* user, const char* pass, const int n_threads=0);
int stop();

#ifdef __cplusplus
Expand Down
10 changes: 6 additions & 4 deletions app/src/main/cpp/native-lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,15 @@ Java_com_example_ottylab_bitzenyminer_MainActivity_startMining(
jobject /* this */,
jstring url,
jstring user,
jstring password) {
jstring password,
jint n_threads) {
Log("startMining");

const char *c_url = env->GetStringUTFChars(url, NULL);
const char *c_user = env->GetStringUTFChars(user, NULL);
const char *c_password = env->GetStringUTFChars(password, NULL);

int result = start(c_url, c_user, c_password);
int result = start(c_url, c_user, c_password, n_threads);

env->ReleaseStringUTFChars(url, c_url);
env->ReleaseStringUTFChars(user, c_user);
Expand All @@ -99,9 +100,10 @@ JNIEXPORT jint
JNICALL
Java_com_example_ottylab_bitzenyminer_MainActivity_startBenchmark(
JNIEnv *env,
jobject /* this */) {
jobject /* this */,
jint n_threads) {
Log("startBenchmark");
return start(NULL, NULL, NULL);
return start(NULL, NULL, NULL, n_threads);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class MainActivity extends AppCompatActivity {
private EditText editTextServer;
private EditText editTextUser;
private EditText editTextPassword;
private EditText editTextNThreads;
private Button buttonDrive;
private CheckBox checkBoxBenchmark;
private TextView textViewLog;
Expand Down Expand Up @@ -97,6 +98,14 @@ public void onFocusChange(View view, boolean b) {
}
});

editTextNThreads = (EditText) findViewById(R.id.editTextNThreads);
editTextNThreads.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean b) {
storeSetting();
}
});

buttonDrive = (Button) findViewById(R.id.buttonDrive);
buttonDrive.setOnClickListener(new View.OnClickListener() {
@Override
Expand All @@ -106,13 +115,19 @@ public void onClick(View view) {
stopMining();
} else {
Log.d("Java", "start");
int n_threads = 0;
try {
n_threads = Integer.parseInt(editTextNThreads.getText().toString());
} catch (NumberFormatException e){}

if (checkBoxBenchmark.isChecked()) {
startBenchmark();
startBenchmark(n_threads);
} else {
startMining(
editTextServer.getText().toString(),
editTextUser.getText().toString(),
editTextPassword.getText().toString());
editTextServer.getText().toString(),
editTextUser.getText().toString(),
editTextPassword.getText().toString(),
n_threads);
}
}

Expand Down Expand Up @@ -140,6 +155,7 @@ private void disableSetting(boolean running) {
editTextServer.setEnabled(!running);
editTextUser.setEnabled(!running);
editTextPassword.setEnabled(!running);
editTextNThreads.setEnabled(!running);
}

private void storeSetting() {
Expand All @@ -148,6 +164,7 @@ private void storeSetting() {
editor.putString("server", editTextServer.getText().toString());
editor.putString("user", editTextUser.getText().toString());
editor.putString("password", editTextPassword.getText().toString());
editor.putString("n_threads", editTextNThreads.getText().toString());
editor.commit();
}

Expand All @@ -156,14 +173,15 @@ private void restoreSetting() {
editTextServer.setText(pref.getString("server", null));
editTextUser.setText(pref.getString("user", null));
editTextPassword.setText(pref.getString("password", null));
editTextNThreads.setText(pref.getString("n_threads", null));
}

/**
* A native method that is implemented by the 'native-lib' native library,
* which is packaged with this application.
*/
public native boolean isMiningRunning();
public native int startMining(String url, String user, String password);
public native int startBenchmark();
public native int startMining(String url, String user, String password, int n_threads);
public native int startBenchmark(int n_threads);
public native int stopMining();
}
16 changes: 15 additions & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editTextUser" />

<EditText
android:id="@+id/editTextNThreads"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:ems="10"
android:hint="number of threads (auto: 0 or empty)"
android:inputType="number"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editTextPassword" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="100dp"
Expand All @@ -71,7 +85,7 @@
android:layout_marginStart="20dp"
android:layout_marginTop="24dp"
android:text="Benchmark"
app:layout_constraintLeft_toRightOf="@+id/buttonDrive"
app:layout_constraintLeft_toRightOf="@+id/editTextNThreads"
app:layout_constraintTop_toBottomOf="@+id/editTextPassword" />
</LinearLayout>

Expand Down

0 comments on commit f8353d7

Please sign in to comment.