avoid using serial while mutex is locked

This commit is contained in:
shufps 2024-09-14 09:39:16 +02:00
parent 4df5d3615e
commit de10ecad99
No known key found for this signature in database
GPG Key ID: 371CB8C24D8CB455

View File

@ -150,6 +150,12 @@ void runASIC(void * task_id) {
uint32_t current_difficulty = 0; uint32_t current_difficulty = 0;
while (mMiner.inRun) { while (mMiner.inRun) {
// wait for the timer to start a new job
// also yields the CPU
pthread_mutex_lock(&job_interval_mutex);
pthread_cond_wait(&job_interval_cond, &job_interval_mutex);
pthread_mutex_unlock(&job_interval_mutex);
// Temperature check // Temperature check
unsigned long currentTime = millis(); unsigned long currentTime = millis();
if (currentTime - lastTempCheck > TEMP_CHECK_INTERVAL) { if (currentTime - lastTempCheck > TEMP_CHECK_INTERVAL) {
@ -172,12 +178,6 @@ void runASIC(void * task_id) {
lastTempCheck = currentTime; lastTempCheck = currentTime;
} }
// wait for the timer to start a new job
// also yields the CPU
pthread_mutex_lock(&job_interval_mutex);
pthread_cond_wait(&job_interval_cond, &job_interval_mutex);
pthread_mutex_unlock(&job_interval_mutex);
// increment extranonce2 // increment extranonce2
extranonce_2++; extranonce_2++;
@ -191,13 +191,15 @@ void runASIC(void * task_id) {
// make sure that another task doesn't mess with the data while // make sure that another task doesn't mess with the data while
// we are using it // we are using it
pthread_mutex_lock(&job_mutex); pthread_mutex_lock(&job_mutex);
if (current_difficulty != mMiner.poolDifficulty) { nerdnos_create_job(&mWorker, &mJob, &asic_jobs[asic_job_id], extranonce_2, mMiner.poolDifficulty);
current_difficulty = mMiner.poolDifficulty; pthread_mutex_unlock(&job_mutex);
// don't send difficulty while the job mutex is locked
if (current_difficulty != asic_jobs[asic_job_id].pool_diff) {
current_difficulty = asic_jobs[asic_job_id].pool_diff;
nerdnos_set_asic_difficulty(current_difficulty); nerdnos_set_asic_difficulty(current_difficulty);
Serial.printf("Set difficulty to %lu\n", current_difficulty); Serial.printf("Set difficulty to %lu\n", current_difficulty);
} }
nerdnos_create_job(&mWorker, &mJob, &asic_jobs[asic_job_id], extranonce_2, current_difficulty);
pthread_mutex_unlock(&job_mutex);
// send the job and // send the job and
nerdnos_send_work(&asic_jobs[asic_job_id], asic_job_id); nerdnos_send_work(&asic_jobs[asic_job_id], asic_job_id);