Merge pull request #77 from ballle98/dev/mutex_cond_init

ballle98/AqualinkD#31: mutex init and cond init called multiple times
pull/87/head
sfeakes 2019-08-09 09:31:23 -05:00 committed by GitHub
commit 9616d987f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 3 additions and 12 deletions

View File

@ -1233,7 +1233,6 @@ bool waitForEitherMessage(struct aqualinkdata *aq_data, char* message1, char* me
{
//logMessage(LOG_DEBUG, "waitForMessage %s %d %d\n",message,numMessageReceived,cmd);
int i=0;
pthread_mutex_init(&aq_data->active_thread.thread_mutex, NULL);
pthread_mutex_lock(&aq_data->active_thread.thread_mutex);
char* msgS1;
char* msgS2;
@ -1279,7 +1278,6 @@ bool waitForEitherMessage(struct aqualinkdata *aq_data, char* message1, char* me
}
//logMessage(LOG_DEBUG, "Programming mode: looking for '%s' received message1 '%s'\n",message1,aq_data->last_message);
pthread_cond_init(&aq_data->active_thread.thread_cond, NULL);
pthread_cond_wait(&aq_data->active_thread.thread_cond, &aq_data->active_thread.thread_mutex);
//logMessage(LOG_DEBUG, "Programming mode: loop %d of %d looking for '%s' received message1 '%s'\n",i,numMessageReceived,message1,aq_data->last_message);
}
@ -1302,7 +1300,6 @@ bool waitForMessage(struct aqualinkdata *aq_data, char* message, int numMessageR
{
logMessage(LOG_DEBUG, "waitForMessage %s %d\n",message,numMessageReceived);
int i=0;
pthread_mutex_init(&aq_data->active_thread.thread_mutex, NULL);
pthread_mutex_lock(&aq_data->active_thread.thread_mutex);
char* msgS;
char* ptr = NULL;
@ -1333,7 +1330,6 @@ bool waitForMessage(struct aqualinkdata *aq_data, char* message, int numMessageR
}
//logMessage(LOG_DEBUG, "Programming mode: looking for '%s' received message '%s'\n",message,aq_data->last_message);
pthread_cond_init(&aq_data->active_thread.thread_cond, NULL);
pthread_cond_wait(&aq_data->active_thread.thread_cond, &aq_data->active_thread.thread_mutex);
//logMessage(LOG_DEBUG, "Programming mode: loop %d of %d looking for '%s' received message '%s'\n",i,numMessageReceived,message,aq_data->last_message);
}
@ -1434,7 +1430,6 @@ bool waitForButtonState(struct aqualinkdata *aq_data, aqkey* button, aqledstate
{
//logMessage(LOG_DEBUG, "waitForMessage %s %d %d\n",message,numMessageReceived,cmd);
int i=0;
pthread_mutex_init(&aq_data->active_thread.thread_mutex, NULL);
pthread_mutex_lock(&aq_data->active_thread.thread_mutex);
while( ++i <= numMessageReceived)
@ -1447,7 +1442,6 @@ bool waitForButtonState(struct aqualinkdata *aq_data, aqkey* button, aqledstate
}
//logMessage(LOG_DEBUG, "Programming mode: looking for '%s' received message '%s'\n",message,aq_data->last_message);
pthread_cond_init(&aq_data->active_thread.thread_cond, NULL);
pthread_cond_wait(&aq_data->active_thread.thread_cond, &aq_data->active_thread.thread_mutex);
//logMessage(LOG_DEBUG, "Programming mode: loop %d of %d looking for '%s' received message '%s'\n",i,numMessageReceived,message,aq_data->last_message);
}

View File

@ -1024,6 +1024,9 @@ void main_loop()
_aqualink_data.battery = OK;
_aqualink_data.open_websockets = 0;
pthread_mutex_init(&_aqualink_data.active_thread.thread_mutex, NULL);
pthread_cond_init(&_aqualink_data.active_thread.thread_cond, NULL);
for (i=0; i < MAX_PUMPS; i++) {
_aqualink_data.pumps[i].rpm = TEMP_UNKNOWN;
_aqualink_data.pumps[i].gph = TEMP_UNKNOWN;

View File

@ -523,7 +523,6 @@ bool waitForPDAMessageHighlight(struct aqualinkdata *aq_data, int highlighIndex,
if(pda_m_hlightindex() == highlighIndex) return true;
int i=0;
pthread_mutex_init(&aq_data->active_thread.thread_mutex, NULL);
pthread_mutex_lock(&aq_data->active_thread.thread_mutex);
while( ++i <= numMessageReceived)
@ -532,7 +531,6 @@ bool waitForPDAMessageHighlight(struct aqualinkdata *aq_data, int highlighIndex,
if (aq_data->last_packet_type == CMD_PDA_HIGHLIGHT && pda_m_hlightindex() == highlighIndex) break;
pthread_cond_init(&aq_data->active_thread.thread_cond, NULL);
pthread_cond_wait(&aq_data->active_thread.thread_cond, &aq_data->active_thread.thread_mutex);
}
@ -554,7 +552,6 @@ bool waitForPDAMessageType(struct aqualinkdata *aq_data, unsigned char mtype, in
logMessage(LOG_DEBUG, "waitForPDAMessageType 0x%02hhx\n",mtype);
int i=0;
pthread_mutex_init(&aq_data->active_thread.thread_mutex, NULL);
pthread_mutex_lock(&aq_data->active_thread.thread_mutex);
while( ++i <= numMessageReceived)
@ -563,7 +560,6 @@ bool waitForPDAMessageType(struct aqualinkdata *aq_data, unsigned char mtype, in
if (aq_data->last_packet_type == mtype) break;
pthread_cond_init(&aq_data->active_thread.thread_cond, NULL);
pthread_cond_wait(&aq_data->active_thread.thread_cond, &aq_data->active_thread.thread_mutex);
}
@ -586,7 +582,6 @@ bool waitForPDAMessageTypesOrMenu(struct aqualinkdata *aq_data, unsigned char mt
int i=0;
bool gotmenu = false;
pthread_mutex_init(&aq_data->active_thread.thread_mutex, NULL);
pthread_mutex_lock(&aq_data->active_thread.thread_mutex);
while( ++i <= numMessageReceived)
@ -602,7 +597,6 @@ bool waitForPDAMessageTypesOrMenu(struct aqualinkdata *aq_data, unsigned char mt
if (aq_data->last_packet_type == mtype1 || aq_data->last_packet_type == mtype2) break;
pthread_cond_init(&aq_data->active_thread.thread_cond, NULL);
pthread_cond_wait(&aq_data->active_thread.thread_cond, &aq_data->active_thread.thread_mutex);
}