diff --git a/src/highlevel/bidib_highlevel_admin.c b/src/highlevel/bidib_highlevel_admin.c index c93fd3b..a35865c 100644 --- a/src/highlevel/bidib_highlevel_admin.c +++ b/src/highlevel/bidib_highlevel_admin.c @@ -42,7 +42,7 @@ int bidib_ping(const char *board, uint8_t ping_byte) { return 1; } // For bidib_state_get_board_ref - pthread_rwlock_rdlock(&bidib_state_boards_rwlock); + pthread_rwlock_rdlock(&bidib_boards_rwlock); const t_bidib_board *const tmp_board = bidib_state_get_board_ref(board); if (tmp_board != NULL && tmp_board->connected) { unsigned int action_id = bidib_get_and_incr_action_id(); @@ -52,11 +52,11 @@ int bidib_ping(const char *board, uint8_t ping_byte) { tmp_board->node_addr.top, tmp_board->node_addr.sub, tmp_board->node_addr.subsub, action_id); t_bidib_node_address tmp_addr = tmp_board->node_addr; - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); bidib_send_sys_ping(tmp_addr, ping_byte, action_id); return 0; } - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); return 1; } @@ -66,7 +66,7 @@ int bidib_identify(const char *board, uint8_t state) { return 1; } // For bidib_state_get_board_ref - pthread_rwlock_rdlock(&bidib_state_boards_rwlock); + pthread_rwlock_rdlock(&bidib_boards_rwlock); const t_bidib_board *const tmp_board = bidib_state_get_board_ref(board); if (tmp_board != NULL && tmp_board->connected) { unsigned int action_id = bidib_get_and_incr_action_id(); @@ -76,11 +76,11 @@ int bidib_identify(const char *board, uint8_t state) { tmp_board->node_addr.top, tmp_board->node_addr.sub, tmp_board->node_addr.subsub, action_id); t_bidib_node_address tmp_addr = tmp_board->node_addr; - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); bidib_send_sys_identify(tmp_addr, state, action_id); return 0; } - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); return 1; } @@ -90,7 +90,7 @@ int bidib_get_protocol_version(const char *board) { return 1; } // For bidib_state_get_board_ref - pthread_rwlock_rdlock(&bidib_state_boards_rwlock); + pthread_rwlock_rdlock(&bidib_boards_rwlock); const t_bidib_board *const tmp_board = bidib_state_get_board_ref(board); if (tmp_board != NULL && tmp_board->connected) { unsigned int action_id = bidib_get_and_incr_action_id(); @@ -100,11 +100,11 @@ int bidib_get_protocol_version(const char *board) { tmp_board->node_addr.top, tmp_board->node_addr.sub, tmp_board->node_addr.subsub, action_id); t_bidib_node_address tmp_addr = tmp_board->node_addr; - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); bidib_send_sys_get_p_version(tmp_addr, action_id); return 0; } - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); return 1; } @@ -114,7 +114,7 @@ int bidib_get_software_version(const char *board) { return 1; } // For bidib_state_get_board_ref - pthread_rwlock_rdlock(&bidib_state_boards_rwlock); + pthread_rwlock_rdlock(&bidib_boards_rwlock); const t_bidib_board *const tmp_board = bidib_state_get_board_ref(board); if (tmp_board != NULL && tmp_board->connected) { unsigned int action_id = bidib_get_and_incr_action_id(); @@ -124,10 +124,10 @@ int bidib_get_software_version(const char *board) { tmp_board->node_addr.top, tmp_board->node_addr.sub, tmp_board->node_addr.subsub, action_id); t_bidib_node_address tmp_addr = tmp_board->node_addr; - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); bidib_send_sys_get_sw_version(tmp_addr, action_id); return 0; } - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); return 1; } diff --git a/src/highlevel/bidib_highlevel_getter.c b/src/highlevel/bidib_highlevel_getter.c index a1823bb..2e7404f 100644 --- a/src/highlevel/bidib_highlevel_getter.c +++ b/src/highlevel/bidib_highlevel_getter.c @@ -248,7 +248,7 @@ t_bidib_track_state bidib_get_state(void) { t_bidib_id_list_query bidib_get_boards(void) { t_bidib_id_list_query query = {0, NULL}; - pthread_rwlock_rdlock(&bidib_state_boards_rwlock); + pthread_rwlock_rdlock(&bidib_boards_rwlock); if (bidib_boards->len > 0) { query.length = bidib_boards->len; query.ids = malloc(sizeof(char *) * query.length); @@ -257,14 +257,14 @@ t_bidib_id_list_query bidib_get_boards(void) { query.ids[i] = strdup(board_i->id->str); } } - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); return query; } t_bidib_id_list_query bidib_get_boards_connected(void) { t_bidib_id_list_query query = {0, NULL}; size_t count = 0; - pthread_rwlock_rdlock(&bidib_state_boards_rwlock); + pthread_rwlock_rdlock(&bidib_boards_rwlock); for (size_t i = 0; i < bidib_boards->len; i++) { const t_bidib_board *const count_tmp = &g_array_index(bidib_boards, t_bidib_board, i); if (count_tmp != NULL && count_tmp->connected) { @@ -283,7 +283,7 @@ t_bidib_id_list_query bidib_get_boards_connected(void) { } } } - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); return query; } @@ -293,12 +293,12 @@ bool bidib_get_board_connected(const char *board) { } bool res = false; // For bidib_state_get_board_ref - pthread_rwlock_rdlock(&bidib_state_boards_rwlock); + pthread_rwlock_rdlock(&bidib_boards_rwlock); const t_bidib_board *const tmp = bidib_state_get_board_ref(board); if (tmp != NULL) { res = tmp->connected; } - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); return res; } @@ -308,20 +308,20 @@ t_bidib_board_features_query bidib_get_board_features(const char *board) { return query; } // For bidib_state_get_board_ref - pthread_rwlock_rdlock(&bidib_state_boards_rwlock); + pthread_rwlock_rdlock(&bidib_boards_rwlock); const t_bidib_board *const tmp = bidib_state_get_board_ref(board); if (tmp != NULL && tmp->features->len != 0) { query.length = tmp->features->len; query.features = malloc(sizeof(char) * query.length * 2); memcpy(query.features, tmp->features->data, sizeof(t_bidib_board_feature) * query.length); } - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); return query; } t_bidib_id_query bidib_get_board_id(t_bidib_unique_id_mod unique_id) { t_bidib_id_query query = {false, NULL}; - pthread_rwlock_rdlock(&bidib_state_boards_rwlock); + pthread_rwlock_rdlock(&bidib_boards_rwlock); for (size_t i = 0; i < bidib_boards->len; i++) { const t_bidib_board *const board_i = &g_array_index(bidib_boards, t_bidib_board, i); if (board_i != NULL && bidib_state_uids_equal(&unique_id, &board_i->unique_id)) { @@ -330,7 +330,7 @@ t_bidib_id_query bidib_get_board_id(t_bidib_unique_id_mod unique_id) { break; } } - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); return query; } @@ -341,13 +341,13 @@ t_bidib_unique_id_query bidib_get_uniqueid(const char *board) { return query; } // For bidib_state_get_board_ref - pthread_rwlock_rdlock(&bidib_state_boards_rwlock); + pthread_rwlock_rdlock(&bidib_boards_rwlock); const t_bidib_board *const board_ref = bidib_state_get_board_ref(board); if (board_ref != NULL && board_ref->unique_id.class_id != 0xFF) { query.known = true; query.unique_id = board_ref->unique_id; } - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); return query; } @@ -355,13 +355,13 @@ t_bidib_unique_id_query bidib_get_uniqueid_by_nodeaddr(t_bidib_node_address node t_bidib_unique_id_query query; query.known = false; // For bidib_state_get_board_ref_by_nodeaddr - pthread_rwlock_rdlock(&bidib_state_boards_rwlock); + pthread_rwlock_rdlock(&bidib_boards_rwlock); const t_bidib_board *const board_ref = bidib_state_get_board_ref_by_nodeaddr(node_address); if (board_ref != NULL && board_ref->connected) { query.known = true; query.unique_id = board_ref->unique_id; } - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); return query; } @@ -372,20 +372,20 @@ t_bidib_node_address_query bidib_get_nodeaddr(const char *board) { return query; } // For bidib_state_get_board_ref - pthread_rwlock_rdlock(&bidib_state_boards_rwlock); + pthread_rwlock_rdlock(&bidib_boards_rwlock); const t_bidib_board *const board_ref = bidib_state_get_board_ref(board); if (board_ref != NULL && board_ref->connected) { query.known_and_connected = true; query.address = board_ref->node_addr; } - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); return query; } t_bidib_node_address_query bidib_get_nodeaddr_by_uniqueid(t_bidib_unique_id_mod uid) { t_bidib_node_address_query query; query.known_and_connected = false; - pthread_rwlock_rdlock(&bidib_state_boards_rwlock); + pthread_rwlock_rdlock(&bidib_boards_rwlock); for (size_t i = 0; i < bidib_boards->len; i++) { const t_bidib_board *const board_i = &g_array_index(bidib_boards, t_bidib_board, i); if (board_i != NULL && bidib_state_uids_equal(&uid, &board_i->unique_id)) { @@ -394,7 +394,7 @@ t_bidib_node_address_query bidib_get_nodeaddr_by_uniqueid(t_bidib_unique_id_mod break; } } - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); return query; } @@ -404,7 +404,7 @@ t_bidib_id_list_query bidib_get_board_points(const char *board) { return query; } // For bidib_state_get_board_ref - pthread_rwlock_rdlock(&bidib_state_boards_rwlock); + pthread_rwlock_rdlock(&bidib_boards_rwlock); const t_bidib_board *const board_ref = bidib_state_get_board_ref(board); if (board_ref != NULL && (board_ref->points_board->len > 0 || board_ref->points_dcc->len > 0)) { @@ -426,7 +426,7 @@ t_bidib_id_list_query bidib_get_board_points(const char *board) { current_index++; } } - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); return query; } @@ -436,7 +436,7 @@ t_bidib_id_list_query bidib_get_board_signals(const char *board) { return query; } // For bidib_state_get_board_ref - pthread_rwlock_rdlock(&bidib_state_boards_rwlock); + pthread_rwlock_rdlock(&bidib_boards_rwlock); const t_bidib_board *const board_ref = bidib_state_get_board_ref(board); if (board_ref != NULL && (board_ref->signals_board->len > 0 || board_ref->signals_dcc->len > 0)) { @@ -458,7 +458,7 @@ t_bidib_id_list_query bidib_get_board_signals(const char *board) { current_index++; } } - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); return query; } @@ -468,7 +468,7 @@ t_bidib_id_list_query bidib_get_board_peripherals(const char *board) { return query; } // For bidib_state_get_board_ref - pthread_rwlock_rdlock(&bidib_state_boards_rwlock); + pthread_rwlock_rdlock(&bidib_boards_rwlock); const t_bidib_board *const board_ref = bidib_state_get_board_ref(board); if (board_ref != NULL && (board_ref->peripherals->len > 0)) { query.length = board_ref->peripherals->len; @@ -480,7 +480,7 @@ t_bidib_id_list_query bidib_get_board_peripherals(const char *board) { query.ids[i] = strdup(peripheral_mapping->id->str); } } - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); return query; } @@ -490,7 +490,7 @@ t_bidib_id_list_query bidib_get_board_segments(const char *board) { return query; } // For bidib_state_get_board_ref - pthread_rwlock_rdlock(&bidib_state_boards_rwlock); + pthread_rwlock_rdlock(&bidib_boards_rwlock); const t_bidib_board *const board_ref = bidib_state_get_board_ref(board); if (board_ref != NULL && (board_ref->segments->len > 0)) { query.length = board_ref->segments->len; @@ -502,7 +502,7 @@ t_bidib_id_list_query bidib_get_board_segments(const char *board) { query.ids[i] = strdup(segment_mapping->id->str); } } - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); return query; } @@ -512,7 +512,7 @@ t_bidib_id_list_query bidib_get_board_reversers(const char *board) { return query; } // For bidib_state_get_board_ref - pthread_rwlock_rdlock(&bidib_state_boards_rwlock); + pthread_rwlock_rdlock(&bidib_boards_rwlock); const t_bidib_board *const board_ref = bidib_state_get_board_ref(board); if (board_ref != NULL && (board_ref->reversers->len > 0)) { query.length = board_ref->reversers->len; @@ -524,14 +524,14 @@ t_bidib_id_list_query bidib_get_board_reversers(const char *board) { query.ids[i] = strdup(reverser_mapping->id->str); } } - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); return query; } t_bidib_id_list_query bidib_get_connected_points(void) { t_bidib_id_list_query query = {0, NULL}; size_t count = 0; - pthread_rwlock_rdlock(&bidib_state_boards_rwlock); + pthread_rwlock_rdlock(&bidib_boards_rwlock); for (size_t i = 0; i < bidib_boards->len; i++) { const t_bidib_board *const board_ref = &g_array_index(bidib_boards, t_bidib_board, i); if (board_ref != NULL && board_ref->connected) { @@ -561,14 +561,14 @@ t_bidib_id_list_query bidib_get_connected_points(void) { } } } - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); return query; } t_bidib_id_list_query bidib_get_connected_signals(void) { t_bidib_id_list_query query = {0, NULL}; size_t count = 0; - pthread_rwlock_rdlock(&bidib_state_boards_rwlock); + pthread_rwlock_rdlock(&bidib_boards_rwlock); for (size_t i = 0; i < bidib_boards->len; i++) { const t_bidib_board *const board_ref = &g_array_index(bidib_boards, t_bidib_board, i); if (board_ref != NULL && board_ref->connected) { @@ -598,14 +598,14 @@ t_bidib_id_list_query bidib_get_connected_signals(void) { } } } - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); return query; } t_bidib_id_list_query bidib_get_connected_peripherals(void) { t_bidib_id_list_query query = {0, NULL}; size_t count = 0; - pthread_rwlock_rdlock(&bidib_state_boards_rwlock); + pthread_rwlock_rdlock(&bidib_boards_rwlock); for (size_t i = 0; i < bidib_boards->len; i++) { const t_bidib_board *const board_ref = &g_array_index(bidib_boards, t_bidib_board, i); if (board_ref != NULL && board_ref->connected) { @@ -628,14 +628,14 @@ t_bidib_id_list_query bidib_get_connected_peripherals(void) { } } } - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); return query; } t_bidib_id_list_query bidib_get_connected_segments(void) { t_bidib_id_list_query query = {0, NULL}; size_t count = 0; - pthread_rwlock_rdlock(&bidib_state_boards_rwlock); + pthread_rwlock_rdlock(&bidib_boards_rwlock); for (size_t i = 0; i < bidib_boards->len; i++) { const t_bidib_board *const board_ref = &g_array_index(bidib_boards, t_bidib_board, i); if (board_ref != NULL && board_ref->connected) { @@ -658,14 +658,14 @@ t_bidib_id_list_query bidib_get_connected_segments(void) { } } } - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); return query; } t_bidib_id_list_query bidib_get_connected_reversers(void) { t_bidib_id_list_query query = {0, NULL}; size_t count = 0; - pthread_rwlock_rdlock(&bidib_state_boards_rwlock); + pthread_rwlock_rdlock(&bidib_boards_rwlock); for (size_t i = 0; i < bidib_boards->len; i++) { const t_bidib_board *const board_ref = &g_array_index(bidib_boards, t_bidib_board, i); if (board_ref != NULL && board_ref->connected) { @@ -688,14 +688,14 @@ t_bidib_id_list_query bidib_get_connected_reversers(void) { } } } - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); return query; } t_bidib_id_list_query bidib_get_connected_boosters(void) { t_bidib_id_list_query query = {0, NULL}; size_t count = 0; - pthread_rwlock_rdlock(&bidib_state_boards_rwlock); + pthread_rwlock_rdlock(&bidib_boards_rwlock); for (size_t i = 0; i < bidib_boards->len; i++) { const t_bidib_board *const board_ref = &g_array_index(bidib_boards, t_bidib_board, i); if (board_ref->connected && board_ref->unique_id.class_id & (1 << 1)) { @@ -714,7 +714,7 @@ t_bidib_id_list_query bidib_get_connected_boosters(void) { } } } - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); return query; } @@ -738,7 +738,7 @@ t_bidib_id_list_query bidib_get_boosters(void) { t_bidib_id_list_query bidib_get_connected_track_outputs(void) { t_bidib_id_list_query query = {0, NULL}; size_t count = 0; - pthread_rwlock_rdlock(&bidib_state_boards_rwlock); + pthread_rwlock_rdlock(&bidib_boards_rwlock); for (size_t i = 0; i < bidib_boards->len; i++) { const t_bidib_board *const board_ref = &g_array_index(bidib_boards, t_bidib_board, i); if (board_ref != NULL && board_ref->connected && board_ref->unique_id.class_id & (1 << 4)) { @@ -758,7 +758,7 @@ t_bidib_id_list_query bidib_get_connected_track_outputs(void) { } } } - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); return query; } @@ -1043,7 +1043,7 @@ t_bidib_track_output_state_query bidib_get_track_output_state(const char *track_ t_bidib_id_list_query bidib_get_trains(void) { t_bidib_id_list_query query = {0, NULL}; // For accessing bidib_trains - pthread_rwlock_rdlock(&bidib_state_trains_rwlock); + pthread_rwlock_rdlock(&bidib_trains_rwlock); if (bidib_trains->len > 0) { query.length = bidib_trains->len; query.ids = malloc(sizeof(char *) * query.length); @@ -1052,7 +1052,7 @@ t_bidib_id_list_query bidib_get_trains(void) { query.ids[i] = strdup(train_i->id->str); } } - pthread_rwlock_unlock(&bidib_state_trains_rwlock); + pthread_rwlock_unlock(&bidib_trains_rwlock); return query; } @@ -1089,7 +1089,7 @@ t_bidib_id_list_query bidib_get_trains_on_track(void) { t_bidib_id_query bidib_get_train_id(t_bidib_dcc_address dcc_address) { t_bidib_id_query query = {false, NULL}; // For accessing bidib_trains - pthread_rwlock_rdlock(&bidib_state_trains_rwlock); + pthread_rwlock_rdlock(&bidib_trains_rwlock); for (size_t i = 0; i < bidib_trains->len; i++) { const t_bidib_train *const train_i = &g_array_index(bidib_trains, t_bidib_train, i); if (train_i->dcc_addr.addrl == dcc_address.addrl && @@ -1099,7 +1099,7 @@ t_bidib_id_query bidib_get_train_id(t_bidib_dcc_address dcc_address) { break; } } - pthread_rwlock_unlock(&bidib_state_trains_rwlock); + pthread_rwlock_unlock(&bidib_trains_rwlock); return query; } @@ -1110,7 +1110,7 @@ t_bidib_dcc_address_query bidib_get_train_dcc_addr(const char *train) { return query; } // For bidib_state_get_train_ref - pthread_rwlock_rdlock(&bidib_state_trains_rwlock); + pthread_rwlock_rdlock(&bidib_trains_rwlock); const t_bidib_train *const tmp = bidib_state_get_train_ref(train); if (tmp != NULL) { query.known = true; @@ -1118,7 +1118,7 @@ t_bidib_dcc_address_query bidib_get_train_dcc_addr(const char *train) { query.dcc_address.addrl = tmp->dcc_addr.addrl; query.dcc_address.type = tmp->dcc_addr.type; } - pthread_rwlock_unlock(&bidib_state_trains_rwlock); + pthread_rwlock_unlock(&bidib_trains_rwlock); return query; } @@ -1128,7 +1128,7 @@ t_bidib_id_list_query bidib_get_train_peripherals(const char *train) { return query; } // For bidib_state_get_train_ref - pthread_rwlock_rdlock(&bidib_state_trains_rwlock); + pthread_rwlock_rdlock(&bidib_trains_rwlock); const t_bidib_train *const tmp = bidib_state_get_train_ref(train); if (tmp != NULL) { query.length = tmp->peripherals->len; @@ -1139,7 +1139,7 @@ t_bidib_id_list_query bidib_get_train_peripherals(const char *train) { query.ids[i] = strdup(mapping_i->id->str); } } - pthread_rwlock_unlock(&bidib_state_trains_rwlock); + pthread_rwlock_unlock(&bidib_trains_rwlock); return query; } @@ -1226,7 +1226,7 @@ t_bidib_train_position_query bidib_get_train_position_intern(const char *train) // Notes regarding mutexes/locks: // - bidib_state_get_train_state_ref: trackstate_trains_mutex // - access bidib_track_state.segments: trackstate_segments_mutex - // - bidib_state_get_train_ref: bidib_state_trains_rwlock >= read + // - bidib_state_get_train_ref: bidib_trains_rwlock >= read const t_bidib_train_state_intern *const train_state_ref = bidib_state_get_train_state_ref(train); const t_bidib_train *const train_ref = bidib_state_get_train_ref(train); @@ -1269,7 +1269,7 @@ t_bidib_train_position_query bidib_get_train_position_intern(const char *train) t_bidib_train_position_query bidib_get_train_position(const char *train) { // All for bidib_get_train_position_intern - pthread_rwlock_rdlock(&bidib_state_trains_rwlock); + pthread_rwlock_rdlock(&bidib_trains_rwlock); pthread_mutex_lock(&trackstate_segments_mutex); pthread_mutex_lock(&trackstate_trains_mutex); @@ -1277,7 +1277,7 @@ t_bidib_train_position_query bidib_get_train_position(const char *train) { pthread_mutex_unlock(&trackstate_trains_mutex); pthread_mutex_unlock(&trackstate_segments_mutex); - pthread_rwlock_unlock(&bidib_state_trains_rwlock); + pthread_rwlock_unlock(&bidib_trains_rwlock); return query; } @@ -1321,14 +1321,14 @@ static t_bidib_id_list_query bidib_get_accessory_aspects(const char *accessory, return query; } // For bidib_state_get_board_accessory_mapping_ref, bidib_state_get_dcc_accessory_mapping_ref - pthread_rwlock_rdlock(&bidib_state_boards_rwlock); + pthread_rwlock_rdlock(&bidib_boards_rwlock); const t_bidib_board_accessory_mapping *const board_mapping = bidib_state_get_board_accessory_mapping_ref(accessory, point); if (board_mapping == NULL) { const t_bidib_dcc_accessory_mapping *const dcc_mapping = bidib_state_get_dcc_accessory_mapping_ref(accessory, point); if (dcc_mapping == NULL) { - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); return query; } else { query.length = dcc_mapping->aspects->len; @@ -1348,7 +1348,7 @@ static t_bidib_id_list_query bidib_get_accessory_aspects(const char *accessory, query.ids[i] = strdup(aspect_mapping->id->str); } } - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); return query; } @@ -1366,7 +1366,7 @@ t_bidib_id_list_query bidib_get_peripheral_aspects(const char *peripheral) { return query; } // For bidib_state_get_peripheral_mapping_ref - pthread_rwlock_rdlock(&bidib_state_boards_rwlock); + pthread_rwlock_rdlock(&bidib_boards_rwlock); const t_bidib_peripheral_mapping *const peripheral_mapping = bidib_state_get_peripheral_mapping_ref(peripheral); if (peripheral_mapping != NULL) { @@ -1378,7 +1378,7 @@ t_bidib_id_list_query bidib_get_peripheral_aspects(const char *peripheral) { query.ids[i] = strdup(aspect_mapping->id->str); } } - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); return query; } diff --git a/src/highlevel/bidib_highlevel_intern.h b/src/highlevel/bidib_highlevel_intern.h index 6893231..65c4ccc 100644 --- a/src/highlevel/bidib_highlevel_intern.h +++ b/src/highlevel/bidib_highlevel_intern.h @@ -35,8 +35,8 @@ #include "../../include/definitions/bidib_definitions_custom.h" -extern pthread_rwlock_t bidib_state_trains_rwlock; -extern pthread_rwlock_t bidib_state_boards_rwlock; +extern pthread_rwlock_t bidib_trains_rwlock; +extern pthread_rwlock_t bidib_boards_rwlock; extern pthread_mutex_t bidib_action_id_mutex; extern pthread_mutex_t trackstate_accessories_mutex; @@ -58,7 +58,7 @@ unsigned int bidib_get_and_incr_action_id(void); * Used only internally in bidib_state_update_train_available and * bidib_get_train_position to avoid the usage of a recursive mutex. * - * Shall only be called with with bidib_state_trains_rwlock >= read acquired, + * Shall only be called with with bidib_trains_rwlock >= read acquired, * and with trackstate_segments_mutex and trackstate_trains_mutex acquired. * * @param train the id of the train. diff --git a/src/highlevel/bidib_highlevel_setter.c b/src/highlevel/bidib_highlevel_setter.c index e48bc56..d08d472 100644 --- a/src/highlevel/bidib_highlevel_setter.c +++ b/src/highlevel/bidib_highlevel_setter.c @@ -75,7 +75,7 @@ int bidib_switch_point(const char *point, const char *aspect) { pthread_mutex_lock(&trackstate_accessories_mutex); // For accessing bidib_boards and bidib_send_cs_accessory_intern - pthread_rwlock_rdlock(&bidib_state_boards_rwlock); + pthread_rwlock_rdlock(&bidib_boards_rwlock); for (size_t i = 0; i < bidib_boards->len; i++) { @@ -89,7 +89,7 @@ int bidib_switch_point(const char *point, const char *aspect) { if (!board_i->connected) { syslog_libbidib(LOG_ERR, "Switch point %s: board %s is not connected", point, board_i->id->str); - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); pthread_mutex_unlock(&trackstate_accessories_mutex); return 1; } @@ -112,7 +112,7 @@ int bidib_switch_point(const char *point, const char *aspect) { point, aspect); ret = 1; } - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); pthread_mutex_unlock(&trackstate_accessories_mutex); return ret; } @@ -126,7 +126,7 @@ int bidib_switch_point(const char *point, const char *aspect) { if (!board_i->connected) { syslog_libbidib(LOG_ERR, "Switch point %s: board %s is not connected", point, board_i->id->str); - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); pthread_mutex_unlock(&trackstate_accessories_mutex); return 1; } @@ -171,11 +171,11 @@ int bidib_switch_point(const char *point, const char *aspect) { tmp_addr.subsub, aspect, action_id); ret = 1; } - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); pthread_mutex_unlock(&trackstate_accessories_mutex); return ret; } else { - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); pthread_mutex_unlock(&trackstate_accessories_mutex); syslog_libbidib(LOG_ERR, "Switch point %s: aspect %s doesn't exist", point, aspect); @@ -184,7 +184,7 @@ int bidib_switch_point(const char *point, const char *aspect) { } } } - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); pthread_mutex_unlock(&trackstate_accessories_mutex); syslog_libbidib(LOG_ERR, "Switch point %s: not found", point); return 1; @@ -200,7 +200,7 @@ int bidib_set_signal(const char *signal, const char *aspect) { pthread_mutex_lock(&trackstate_accessories_mutex); // For accessing bidib_boards and bidib_send_cs_accessory_intern - pthread_rwlock_rdlock(&bidib_state_boards_rwlock); + pthread_rwlock_rdlock(&bidib_boards_rwlock); for (size_t i = 0; i < bidib_boards->len; i++) { const t_bidib_board *const board_i = &g_array_index(bidib_boards, t_bidib_board, i); @@ -211,7 +211,7 @@ int bidib_set_signal(const char *signal, const char *aspect) { if (!board_i->connected) { syslog_libbidib(LOG_ERR, "Set signal %s: board %s is not connected", signal, board_i->id->str); - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); pthread_mutex_unlock(&trackstate_accessories_mutex); return 1; } @@ -233,7 +233,7 @@ int bidib_set_signal(const char *signal, const char *aspect) { signal, aspect); ret = 1; } - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); pthread_mutex_unlock(&trackstate_accessories_mutex); return ret; } @@ -246,7 +246,7 @@ int bidib_set_signal(const char *signal, const char *aspect) { if (!board_i->connected) { syslog_libbidib(LOG_ERR, "Set signal %s: board %s is not connected", signal, board_i->id->str); - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); pthread_mutex_unlock(&trackstate_accessories_mutex); return 1; } @@ -293,13 +293,13 @@ int bidib_set_signal(const char *signal, const char *aspect) { signal, aspect); ret = 1; } - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); pthread_mutex_unlock(&trackstate_accessories_mutex); return ret; } } } - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); pthread_mutex_unlock(&trackstate_accessories_mutex); syslog_libbidib(LOG_ERR, "Set signal %s: not found", signal); return 1; @@ -311,7 +311,7 @@ int bidib_set_peripheral(const char *peripheral, const char *aspect) { return 1; } // For accessing bidib_boards - pthread_rwlock_rdlock(&bidib_state_boards_rwlock); + pthread_rwlock_rdlock(&bidib_boards_rwlock); for (size_t i = 0; i < bidib_boards->len; i++) { const t_bidib_board *const board_i = &g_array_index(bidib_boards, t_bidib_board, i); for (size_t j = 0; j < board_i->peripherals->len; j++) { @@ -321,7 +321,7 @@ int bidib_set_peripheral(const char *peripheral, const char *aspect) { if (!board_i->connected) { syslog_libbidib(LOG_ERR, "Set peripheral %s: board %s is not connected", peripheral, board_i->id->str); - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); return 1; } const t_bidib_aspect *const aspect_mapping = @@ -335,10 +335,10 @@ int bidib_set_peripheral(const char *peripheral, const char *aspect) { aspect_mapping->id->str, aspect_mapping->value, action_id); bidib_send_lc_output(board_i->node_addr, peripheral_mapping->port.port0, peripheral_mapping->port.port1, aspect_mapping->value, action_id); - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); return 0; } else { - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); syslog_libbidib(LOG_ERR, "Set peripheral %s: aspect %s doesn't exist", peripheral, aspect); return 1; @@ -346,14 +346,14 @@ int bidib_set_peripheral(const char *peripheral, const char *aspect) { } } } - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); syslog_libbidib(LOG_ERR, "Set peripheral %s: not found", peripheral); return 1; } /** * Set the train speed on track output to some value. - * Shall only be called with bidib_state_trains_rwlock >=read acquired. + * Shall only be called with bidib_trains_rwlock >=read acquired. * * @param train the id/name of the train whose speed to set * @param speed the speed to set @@ -372,32 +372,32 @@ int bidib_set_train_speed_internal(const char *train, int speed, const char *tra return 1; } // Notes regarding mutexes/locks: - // - bidib_state_get_train_ref: bidib_state_trains_rwlock >=read -> by caller - // - bidib_state_get_board_ref: bidib_state_boards_rwlock >=read -> locked locally + // - bidib_state_get_train_ref: bidib_trains_rwlock >=read -> by caller + // - bidib_state_get_board_ref: bidib_boards_rwlock >=read -> locked locally // - bidib_state_get_train_state_ref: trackstate_trains_mutex -> locked locally - // - bidib_send_cs_drive_intern: we pass false -> need lock bidib_state_trains_rwlock -> caller - // Important: trackstate_trains_mutex and bidib_state_boards_rwlock have to be released + // - bidib_send_cs_drive_intern: we pass false -> need lock bidib_trains_rwlock -> caller + // Important: trackstate_trains_mutex and bidib_boards_rwlock have to be released // before bidib_send_cs_drive_intern is called. const t_bidib_train *const tmp_train = bidib_state_get_train_ref(train); // For bidib_state_get_train_state_ref pthread_mutex_lock(&trackstate_trains_mutex); // For bidib_state_get_board_ref - pthread_rwlock_rdlock(&bidib_state_boards_rwlock); + pthread_rwlock_rdlock(&bidib_boards_rwlock); const t_bidib_board *const board = bidib_state_get_board_ref(track_output); if (tmp_train == NULL) { - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); pthread_mutex_unlock(&trackstate_trains_mutex); syslog_libbidib(LOG_ERR, "Set train speed: train %s doesn't exist", train); return 1; } else if (board == NULL || !board->connected) { - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); pthread_mutex_unlock(&trackstate_trains_mutex); syslog_libbidib(LOG_ERR, "Set train speed: board %s doesn't exist or is not connected", track_output); return 1; } else if (!(board->unique_id.class_id & (1 << 4))) { - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); pthread_mutex_unlock(&trackstate_trains_mutex); syslog_libbidib(LOG_ERR, "Set train speed: board %s has no track output", track_output); @@ -437,7 +437,7 @@ int bidib_set_train_speed_internal(const char *train, int speed, const char *tra train, speed, board->id->str, board->node_addr.top, board->node_addr.sub, board->node_addr.subsub, action_id); t_bidib_node_address tmp_addr = board->node_addr; - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); pthread_mutex_unlock(&trackstate_trains_mutex); bidib_send_cs_drive_intern(tmp_addr, params, action_id, false); return 0; @@ -447,9 +447,9 @@ int bidib_set_train_speed_internal(const char *train, int speed, const char *tra int bidib_set_train_speed(const char *train, int speed, const char *track_output) { int ret = 0; // For bidib_set_train_speed_internal - pthread_rwlock_wrlock(&bidib_state_trains_rwlock); + pthread_rwlock_wrlock(&bidib_trains_rwlock); ret = bidib_set_train_speed_internal(train, speed, track_output); - pthread_rwlock_unlock(&bidib_state_trains_rwlock); + pthread_rwlock_unlock(&bidib_trains_rwlock); return ret; } @@ -463,10 +463,10 @@ int bidib_set_calibrated_train_speed(const char *train, int speed, const char *t return 1; } // For bidib_state_get_train_ref and bidib_set_train_speed_internal - pthread_rwlock_wrlock(&bidib_state_trains_rwlock); + pthread_rwlock_wrlock(&bidib_trains_rwlock); const t_bidib_train *const tmp_train = bidib_state_get_train_ref(train); if (tmp_train == NULL) { - pthread_rwlock_unlock(&bidib_state_trains_rwlock); + pthread_rwlock_unlock(&bidib_trains_rwlock); syslog_libbidib(LOG_ERR, "Set calibrated train speed: %s train does not exist", train); return 1; } @@ -474,7 +474,7 @@ int bidib_set_calibrated_train_speed(const char *train, int speed, const char *t if (tmp_train->calibration == NULL) { syslog_libbidib(LOG_ERR, "Set calibrated train speed: no calibration for train %s", tmp_train->id->str); - pthread_rwlock_unlock(&bidib_state_trains_rwlock); + pthread_rwlock_unlock(&bidib_trains_rwlock); return 1; } @@ -490,7 +490,7 @@ int bidib_set_calibrated_train_speed(const char *train, int speed, const char *t train, g_array_index(tmp_train->calibration, int, speed - 1), track_output); } - pthread_rwlock_unlock(&bidib_state_trains_rwlock); + pthread_rwlock_unlock(&bidib_trains_rwlock); return error; } @@ -500,26 +500,26 @@ int bidib_emergency_stop_train(const char *train, const char *track_output) { return 1; } // For bidib_state_get_train_ref - pthread_rwlock_wrlock(&bidib_state_trains_rwlock); + pthread_rwlock_wrlock(&bidib_trains_rwlock); // For bidib_state_get_board_ref - pthread_rwlock_rdlock(&bidib_state_boards_rwlock); + pthread_rwlock_rdlock(&bidib_boards_rwlock); const t_bidib_train *const tmp_train = bidib_state_get_train_ref(train); const t_bidib_board *const board = bidib_state_get_board_ref(track_output); if (tmp_train == NULL) { - pthread_rwlock_unlock(&bidib_state_boards_rwlock); - pthread_rwlock_unlock(&bidib_state_trains_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); + pthread_rwlock_unlock(&bidib_trains_rwlock); syslog_libbidib(LOG_ERR, "Emergency stop train: train %s doesn't exist", train); return 1; } else if (board == NULL || !board->connected) { - pthread_rwlock_unlock(&bidib_state_boards_rwlock); - pthread_rwlock_unlock(&bidib_state_trains_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); + pthread_rwlock_unlock(&bidib_trains_rwlock); syslog_libbidib(LOG_ERR, "Emergency stop train: board %s doesn't exist or is not connected", track_output); return 1; } else if (!(board->unique_id.class_id & (1 << 4))) { - pthread_rwlock_unlock(&bidib_state_boards_rwlock); - pthread_rwlock_unlock(&bidib_state_trains_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); + pthread_rwlock_unlock(&bidib_trains_rwlock); syslog_libbidib(LOG_ERR, "Emergency stop train: board %s is no track output", track_output); return 1; @@ -550,16 +550,16 @@ int bidib_emergency_stop_train(const char *train, const char *track_output) { train, board->id->str, board->node_addr.top, board->node_addr.sub, board->node_addr.subsub, action_id); t_bidib_node_address tmp_addr = board->node_addr; - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); bidib_send_cs_drive_intern(tmp_addr, params, action_id, false); - pthread_rwlock_unlock(&bidib_state_trains_rwlock); + pthread_rwlock_unlock(&bidib_trains_rwlock); return 0; } } /** * Get the current bit(s) for the train peripherals. - * Shall only be called with bidib_state_trains_rwlock >= read acquired, + * Shall only be called with bidib_trains_rwlock >= read acquired, * and with trackstate_trains_mutex acquired. * * @param train @@ -589,18 +589,18 @@ int bidib_set_train_peripheral(const char *train, const char *peripheral, uint8_ return 1; } // Notes on mutexes/locks: - // - bidib_state_get_train_ref: bidib_state_trains_rwlock >=read - // - bidib_state_get_board_ref: bidib_state_boards_rwlock >=read + // - bidib_state_get_train_ref: bidib_trains_rwlock >=read + // - bidib_state_get_board_ref: bidib_boards_rwlock >=read // - bidib_get_current_train_peripheral_bits: trackstate_trains_mutex (and techn. trains_wrlock) - // - bidib_send_cs_drive_intern: bidib_state_trains_rwlock >=read (as we pass false for lock param) + // - bidib_send_cs_drive_intern: bidib_trains_rwlock >=read (as we pass false for lock param) // For bidib_state_get_train_ref and bidib_send_cs_drive_intern - pthread_rwlock_wrlock(&bidib_state_trains_rwlock); + pthread_rwlock_wrlock(&bidib_trains_rwlock); // For bidib_get_current_train_peripheral_bits pthread_mutex_lock(&trackstate_trains_mutex); // For bidib_state_get_board_ref - pthread_rwlock_rdlock(&bidib_state_boards_rwlock); + pthread_rwlock_rdlock(&bidib_boards_rwlock); const t_bidib_train *const tmp_train = bidib_state_get_train_ref(train); const t_bidib_board *const board = bidib_state_get_board_ref(track_output); @@ -616,9 +616,9 @@ int bidib_set_train_peripheral(const char *train, const char *peripheral, uint8_ syslog_libbidib(LOG_ERR, "Set train peripheral: board %s is not a track output", track_output); } - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); pthread_mutex_unlock(&trackstate_trains_mutex); - pthread_rwlock_unlock(&bidib_state_trains_rwlock); + pthread_rwlock_unlock(&bidib_trains_rwlock); return 1; } @@ -676,16 +676,16 @@ int bidib_set_train_peripheral(const char *train, const char *peripheral, uint8_ peripheral, train, state, board->id->str, board->node_addr.top, board->node_addr.sub, board->node_addr.subsub, action_id); t_bidib_node_address tmp_addr = board->node_addr; - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); pthread_mutex_unlock(&trackstate_trains_mutex); bidib_send_cs_drive_intern(tmp_addr, params, action_id, false); - pthread_rwlock_unlock(&bidib_state_trains_rwlock); + pthread_rwlock_unlock(&bidib_trains_rwlock); return 0; } } - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); pthread_mutex_unlock(&trackstate_trains_mutex); - pthread_rwlock_unlock(&bidib_state_trains_rwlock); + pthread_rwlock_unlock(&bidib_trains_rwlock); syslog_libbidib(LOG_ERR, "Set train peripheral: peripheral %s doesn't exist", peripheral); return 1; } @@ -696,15 +696,15 @@ int bidib_set_booster_power_state(const char *booster, bool on) { return 1; } // For bidib_state_get_board_ref - pthread_rwlock_rdlock(&bidib_state_boards_rwlock); + pthread_rwlock_rdlock(&bidib_boards_rwlock); const t_bidib_board *const board = bidib_state_get_board_ref(booster); if (board == NULL || !board->connected) { - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); syslog_libbidib(LOG_ERR, "Set booster: board %s doesn't exist or is not connected", booster); return 1; } else if (!(board->unique_id.class_id & (1 << 1))) { - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); syslog_libbidib(LOG_ERR, "Set booster: board %s is no booster", booster); return 1; } else { @@ -715,7 +715,7 @@ int bidib_set_booster_power_state(const char *booster, bool on) { board->id->str, board->node_addr.top, board->node_addr.sub, board->node_addr.subsub, "on", action_id); t_bidib_node_address tmp_addr = board->node_addr; - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); bidib_send_boost_on(tmp_addr, 0x01, action_id); } else { syslog_libbidib(LOG_NOTICE, "Set booster: %s (0x%02x 0x%02x " @@ -723,7 +723,7 @@ int bidib_set_booster_power_state(const char *booster, bool on) { board->id->str, board->node_addr.top, board->node_addr.sub, board->node_addr.subsub, "off", action_id); t_bidib_node_address tmp_addr = board->node_addr; - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); bidib_send_boost_off(tmp_addr, 0x01, action_id); } return 0; @@ -736,16 +736,16 @@ int bidib_set_track_output_state(const char *track_output, t_bidib_cs_state stat return 1; } // For bidib_state_get_board_ref - pthread_rwlock_rdlock(&bidib_state_boards_rwlock); + pthread_rwlock_rdlock(&bidib_boards_rwlock); const t_bidib_board *const board = bidib_state_get_board_ref(track_output); if (board == NULL || !board->connected) { - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); syslog_libbidib(LOG_ERR, "Set track output state: board %s does not exist or is not connected", track_output); return 1; } else if (!(board->unique_id.class_id & (1 << 4))) { - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); syslog_libbidib(LOG_ERR, "Set track output state: board %s is no track output", track_output); return 1; @@ -756,14 +756,14 @@ int bidib_set_track_output_state(const char *track_output, t_bidib_cs_state stat board->id->str, board->node_addr.top, board->node_addr.sub, board->node_addr.subsub, state, action_id); t_bidib_node_address tmp_addr = board->node_addr; - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); bidib_send_cs_set_state(tmp_addr, state, action_id); return 0; } } void bidib_set_track_output_state_all(t_bidib_cs_state state) { - pthread_rwlock_rdlock(&bidib_state_boards_rwlock); + pthread_rwlock_rdlock(&bidib_boards_rwlock); unsigned int action_id = bidib_get_and_incr_action_id(); syslog_libbidib(LOG_NOTICE, "Set all track outputs to state: 0x%02x with action id: %d", state, action_id); @@ -773,7 +773,7 @@ void bidib_set_track_output_state_all(t_bidib_cs_state state) { bidib_send_cs_set_state(board_i->node_addr, state, action_id); } } - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); } int bidib_request_reverser_state(const char *reverser, const char *board) { @@ -785,20 +785,20 @@ int bidib_request_reverser_state(const char *reverser, const char *board) { // For bidib_state_get_reverser_state_ref (devnote: write) pthread_mutex_lock(&trackstate_reversers_mutex); // For bidib_state_get_board_ref and bidib_state_get_reverser_mapping_ref - pthread_rwlock_rdlock(&bidib_state_boards_rwlock); + pthread_rwlock_rdlock(&bidib_boards_rwlock); const t_bidib_board *board_ref = bidib_state_get_board_ref(board); const t_bidib_reverser_mapping *mapping_ref = bidib_state_get_reverser_mapping_ref(reverser); t_bidib_reverser_state *state_ref = bidib_state_get_reverser_state_ref(reverser); if (board_ref == NULL || !board_ref->connected) { - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); pthread_mutex_unlock(&trackstate_reversers_mutex); syslog_libbidib(LOG_ERR, "Request reverser state: board %s doesn't exist or is not connected", board); return 1; } else if (mapping_ref == NULL || state_ref == NULL) { - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); pthread_mutex_unlock(&trackstate_reversers_mutex); syslog_libbidib(LOG_ERR, "Request reverser state: reverser %s does not exist", @@ -814,7 +814,7 @@ int bidib_request_reverser_state(const char *reverser, const char *board) { bidib_send_vendor_get(board_ref->node_addr, (uint8_t)mapping_ref->cv->len, (uint8_t *)mapping_ref->cv->str, 0); - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); pthread_mutex_unlock(&trackstate_reversers_mutex); return 0; } diff --git a/src/highlevel/bidib_highlevel_util.c b/src/highlevel/bidib_highlevel_util.c index acc8789..71430ab 100644 --- a/src/highlevel/bidib_highlevel_util.c +++ b/src/highlevel/bidib_highlevel_util.c @@ -52,8 +52,8 @@ static pthread_t bidib_heartbeat_thread = 0; // bidib_track_state, bidib_trains data structures. // They do NOT protect the concurrent sending of low-level commands // to the BiDiB master node over a serial connection. -pthread_rwlock_t bidib_state_trains_rwlock; -pthread_rwlock_t bidib_state_boards_rwlock; +pthread_rwlock_t bidib_trains_rwlock; +pthread_rwlock_t bidib_boards_rwlock; pthread_mutex_t trackstate_accessories_mutex; pthread_mutex_t trackstate_peripherals_mutex; @@ -69,8 +69,8 @@ volatile bool bidib_discard_rx = true; volatile bool bidib_lowlevel_debug_mode = false; static void bidib_init_rwlocks(void) { - pthread_rwlock_init(&bidib_state_trains_rwlock, NULL); - pthread_rwlock_init(&bidib_state_boards_rwlock, NULL); + pthread_rwlock_init(&bidib_trains_rwlock, NULL); + pthread_rwlock_init(&bidib_boards_rwlock, NULL); } static void bidib_init_mutexes(void) { diff --git a/src/lowlevel/bidib_lowlevel_intern.h b/src/lowlevel/bidib_lowlevel_intern.h index 5f76f67..e92d8cc 100644 --- a/src/lowlevel/bidib_lowlevel_intern.h +++ b/src/lowlevel/bidib_lowlevel_intern.h @@ -36,7 +36,7 @@ /** * Used to avoid the usage of a recursive rwlock. - * Shall be called with param `lock` = false if bidib_state_trains_rwlock + * Shall be called with param `lock` = false if bidib_trains_rwlock * has already been acquired with >= read. * * @param node_address the three bytes on top of the address stack. @@ -52,7 +52,7 @@ void bidib_send_cs_drive_intern(t_bidib_node_address node_address, /** * Issues an accessory command. * Shall only be called with trackstate_accessories_mutex acquired, - * and with bidib_state_boards_rwlock >=read acquired. + * and with bidib_boards_rwlock >=read acquired. * * @param node_address the three bytes on top of the address stack. * @param cs_accessory_params the parameters. diff --git a/src/lowlevel/bidib_lowlevel_system.c b/src/lowlevel/bidib_lowlevel_system.c index f77003b..e1fd05c 100644 --- a/src/lowlevel/bidib_lowlevel_system.c +++ b/src/lowlevel/bidib_lowlevel_system.c @@ -123,9 +123,9 @@ void bidib_send_sys_reset(unsigned int action_id) { bidib_set_track_output_state_all(BIDIB_CS_GO); bidib_flush(); usleep(500000); // wait for track output so it can receive initial values - pthread_rwlock_rdlock(&bidib_state_boards_rwlock); + pthread_rwlock_rdlock(&bidib_boards_rwlock); bidib_state_query_occupancy(); - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); bidib_flush(); usleep(500000); // wait for occupancy data bidib_state_set_initial_values(); diff --git a/src/lowlevel/bidib_lowlevel_track.c b/src/lowlevel/bidib_lowlevel_track.c index f76e99c..8901a32 100644 --- a/src/lowlevel/bidib_lowlevel_track.c +++ b/src/lowlevel/bidib_lowlevel_track.c @@ -83,9 +83,9 @@ void bidib_send_cs_drive_intern(t_bidib_node_address node_address, cs_drive_params.function3, cs_drive_params.function4}; bidib_buffer_message_with_data(addr_stack, MSG_CS_DRIVE, 9, data, action_id); if (lock) { - pthread_rwlock_rdlock(&bidib_state_trains_rwlock); + pthread_rwlock_rdlock(&bidib_trains_rwlock); bidib_state_cs_drive(cs_drive_params); - pthread_rwlock_unlock(&bidib_state_trains_rwlock); + pthread_rwlock_unlock(&bidib_trains_rwlock); } else { bidib_state_cs_drive(cs_drive_params); } @@ -114,11 +114,11 @@ void bidib_send_cs_accessory(t_bidib_node_address node_address, unsigned int action_id) { // Both for bidib_send_cs_accessory_intern (devnote: write) pthread_mutex_lock(&trackstate_accessories_mutex); - pthread_rwlock_rdlock(&bidib_state_boards_rwlock); + pthread_rwlock_rdlock(&bidib_boards_rwlock); bidib_send_cs_accessory_intern(node_address, cs_accessory_params, action_id); - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); pthread_mutex_unlock(&trackstate_accessories_mutex); } diff --git a/src/state/bidib_state.c b/src/state/bidib_state.c index 1a1d474..d355cc5 100644 --- a/src/state/bidib_state.c +++ b/src/state/bidib_state.c @@ -94,7 +94,7 @@ int bidib_state_init(const char *config_dir) { // Locks/Mutexes: // - Writes to bidib_boards array is protected by acquiring -// bidib_state_boards_rwlock. +// bidib_boards_rwlock. // - Internal: bidib_uplink_intern_queue_mutex, bidib_node_state_table_mutex // Params: // - May modify sub_iface_queue: Appends interface nodes. @@ -173,7 +173,7 @@ static bool bidib_state_query_nodetab(t_bidib_node_address node_address, } else { node_address_i.subsub = local_node_addr; } - pthread_rwlock_wrlock(&bidib_state_boards_rwlock); + pthread_rwlock_wrlock(&bidib_boards_rwlock); t_bidib_board *board_i = bidib_state_get_board_ref_by_uniqueid(unique_id_i); if (board_i == NULL) { syslog_libbidib(LOG_ERR, @@ -188,7 +188,7 @@ static bool bidib_state_query_nodetab(t_bidib_node_address node_address, board_i->id->str, board_i->node_addr.top, board_i->node_addr.sub, board_i->node_addr.subsub); } - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); if (i > 0 && unique_id_i.class_id & (1 << 7)) { // add node to queue if it is an interface t_bidib_node_address *sub_iface_addr = malloc(sizeof(t_bidib_node_address)); @@ -248,7 +248,7 @@ void bidib_state_query_occupancy(void) { } void bidib_state_set_board_features(void) { - pthread_rwlock_rdlock(&bidib_state_boards_rwlock); + pthread_rwlock_rdlock(&bidib_boards_rwlock); for (size_t i = 0; i < bidib_boards->len; i++) { const t_bidib_board *const board_i = &g_array_index(bidib_boards, t_bidib_board, i); if (board_i->connected) { @@ -298,7 +298,7 @@ void bidib_state_set_board_features(void) { } } } - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); } void bidib_state_set_initial_values(void) { @@ -415,19 +415,19 @@ t_bidib_bm_confidence_level bidib_bm_confidence_to_level(t_bidib_segment_state_c bool bidib_state_add_board(t_bidib_board board) { bool error = false; // For bidib_state_get_board_ref, bidib_state_get_board_ref_by_uniqueid, and accessing bidib_boards - pthread_rwlock_wrlock(&bidib_state_boards_rwlock); + pthread_rwlock_wrlock(&bidib_boards_rwlock); if (bidib_state_get_board_ref(board.id->str) != NULL || bidib_state_get_board_ref_by_uniqueid(board.unique_id) != NULL) { error = true; } else { g_array_append_val(bidib_boards, board); } - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); return error; } bool bidib_state_dcc_addr_in_use(t_bidib_dcc_address dcc_address) { - pthread_rwlock_rdlock(&bidib_state_boards_rwlock); + pthread_rwlock_rdlock(&bidib_boards_rwlock); for (size_t i = 0; i < bidib_boards->len; i++) { const t_bidib_board *const tmp_board = &g_array_index(bidib_boards, t_bidib_board, i); @@ -437,7 +437,7 @@ bool bidib_state_dcc_addr_in_use(t_bidib_dcc_address dcc_address) { t_bidib_dcc_accessory_mapping, j); if (tmp_dcc_mapping->dcc_addr.addrl == dcc_address.addrl && tmp_dcc_mapping->dcc_addr.addrh == dcc_address.addrh) { - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); return true; } } @@ -448,12 +448,12 @@ bool bidib_state_dcc_addr_in_use(t_bidib_dcc_address dcc_address) { t_bidib_dcc_accessory_mapping, j); if (tmp_dcc_mapping->dcc_addr.addrl == dcc_address.addrl && tmp_dcc_mapping->dcc_addr.addrh == dcc_address.addrh) { - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); return true; } } } - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); for (size_t i = 0; i < bidib_trains->len; i++) { const t_bidib_train *const tmp_train = &g_array_index(bidib_trains, t_bidib_train, i); @@ -611,12 +611,12 @@ bool bidib_state_add_board_signal_state(t_bidib_board_accessory_state signal_sta bool bidib_state_add_dcc_point_state(t_bidib_dcc_accessory_state point_state, t_bidib_dcc_address dcc_address) { - pthread_rwlock_rdlock(&bidib_state_trains_rwlock); + pthread_rwlock_rdlock(&bidib_trains_rwlock); if (bidib_state_point_exists(point_state.id) || bidib_state_dcc_addr_in_use(dcc_address)) { return true; } - pthread_rwlock_unlock(&bidib_state_trains_rwlock); + pthread_rwlock_unlock(&bidib_trains_rwlock); // For accessing bidib_track_state.points_dcc (devnote: write) pthread_mutex_lock(&trackstate_accessories_mutex); @@ -627,12 +627,12 @@ bool bidib_state_add_dcc_point_state(t_bidib_dcc_accessory_state point_state, bool bidib_state_add_dcc_signal_state(t_bidib_dcc_accessory_state signal_state, t_bidib_dcc_address dcc_address) { - pthread_rwlock_rdlock(&bidib_state_trains_rwlock); + pthread_rwlock_rdlock(&bidib_trains_rwlock); if (bidib_state_signal_exists(signal_state.id) || bidib_state_dcc_addr_in_use(dcc_address)) { return true; } - pthread_rwlock_unlock(&bidib_state_trains_rwlock); + pthread_rwlock_unlock(&bidib_trains_rwlock); // For accessing bidib_track_state.signals_dcc (devnote: write) pthread_mutex_lock(&trackstate_accessories_mutex); @@ -694,7 +694,7 @@ void bidib_state_update_train_available(void) { // Notes regarding mutexes/locks: // - accessing bidib_track_state.trains: trackstate_trains_mutex // - bidib_get_train_position_intern: - // trackstate_segments_mutex, trackstate_trains_mutex, bidib_state_trains_rwlock >= read + // trackstate_segments_mutex, trackstate_trains_mutex, bidib_trains_rwlock >= read t_bidib_train_state_intern *train_state; t_bidib_train_position_query query; struct timespec tv; @@ -877,7 +877,7 @@ void bidib_state_reset_train_params(void) { params.function3 = 0x00; params.function4 = 0x00; // For bidib_send_cs_drive_intern - pthread_rwlock_wrlock(&bidib_state_trains_rwlock); + pthread_rwlock_wrlock(&bidib_trains_rwlock); for (size_t i = 0; i < bidib_trains->len; i++) { const t_bidib_train *const train_i = &g_array_index(bidib_trains, t_bidib_train, i); params.dcc_address = train_i->dcc_addr; @@ -894,16 +894,16 @@ void bidib_state_reset_train_params(void) { break; } // For accessing bidib_boards - pthread_rwlock_rdlock(&bidib_state_boards_rwlock); + pthread_rwlock_rdlock(&bidib_boards_rwlock); for (size_t j = 0; j < bidib_boards->len; j++) { const t_bidib_board *const board_i = &g_array_index(bidib_boards, t_bidib_board, j); if (board_i->connected && board_i->unique_id.class_id & (1 << 4)) { - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); bidib_send_cs_drive_intern(board_i->node_addr, params, 0, false); - pthread_rwlock_rdlock(&bidib_state_boards_rwlock); + pthread_rwlock_rdlock(&bidib_boards_rwlock); } } - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); } - pthread_rwlock_unlock(&bidib_state_trains_rwlock); + pthread_rwlock_unlock(&bidib_trains_rwlock); } diff --git a/src/state/bidib_state_getter.c b/src/state/bidib_state_getter.c index 72a58ac..36bd33f 100644 --- a/src/state/bidib_state_getter.c +++ b/src/state/bidib_state_getter.c @@ -322,7 +322,7 @@ t_bidib_segment_state_intern bidib_state_get_segment_state( t_bidib_segment_state_intern *bidib_state_get_segment_state_ref_by_nodeaddr( t_bidib_node_address node_address, uint8_t number) { // For bidib_state_get_board_ref_by_nodeaddr - pthread_rwlock_rdlock(&bidib_state_boards_rwlock); + pthread_rwlock_rdlock(&bidib_boards_rwlock); const t_bidib_board *const board = bidib_state_get_board_ref_by_nodeaddr(node_address); if (board != NULL) { for (size_t i = 0; i < board->segments->len; i++) { @@ -330,12 +330,12 @@ t_bidib_segment_state_intern *bidib_state_get_segment_state_ref_by_nodeaddr( t_bidib_segment_mapping, i); if (mapping_i.addr == number) { t_bidib_segment_state_intern *ret = bidib_state_get_segment_state_ref(mapping_i.id->str); - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); return ret; } } } - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); return NULL; } @@ -452,12 +452,12 @@ t_bidib_booster_state *bidib_state_get_booster_state_ref_by_nodeaddr( t_bidib_node_address node_address) { t_bidib_booster_state *booster_state = NULL; // For bidib_state_get_board_ref_by_nodeaddr - pthread_rwlock_rdlock(&bidib_state_boards_rwlock); + pthread_rwlock_rdlock(&bidib_boards_rwlock); const t_bidib_board *sender = bidib_state_get_board_ref_by_nodeaddr(node_address); if (sender != NULL) { booster_state = bidib_state_get_booster_state_ref(sender->id->str); } - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); return booster_state; } @@ -465,11 +465,11 @@ t_bidib_track_output_state *bidib_state_get_track_output_state_ref_by_nodeaddr( t_bidib_node_address node_address) { t_bidib_track_output_state *track_output_state = NULL; // For bidib_state_get_board_ref_by_nodeaddr - pthread_rwlock_rdlock(&bidib_state_boards_rwlock); + pthread_rwlock_rdlock(&bidib_boards_rwlock); const t_bidib_board *sender = bidib_state_get_board_ref_by_nodeaddr(node_address); if (sender != NULL) { track_output_state = bidib_state_get_track_output_state_ref(sender->id->str); } - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); return track_output_state; } diff --git a/src/state/bidib_state_getter_intern.h b/src/state/bidib_state_getter_intern.h index 48010bc..c4821d9 100644 --- a/src/state/bidib_state_getter_intern.h +++ b/src/state/bidib_state_getter_intern.h @@ -37,7 +37,7 @@ /** * Returns the reference to the board with the given id. - * Shall only be called with bidib_state_boards_rwlock >= read acquired. + * Shall only be called with bidib_boards_rwlock >= read acquired. * * @param board the id of the board. * @return NULL if not found, otherwise the reference to the board. @@ -46,7 +46,7 @@ t_bidib_board *bidib_state_get_board_ref(const char *board); /** * Returns the reference to the board with the given unique id. - * Shall only be called with bidib_state_boards_rwlock >= read acquired. + * Shall only be called with bidib_boards_rwlock >= read acquired. * * @param unique_id the unique id of the board. * @return NULL if not found, otherwise the reference to the board. @@ -73,7 +73,7 @@ t_bidib_track_output_state *bidib_state_get_track_output_state_ref(const char *t /** * Returns the reference to the board accessory mapping with the given id. - * Shall only be called with bidib_state_boards_rwlock >= read acquired. + * Shall only be called with bidib_boards_rwlock >= read acquired. * * @param accessory the id of the board accessory. * @param point whether the accessory is a point or a signal. @@ -84,7 +84,7 @@ t_bidib_board_accessory_mapping *bidib_state_get_board_accessory_mapping_ref( /** * Returns the reference to the board accessory mapping with the given number. - * Shall only be called with bidib_state_boards_rwlock >= read acquired. + * Shall only be called with bidib_boards_rwlock >= read acquired. * * @param node_address the node address of the board. * @param number the number of the accessory. @@ -108,7 +108,7 @@ t_bidib_board_accessory_state *bidib_state_get_board_accessory_state_ref(const c /** * Returns the reference to the dcc accessory mapping with the given id. - * Shall only be called with bidib_state_boards_rwlock >= read acquired. + * Shall only be called with bidib_boards_rwlock >= read acquired. * * @param accessory the id of the dcc accessory. * @param point whether the accessory is a point or a signal. @@ -119,7 +119,7 @@ t_bidib_dcc_accessory_mapping *bidib_state_get_dcc_accessory_mapping_ref( /** * Returns the reference to the dcc accessory mapping with the given dcc address. - * Shall only be called with bidib_state_boards_rwlock >= read acquired. + * Shall only be called with bidib_boards_rwlock >= read acquired. * * @param node_address the node address of the board. * @param dcc_address the dcc address of the accessory. @@ -143,7 +143,7 @@ t_bidib_dcc_accessory_state *bidib_state_get_dcc_accessory_state_ref(const char /** * Returns the reference to the peripheral mapping with the given id. - * Shall only be called with bidib_state_boards_rwlock >= read acquired. + * Shall only be called with bidib_boards_rwlock >= read acquired. * * @param peripheral the id of the peripheral. * @return NULL if not found, otherwise the reference to the peripheral mapping. @@ -152,7 +152,7 @@ t_bidib_peripheral_mapping *bidib_state_get_peripheral_mapping_ref(const char *p /** * Returns the reference to the peripheral mapping with the given port. - * Shall only be called with the bidib_state_boards_rwlock >= read acquired. + * Shall only be called with the bidib_boards_rwlock >= read acquired. * * @param node_address the node address of the board. * @param port the port of the peripheral. @@ -191,8 +191,8 @@ t_bidib_segment_state_intern bidib_state_get_segment_state( /** * Returns the reference to the segment state with the given id. * Shall only be called with trackstate_segments_mutex acquired. - * Note: uses bidib_state_boards_rwlock internally, so shall not be called - * with bidib_state_boards_rwlock already acquired. + * Note: uses bidib_boards_rwlock internally, so shall not be called + * with bidib_boards_rwlock already acquired. * * @param node_address the node address of the board. * @param number the number on the board. @@ -212,7 +212,7 @@ t_bidib_reverser_state *bidib_state_get_reverser_state_ref(const char *reverser) /** * Returns the reference to the reverser mapping with the given CV. - * Shall only be called with the bidib_state_boards_rwlock >= read acquired. + * Shall only be called with the bidib_boards_rwlock >= read acquired. * * @param node_address the node address of the board. * @param cv the CV of the reverser. @@ -223,7 +223,7 @@ t_bidib_reverser_mapping *bidib_state_get_reverser_mapping_ref_by_cv( /** * Returns the reference to the reverser mapping with the given id. - * Shall only be called with the bidib_state_boards_rwlock >= read acquired. + * Shall only be called with the bidib_boards_rwlock >= read acquired. * * @param id the name of the reverser. * @return NULL if not found, otherwise the reference to the reverser mapping. @@ -232,7 +232,7 @@ t_bidib_reverser_mapping *bidib_state_get_reverser_mapping_ref(const char *rever /** * Returns the reference to the board with the given node address. - * Shall only be called with bidib_state_boards_rwlock >= read acquired. + * Shall only be called with bidib_boards_rwlock >= read acquired. * * @param node_address the node address of the board. * @return NULL if not found, otherwise the reference to the board. @@ -241,7 +241,7 @@ t_bidib_board *bidib_state_get_board_ref_by_nodeaddr(t_bidib_node_address node_a /** * Returns the reference to the train with the given id. - * Shall only be called with bidib_state_trains_rwlock >= read acquired. + * Shall only be called with bidib_trains_rwlock >= read acquired. * * @param train the id of the train. * @return NULL if not found, otherwise the reference to the train. @@ -250,7 +250,7 @@ t_bidib_train *bidib_state_get_train_ref(const char *train); /** * Returns the reference to the train state with the given dcc address. - * Shall only be called with bidib_state_trains_rwlock >= read acquired, + * Shall only be called with bidib_trains_rwlock >= read acquired, * and with trackstate_trains_mutex acquired. * * @param dcc_address the dcc address of the train. @@ -261,7 +261,7 @@ t_bidib_train_state_intern *bidib_state_get_train_state_ref_by_dccaddr( /** * Returns the reference to the train peripheral state with the given bit. - * Shall only be called with bidib_state_trains_rwlock >= read acquired. + * Shall only be called with bidib_trains_rwlock >= read acquired. * * @param train_state the train state. * @param bit the bit of the peripheral. @@ -282,7 +282,7 @@ t_bidib_train_state_intern *bidib_state_get_train_state_ref(const char *train); /** * Returns the reference to the booster state with the given node address. * Shall only be called with trackstate_boosters_mutex acquired. - * Note: uses bidib_state_boards_rwlock internally. + * Note: uses bidib_boards_rwlock internally. * * @param node_address the node address of the board. * @return NULL if not found, otherwise the reference to the booster state. @@ -293,7 +293,7 @@ t_bidib_booster_state *bidib_state_get_booster_state_ref_by_nodeaddr( /** * Returns the reference to the track output state with the given node address. * Shall only be called with trackstate_track_outputs_mutex acquired. - * Note: uses bidib_state_boards_rwlock internally. + * Note: uses bidib_boards_rwlock internally. * * @param node_address the node address of the board. * @return NULL if not found, otherwise the reference to the track output state. diff --git a/src/state/bidib_state_intern.h b/src/state/bidib_state_intern.h index b17aded..0b846a4 100644 --- a/src/state/bidib_state_intern.h +++ b/src/state/bidib_state_intern.h @@ -167,8 +167,8 @@ typedef struct { GArray *trains; } t_bidib_state_initial_values; -extern pthread_rwlock_t bidib_state_trains_rwlock; -extern pthread_rwlock_t bidib_state_boards_rwlock; +extern pthread_rwlock_t bidib_trains_rwlock; +extern pthread_rwlock_t bidib_boards_rwlock; extern pthread_mutex_t trackstate_accessories_mutex; extern pthread_mutex_t trackstate_peripherals_mutex; @@ -415,8 +415,8 @@ void bidib_state_free_single_segment_state_intern(t_bidib_segment_state_intern s /** * Checks whether a dcc address is already used by a train, point or signal. - * Shall only be called with bidib_state_trains_rwlock >=read acquired. - * Note: uses bidib_state_boards_rwlock internally. + * Shall only be called with bidib_trains_rwlock >=read acquired. + * Note: uses bidib_boards_rwlock internally. * * @param dcc_address the dcc address which should be checked. * @return true if the dcc address is already in use, otherwise false. @@ -425,7 +425,7 @@ bool bidib_state_dcc_addr_in_use(t_bidib_dcc_address dcc_address); /** * Adds a train to the current state. - * Shall only be called with bidib_state_trains_rwlock >= read acquired. + * Shall only be called with bidib_trains_rwlock >= read acquired. * * @param train the new train. * @return true if NULL or train already exists, otherwise false. @@ -469,7 +469,7 @@ void bidib_state_add_initial_train_value(t_bidib_state_train_initial_value value /** * Updates the available state for all trains. - * Shall only be called with bidib_state_trains_rwlock >= read acquired, + * Shall only be called with bidib_trains_rwlock >= read acquired, * and with trackstate_segments_mutex and trackstate_trains_mutex acquired. */ void bidib_state_update_train_available(void); diff --git a/src/state/bidib_state_setter.c b/src/state/bidib_state_setter.c index b3875af..774ae2f 100644 --- a/src/state/bidib_state_setter.c +++ b/src/state/bidib_state_setter.c @@ -42,7 +42,7 @@ void bidib_state_vendor(t_bidib_node_address node_address, uint8_t length, // For bidib_state_get_reverser_state_ref (devnote: write) pthread_mutex_lock(&trackstate_reversers_mutex); // For bidib_state_get_reverser_mapping_ref_by_cv - pthread_rwlock_rdlock(&bidib_state_boards_rwlock); + pthread_rwlock_rdlock(&bidib_boards_rwlock); uint8_t name_len = value_list[0]; char *name = strndup((const char *)&value_list[1], name_len); @@ -56,7 +56,7 @@ void bidib_state_vendor(t_bidib_node_address node_address, uint8_t length, t_bidib_reverser_state *reverser_state = bidib_state_get_reverser_state_ref(mapping->id->str); if (reverser_state == NULL) { - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); pthread_mutex_unlock(&trackstate_reversers_mutex); syslog_libbidib(LOG_ERR, "Feedback for vendor-specific configuration %s (value %s) " @@ -96,7 +96,7 @@ void bidib_state_vendor(t_bidib_node_address node_address, uint8_t length, node_address.top, node_address.sub, node_address.subsub); } - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); pthread_mutex_unlock(&trackstate_reversers_mutex); free(name); @@ -127,7 +127,7 @@ void bidib_state_accessory_state(t_bidib_node_address node_address, uint8_t numb // For bidib_state_get_board_accessory_state_ref (devnote: write) pthread_mutex_lock(&trackstate_accessories_mutex); // For bidib_state_get_board_accessory_mapping_ref_by_number - pthread_rwlock_rdlock(&bidib_state_boards_rwlock); + pthread_rwlock_rdlock(&bidib_boards_rwlock); bool point; const t_bidib_board_accessory_mapping *const accessory_mapping = bidib_state_get_board_accessory_mapping_ref_by_number(node_address, number, &point); @@ -184,14 +184,14 @@ void bidib_state_accessory_state(t_bidib_node_address node_address, uint8_t numb "No board accessory 0x%02x configured for node address 0x%02x 0x%02x 0x%02x 0x00", number, node_address.top, node_address.sub, node_address.subsub); } - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); pthread_mutex_unlock(&trackstate_accessories_mutex); } void bidib_state_node_new(t_bidib_node_address node_address, uint8_t local_addr, t_bidib_unique_id_mod unique_id) { // For bidib_state_get_board_ref_by_uniqueid - pthread_rwlock_wrlock(&bidib_state_boards_rwlock); + pthread_rwlock_wrlock(&bidib_boards_rwlock); t_bidib_board *board = bidib_state_get_board_ref_by_uniqueid(unique_id); if (board != NULL) { board->connected = true; @@ -210,7 +210,7 @@ void bidib_state_node_new(t_bidib_node_address node_address, uint8_t local_addr, unique_id.product_id1, unique_id.product_id2, unique_id.product_id3, unique_id.product_id4); } - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); } static bool bidib_state_is_subnode(t_bidib_node_address node_address, @@ -232,7 +232,7 @@ static bool bidib_state_is_subnode(t_bidib_node_address node_address, void bidib_state_node_lost(t_bidib_unique_id_mod unique_id) { // For bidib_state_get_board_ref_by_uniqueid - pthread_rwlock_wrlock(&bidib_state_boards_rwlock); + pthread_rwlock_wrlock(&bidib_boards_rwlock); t_bidib_board *board = bidib_state_get_board_ref_by_uniqueid(unique_id); if (board != NULL) { board->connected = false; @@ -253,7 +253,7 @@ void bidib_state_node_lost(t_bidib_unique_id_mod unique_id) { unique_id.product_id1, unique_id.product_id2, unique_id.product_id3, unique_id.product_id4); } - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); } void bidib_state_cs_state(t_bidib_node_address node_address, uint8_t state, @@ -279,7 +279,7 @@ void bidib_state_cs_state(t_bidib_node_address node_address, uint8_t state, void bidib_state_cs_drive_ack(t_bidib_dcc_address dcc_address, uint8_t ack, unsigned int action_id) { // For bidib_state_get_train_state_ref_by_dccaddr and bidib_state_dcc_addr_in_use - pthread_rwlock_rdlock(&bidib_state_trains_rwlock); + pthread_rwlock_rdlock(&bidib_trains_rwlock); // For bidib_state_get_train_state_ref_by_dccaddr (devnote: write) pthread_mutex_lock(&trackstate_trains_mutex); @@ -300,7 +300,7 @@ void bidib_state_cs_drive_ack(t_bidib_dcc_address dcc_address, uint8_t ack, unsi } } pthread_mutex_unlock(&trackstate_trains_mutex); - pthread_rwlock_unlock(&bidib_state_trains_rwlock); + pthread_rwlock_unlock(&bidib_trains_rwlock); } void bidib_state_cs_accessory_ack(t_bidib_node_address node_address, @@ -474,7 +474,7 @@ void bidib_state_lc_stat(t_bidib_node_address node_address, t_bidib_peripheral_p // For bidib_state_get_peripheral_state_ref (devnote: write) pthread_mutex_lock(&trackstate_peripherals_mutex); // For bidib_state_get_peripheral_mapping_ref_by_port - pthread_rwlock_rdlock(&bidib_state_boards_rwlock); + pthread_rwlock_rdlock(&bidib_boards_rwlock); const t_bidib_peripheral_mapping *const peripheral_mapping = bidib_state_get_peripheral_mapping_ref_by_port(node_address, port); @@ -509,7 +509,7 @@ void bidib_state_lc_stat(t_bidib_node_address node_address, t_bidib_peripheral_p port.port0, port.port1, node_address.top, node_address.sub, node_address.subsub); } - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); pthread_mutex_unlock(&trackstate_peripherals_mutex); } @@ -520,7 +520,7 @@ void bidib_state_lc_wait(t_bidib_node_address node_address, t_bidib_peripheral_p // For bidib_state_get_peripheral_state_ref (devnote: write) pthread_mutex_lock(&trackstate_peripherals_mutex); // For bidib_state_get_peripheral_mapping_ref_by_port - pthread_rwlock_rdlock(&bidib_state_boards_rwlock); + pthread_rwlock_rdlock(&bidib_boards_rwlock); const t_bidib_peripheral_mapping *const peripheral_mapping = bidib_state_get_peripheral_mapping_ref_by_port(node_address, port); @@ -539,13 +539,13 @@ void bidib_state_lc_wait(t_bidib_node_address node_address, t_bidib_peripheral_p port.port0, port.port1, node_address.top, node_address.sub, node_address.subsub); } - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); pthread_mutex_unlock(&trackstate_peripherals_mutex); } /** * Logging utility for if a known or unknown train enters/exits a segment. - * Shall only be called with bidib_state_trains_rwlock >=read acquired, + * Shall only be called with bidib_trains_rwlock >=read acquired, * and with trackstate_trains_mutex acquired. * * @param detected if the train was detected (=entered, true) or left (=exited, false) a segment @@ -593,7 +593,7 @@ void bidib_state_log_train_detect(bool detected, const t_bidib_dcc_address *cons void bidib_state_bm_occ(t_bidib_node_address node_address, uint8_t number, bool occ) { // For bidib_state_log_train_detect and bidib_state_update_train_available - pthread_rwlock_rdlock(&bidib_state_trains_rwlock); + pthread_rwlock_rdlock(&bidib_trains_rwlock); // For bidib_state_get_segment_state_ref_by_nodeaddr and bidib_state_update_train_available // (devnote: write) @@ -623,14 +623,14 @@ void bidib_state_bm_occ(t_bidib_node_address node_address, uint8_t number, bool } pthread_mutex_unlock(&trackstate_trains_mutex); pthread_mutex_unlock(&trackstate_segments_mutex); - pthread_rwlock_unlock(&bidib_state_trains_rwlock); + pthread_rwlock_unlock(&bidib_trains_rwlock); } void bidib_state_bm_multiple(t_bidib_node_address node_address, uint8_t number, uint8_t size, const uint8_t *const data) { t_bidib_segment_state_intern *segment_state; // For bidib_state_log_train_detect and bidib_state_update_train_available - pthread_rwlock_rdlock(&bidib_state_trains_rwlock); + pthread_rwlock_rdlock(&bidib_trains_rwlock); // For bidib_state_get_segment_state_ref_by_nodeaddr and bidib_state_update_train_available // (devnote: write) @@ -667,7 +667,7 @@ void bidib_state_bm_multiple(t_bidib_node_address node_address, uint8_t number, bidib_state_update_train_available(); pthread_mutex_unlock(&trackstate_trains_mutex); pthread_mutex_unlock(&trackstate_segments_mutex); - pthread_rwlock_unlock(&bidib_state_trains_rwlock); + pthread_rwlock_unlock(&bidib_trains_rwlock); } void bidib_state_bm_confidence(t_bidib_node_address node_address, uint8_t conf_void, @@ -675,7 +675,7 @@ void bidib_state_bm_confidence(t_bidib_node_address node_address, uint8_t conf_v // For bidib_state_get_segment_state_ref (devnote: write) pthread_mutex_lock(&trackstate_segments_mutex); // For bidib_state_get_board_ref_by_nodeaddr - pthread_rwlock_rdlock(&bidib_state_boards_rwlock); + pthread_rwlock_rdlock(&bidib_boards_rwlock); const t_bidib_board *const board = bidib_state_get_board_ref_by_nodeaddr(node_address); if (board != NULL) { @@ -715,13 +715,13 @@ void bidib_state_bm_confidence(t_bidib_node_address node_address, uint8_t conf_v "No board configured for node address 0x%02x 0x%02x 0x%02x 0x00", node_address.top, node_address.sub, node_address.subsub); } - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); pthread_mutex_unlock(&trackstate_segments_mutex); } /** * Check for new and lost dcc addresses in segment state and log accordingly. - * Shall only be called with bidib_state_trains_rwlock >= read acquired, + * Shall only be called with bidib_trains_rwlock >= read acquired, * and with trackstate_trains_mutex acquired. * * @param segment_state_intern_query the segment for which to log address changes, state with old addrs. @@ -789,7 +789,7 @@ void bidib_state_bm_address_log_changes( void bidib_state_bm_address(t_bidib_node_address node_address, uint8_t number, uint8_t address_count, const uint8_t *const addresses) { // For bidib_state_update_train_available and bidib_state_bm_address_log_changes - pthread_rwlock_rdlock(&bidib_state_trains_rwlock); + pthread_rwlock_rdlock(&bidib_trains_rwlock); // For bidib_state_get_segment_state_ref_by_nodeaddr and bidib_state_update_train_available // (devnote: write) @@ -834,7 +834,7 @@ void bidib_state_bm_address(t_bidib_node_address node_address, uint8_t number, } pthread_mutex_unlock(&trackstate_trains_mutex); pthread_mutex_unlock(&trackstate_segments_mutex); - pthread_rwlock_unlock(&bidib_state_trains_rwlock); + pthread_rwlock_unlock(&bidib_trains_rwlock); } void bidib_state_bm_current(t_bidib_node_address node_address, uint8_t number, @@ -887,7 +887,7 @@ void bidib_state_bm_current(t_bidib_node_address node_address, uint8_t number, void bidib_state_bm_speed(t_bidib_dcc_address dcc_address, uint8_t speedl, uint8_t speedh) { // For bidib_state_get_train_state_ref_by_dccaddr - pthread_rwlock_rdlock(&bidib_state_trains_rwlock); + pthread_rwlock_rdlock(&bidib_trains_rwlock); // For bidib_state_get_train_state_ref_by_dccaddr (devnote: write) pthread_mutex_lock(&trackstate_trains_mutex); @@ -902,13 +902,13 @@ void bidib_state_bm_speed(t_bidib_dcc_address dcc_address, uint8_t speedl, uint8 dcc_address.addrl, dcc_address.addrh); } pthread_mutex_unlock(&trackstate_trains_mutex); - pthread_rwlock_unlock(&bidib_state_trains_rwlock); + pthread_rwlock_unlock(&bidib_trains_rwlock); } void bidib_state_bm_dyn_state(t_bidib_dcc_address dcc_address, uint8_t dyn_num, uint8_t value, unsigned int action_id) { // For bidib_state_get_train_state_ref_by_dccaddr - pthread_rwlock_rdlock(&bidib_state_trains_rwlock); + pthread_rwlock_rdlock(&bidib_trains_rwlock); // For bidib_state_get_train_state_ref_by_dccaddr (devnote: write) pthread_mutex_lock(&trackstate_trains_mutex); @@ -962,7 +962,7 @@ void bidib_state_bm_dyn_state(t_bidib_dcc_address dcc_address, uint8_t dyn_num, dcc_address.addrl, dcc_address.addrh); } pthread_mutex_unlock(&trackstate_trains_mutex); - pthread_rwlock_unlock(&bidib_state_trains_rwlock); + pthread_rwlock_unlock(&bidib_trains_rwlock); } void bidib_state_boost_diagnostic(t_bidib_node_address node_address, uint8_t length, diff --git a/src/state/bidib_state_setter_intern.h b/src/state/bidib_state_setter_intern.h index cde5ebe..1ae763a 100644 --- a/src/state/bidib_state_setter_intern.h +++ b/src/state/bidib_state_setter_intern.h @@ -108,7 +108,7 @@ void bidib_state_cs_drive_ack(t_bidib_dcc_address dcc_address, uint8_t ack, /** * Sets the ack info for an dcc accessory. * Shall only be called with trackstate_accessories_mutex acquired, - * and bidib_state_boards_rwlock >= read lock acquired. + * and bidib_boards_rwlock >= read lock acquired. * * @param node_address the node address of the board. * @param dcc_address the dcc address of the accessory. @@ -119,7 +119,7 @@ void bidib_state_cs_accessory_ack(t_bidib_node_address node_address, /** * Sets the reported info about a manual train drive operation. - * Shall only be called with bidib_state_trains_rwlock >= read acquired. + * Shall only be called with bidib_trains_rwlock >= read acquired. * Note: uses trackstate_trains_mutex locally. * * @param params the parameters for the drive command. @@ -129,7 +129,7 @@ void bidib_state_cs_drive(t_bidib_cs_drive_mod params); /** * Sets the reported info about manual dcc accessory operation. * Shall only be called with trackstate_accessories_mutex acquired, - * and with bidib_state_boards_rwlock >= read acquired. + * and with bidib_boards_rwlock >= read acquired. * * @param node_address the node address of the board. * @param dcc_address the dcc address of the accessory. @@ -141,7 +141,7 @@ void bidib_state_cs_accessory_manual(t_bidib_node_address node_address, /** * Sets the new state for a dcc accessory. * Shall only be called with trackstate_accessories_mutex acquired, - * and with bidib_state_boards_rwlock >= read acquired. + * and with bidib_boards_rwlock >= read acquired. * * @param node_address the node address of the board. * @param params the parameters for the dcc accessory. diff --git a/src/transmission/bidib_transmission_receive.c b/src/transmission/bidib_transmission_receive.c index 7438510..6a61e34 100644 --- a/src/transmission/bidib_transmission_receive.c +++ b/src/transmission/bidib_transmission_receive.c @@ -218,7 +218,7 @@ static void bidib_log_received_message(const uint8_t *const addr_stack, uint8_t syslog_libbidib(LOG_DEBUG, "Message bytes: %s", hex_string); } -// Shall only be called with bidib_state_boards_rwlock >= read acquired. +// Shall only be called with bidib_boards_rwlock >= read acquired. static void bidib_log_sys_error(const uint8_t *const message, t_bidib_node_address node_address, unsigned int action_id) { @@ -254,7 +254,7 @@ static void bidib_log_sys_error(const uint8_t *const message, g_string_free(fault_name, TRUE); } -// Shall only be called with bidib_state_boards_rwlock >= read acquired. +// Shall only be called with bidib_boards_rwlock >= read acquired. static void bidib_log_boost_stat_error(const uint8_t *const message, t_bidib_node_address node_address, unsigned int action_id) { @@ -274,7 +274,7 @@ static void bidib_log_boost_stat_error(const uint8_t *const message, g_string_free(fault_name, TRUE); } -// Shall only be called with bidib_state_boards_rwlock >= read acquired. +// Shall only be called with bidib_boards_rwlock >= read acquired. static void bidib_log_boost_stat_okay(const uint8_t *const message, t_bidib_node_address node_address, unsigned int action_id) { @@ -380,10 +380,10 @@ void bidib_handle_received_message(uint8_t *message, uint8_t type, dcc_address.addrh = message[data_index + 1]; // Both for bidib_state_cs_accessory_ack (devnote: write for first) pthread_mutex_lock(&trackstate_accessories_mutex); - pthread_rwlock_rdlock(&bidib_state_boards_rwlock); + pthread_rwlock_rdlock(&bidib_boards_rwlock); bidib_state_cs_accessory_ack(node_address, dcc_address, message[data_index + 2]); - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); pthread_mutex_unlock(&trackstate_accessories_mutex); free(message); break; @@ -401,9 +401,9 @@ void bidib_handle_received_message(uint8_t *message, uint8_t type, cs_drive_params.function2 = message[data_index + 6]; cs_drive_params.function3 = message[data_index + 7]; cs_drive_params.function4 = message[data_index + 8]; - pthread_rwlock_wrlock(&bidib_state_trains_rwlock); + pthread_rwlock_wrlock(&bidib_trains_rwlock); bidib_state_cs_drive(cs_drive_params); - pthread_rwlock_unlock(&bidib_state_trains_rwlock); + pthread_rwlock_unlock(&bidib_trains_rwlock); free(message); break; case MSG_CS_ACCESSORY_MANUAL: @@ -414,9 +414,9 @@ void bidib_handle_received_message(uint8_t *message, uint8_t type, dcc_address.addrh = message[data_index + 1]; // Both for bidib_state_cs_accessory_manual (devnote: write for first) pthread_mutex_lock(&trackstate_accessories_mutex); - pthread_rwlock_rdlock(&bidib_state_boards_rwlock); + pthread_rwlock_rdlock(&bidib_boards_rwlock); bidib_state_cs_accessory_manual(node_address, dcc_address, message[data_index + 2]); - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); pthread_mutex_unlock(&trackstate_accessories_mutex); free(message); break; @@ -443,10 +443,10 @@ void bidib_handle_received_message(uint8_t *message, uint8_t type, bidib_log_received_message(addr_stack, seqnum, type, LOG_INFO, message, action_id); bidib_state_bm_occ(node_address, message[data_index], true); - pthread_rwlock_rdlock(&bidib_state_boards_rwlock); + pthread_rwlock_rdlock(&bidib_boards_rwlock); board = bidib_state_get_board_ref_by_nodeaddr(node_address); secack_on = board != NULL && board->secack_on; - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); if (secack_on) { bidib_send_bm_mirror_occ(node_address, message[data_index], 0); bidib_flush(); @@ -459,10 +459,10 @@ void bidib_handle_received_message(uint8_t *message, uint8_t type, bidib_log_received_message(addr_stack, seqnum, type, LOG_DEBUG, message, action_id); bidib_state_bm_occ(node_address, message[data_index], false); - pthread_rwlock_rdlock(&bidib_state_boards_rwlock); + pthread_rwlock_rdlock(&bidib_boards_rwlock); board = bidib_state_get_board_ref_by_nodeaddr(node_address); secack_on = board != NULL && board->secack_on; - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); if (secack_on) { bidib_send_bm_mirror_free(node_address, message[data_index], 0); bidib_flush(); @@ -475,10 +475,10 @@ void bidib_handle_received_message(uint8_t *message, uint8_t type, message, action_id); bidib_state_bm_multiple(node_address, message[data_index], message[data_index + 1], &message[data_index + 2]); - pthread_rwlock_rdlock(&bidib_state_boards_rwlock); + pthread_rwlock_rdlock(&bidib_boards_rwlock); board = bidib_state_get_board_ref_by_nodeaddr(node_address); secack_on = board != NULL && board->secack_on; - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); if (secack_on) { bidib_send_bm_mirror_multiple(node_address, message[data_index], message[data_index + 1], &message[data_index + 2], 0); @@ -582,16 +582,16 @@ void bidib_handle_received_message(uint8_t *message, uint8_t type, // add to error queue bidib_log_received_message(addr_stack, seqnum, type, LOG_ERR, message, action_id); - pthread_rwlock_rdlock(&bidib_state_boards_rwlock); + pthread_rwlock_rdlock(&bidib_boards_rwlock); bidib_log_boost_stat_error(message, node_address, action_id); - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); bidib_uplink_error_queue_add(message, type, addr_stack); } else { bidib_log_received_message(addr_stack, seqnum, type, LOG_DEBUG, message, action_id); - pthread_rwlock_rdlock(&bidib_state_boards_rwlock); + pthread_rwlock_rdlock(&bidib_boards_rwlock); bidib_log_boost_stat_okay(message, node_address, action_id); - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); free(message); } break; @@ -622,9 +622,9 @@ void bidib_handle_received_message(uint8_t *message, uint8_t type, // add to error message queue bidib_log_received_message(addr_stack, seqnum, type, LOG_DEBUG, message, action_id); - pthread_rwlock_rdlock(&bidib_state_boards_rwlock); + pthread_rwlock_rdlock(&bidib_boards_rwlock); bidib_log_sys_error(message, node_address, action_id); - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); bidib_uplink_error_queue_add(message, type, addr_stack); break; case MSG_NODE_NA: @@ -639,10 +639,10 @@ void bidib_handle_received_message(uint8_t *message, uint8_t type, // add to message queue bidib_log_received_message(addr_stack, seqnum, type, LOG_INFO, message, action_id); - pthread_rwlock_rdlock(&bidib_state_boards_rwlock); + pthread_rwlock_rdlock(&bidib_boards_rwlock); board = bidib_state_get_board_ref_by_nodeaddr(node_address); secack_on = board != NULL && board->secack_on; - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); if (secack_on) { bidib_send_msg_bm_mirror_position(node_address, message[data_index], message[data_index + 1], diff --git a/test/unit/bidib_highlevel_message_tests.c b/test/unit/bidib_highlevel_message_tests.c index e074699..4bc445c 100644 --- a/test/unit/bidib_highlevel_message_tests.c +++ b/test/unit/bidib_highlevel_message_tests.c @@ -60,7 +60,7 @@ static void write_bytes(uint8_t* msg, int32_t len) { // Assume that the system receives a response to its request. static void board_receives_response(const uint8_t response_type) { - pthread_rwlock_wrlock(&bidib_state_boards_rwlock); + pthread_rwlock_wrlock(&bidib_boards_rwlock); t_bidib_board *board_i; for (size_t i = 0; i < bidib_boards->len; i++) { board_i = &g_array_index(bidib_boards, t_bidib_board, i); @@ -72,16 +72,16 @@ static void board_receives_response(const uint8_t response_type) { 0x00 }; bidib_node_state_update(addr_stack, response_type); - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); return; } } - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); } static void set_all_boards_and_trains_connected(void) { // For accessing bidib_boards - pthread_rwlock_wrlock(&bidib_state_boards_rwlock); + pthread_rwlock_wrlock(&bidib_boards_rwlock); t_bidib_board *board_i; for (size_t i = 0; i < bidib_boards->len; i++) { board_i = &g_array_index(bidib_boards, t_bidib_board, i); @@ -89,7 +89,7 @@ static void set_all_boards_and_trains_connected(void) { board_i->connected = true; } } - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); // For bidib_state_get_train_state_ref (devnote: write) pthread_mutex_lock(&trackstate_trains_mutex); t_bidib_train_state_intern *train_state = bidib_state_get_train_state_ref("train1"); diff --git a/test/unit/bidib_parallel_tests.c b/test/unit/bidib_parallel_tests.c index 88d2e54..6d58c1b 100644 --- a/test/unit/bidib_parallel_tests.c +++ b/test/unit/bidib_parallel_tests.c @@ -62,7 +62,7 @@ static void write_bytes(uint8_t* msg, int32_t len) { } static void set_all_boards_and_trains_connected(void) { - pthread_rwlock_wrlock(&bidib_state_boards_rwlock); + pthread_rwlock_wrlock(&bidib_boards_rwlock); t_bidib_board *board_i; for (size_t i = 0; i < bidib_boards->len; i++) { board_i = &g_array_index(bidib_boards, t_bidib_board, i); @@ -70,7 +70,7 @@ static void set_all_boards_and_trains_connected(void) { board_i->connected = true; } } - pthread_rwlock_unlock(&bidib_state_boards_rwlock); + pthread_rwlock_unlock(&bidib_boards_rwlock); // For bidib_state_get_train_state_ref (devnote: write) pthread_mutex_lock(&trackstate_trains_mutex);