aboutsummarylogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntony Kellermann2018-08-22 10:22:38 -0400
committerAntony Kellermann2018-08-22 10:22:38 -0400
commitba1aad0d899415794aad7580356f89e1a4d7ef4c (patch)
tree9ea0c40082d1513e40be6103a33a0a24fb50de9f
parent2ff187cfb87bce351b044ed8c00e06e09ad73537 (diff)
downloadaur-ba1aad0d899415794aad7580356f89e1a4d7ef4c.tar.gz
Fixed api thread problem and removed macros
-rw-r--r--api.c39
-rw-r--r--api.h4
2 files changed, 28 insertions, 15 deletions
diff --git a/api.c b/api.c
index e904a58f8869..e213f35139d4 100644
--- a/api.c
+++ b/api.c
@@ -301,29 +301,45 @@ void api_info_array_store_data_batch(Info_Array* pInfo_Array, Data_Level data_le
// All IEX securities are accounted for
Info* pInfo;
pthread_t threads[pInfo_Array->length];
+ int open_threads[pInfo_Array->length];
+ memset(open_threads, 0, pInfo_Array->length * sizeof(int));
for (size_t i = 0; i < pInfo_Array->length; i++) {
pInfo = pInfo_Array->array[i];
if (pInfo->api_provider == EMPTY && strcmp(pInfo->symbol, "USD$") != 0) {
- if (strlen(pInfo->symbol) > 5) // Crypto
- pthread_create(&threads[i], NULL, coinmarketcap_store_info, pInfo);
- else pthread_create(&threads[i], NULL, alphavantage_store_info, pInfo); // AV
+ open_threads[i] = 1;
+ if (strlen(pInfo->symbol) > 5 && pthread_create(&threads[i], NULL,
+ coinmarketcap_store_info, pInfo)) { // Crypto
+ EXIT_MSG("Error creating thread!");
+ } else if (pthread_create(&threads[i], NULL, alphavantage_store_info, pInfo)) {
+ EXIT_MSG("Error creating thread!");
+ }
}
}
+ // All IEX and AV are accounted for
for (size_t i = 0; i < pInfo_Array->length; i++) {
pInfo = pInfo_Array->array[i];
- if (pInfo->api_provider != IEX && strcmp(pInfo->symbol, "USD$") != 0) {
- pthread_join(threads[i], NULL);
- if (strlen(pInfo->symbol) <= 5) // Crypto with 5 char or less name
- pthread_create(&threads[i], NULL, alphavantage_store_info, pInfo);
+ if (open_threads[i]) {
+ if (pthread_join(threads[i], NULL))
+ EXIT_MSG("Error joining thread!");
+
+ open_threads[i] = 0;
}
+
+ // Crypto with 5 char or less name
+ if (pInfo->api_provider == EMPTY && strcmp(pInfo->symbol, "USD$") != 0 &&
+ pthread_create(&threads[i], NULL, coinmarketcap_store_info, pInfo))
+ EXIT_MSG("Error creating thread!");
}
+
+ // All accounted for
for (size_t i = 0; i < pInfo_Array->length; i++) {
- pInfo = pInfo_Array->array[i];
- if (pInfo->api_provider != IEX && pInfo->api_provider != ALPHAVANTAGE &&
- strlen(pInfo->symbol) <= 5 && strcmp(pInfo->symbol, "USD$") != 0)
- pthread_join(threads[i], NULL); // Crypto with 5 char or less name
+ if (open_threads[i]) {
+ if (pthread_join(threads[i], NULL))
+ EXIT_MSG("Error joining thread!");
+ open_threads[i] = 0;
+ }
info_store_check_data(pInfo_Array->array[i]);
}
info_array_store_totals(pInfo_Array);
@@ -466,6 +482,7 @@ void info_store_quote_from_json(Info* pInfo, const Json* jquote) {
void info_store_chart_from_json(Info* pInfo, const Json* jchart) {
+ free(pInfo->points);
size_t len = json_object_array_length(jchart);
pInfo->points = calloc(len + 1, sizeof(double));
pointer_alloc_check(pInfo->points);
diff --git a/api.h b/api.h
index 4192c8b65319..125ca4cb3645 100644
--- a/api.h
+++ b/api.h
@@ -17,10 +17,6 @@ typedef enum data_level {
ALL, CHECK, MISC, NEWS
} Data_Level;
-#define DATA_ALL 0
-#define DATA_CHECK 1
-#define DATA_MISC 2
-
#define QUARTERS 4
#define DATE_MAX_LENGTH 32
#define CELL_MAX_LENGTH 16