Skip to content

Commit

Permalink
Revert "CODE: Add further mutexes to attempt to resolve data race iss…
Browse files Browse the repository at this point in the history
…ues"

This reverts commit a807186.
  • Loading branch information
jamespetts committed Jun 23, 2024
1 parent 5e02440 commit 2e76934
Show file tree
Hide file tree
Showing 11 changed files with 8 additions and 114 deletions.
1 change: 1 addition & 0 deletions bauer/hausbauer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,7 @@ gebaeude_t *hausbauer_t::build_station_extension_depot(player_t *player, koord3d
gr->obj_remove(zeiger);
zeiger->set_flag(obj_t::not_on_map);
}

gr->obj_add(gb);
parapet_t::hide_all(gr->get_pos());

Expand Down
2 changes: 1 addition & 1 deletion bauer/pier_builder.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* This file is part of the Simutrans-Extended project under the Artistic License.
* (see LICENSE.txt)
*/
Expand Down
1 change: 1 addition & 0 deletions bauer/tree_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ bool tree_builder_t::plant_tree_on_coordinate(koord pos, const tree_desc_t *desc
b->geburt = welt->get_current_month() - simrand(baum_t::AGE_LIMIT-1);
b->calc_off( welt->lookup( b->get_pos() )->get_grund_hang() );
}

gr->obj_add( b );
return true; //tree was planted - currently unused value is not checked
}
Expand Down
1 change: 0 additions & 1 deletion boden/wege/weg.h
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,6 @@ class weg_t : public obj_no_info_t
waytype_t get_waytype() const OVERRIDE { return wtyp; }

inline bool is_rail_type() const { return wtyp == track_wt || wtyp == maglev_wt || wtyp == tram_wt || wtyp == narrowgauge_wt || wtyp == monorail_wt; }
inline bool is_rail_type_or_air() const { return wtyp == track_wt || wtyp == maglev_wt || wtyp == tram_wt || wtyp == narrowgauge_wt || wtyp == monorail_wt || wtyp == air_wt; }

/**
* @return the object type.
Expand Down
2 changes: 1 addition & 1 deletion simconvoi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ void convoi_t::unreserve_route_range(route_range_specification range)
{
weg_t* const way = all_ways[i];
//schiene_t* const sch = obj_cast<schiene_t>(way);
schiene_t* const sch = way->is_rail_type_or_air() ? (schiene_t*)way : NULL;
schiene_t* const sch = way->is_rail_type() || way->get_waytype() == air_wt ? (schiene_t*)way : NULL;
if (sch && sch->get_reserved_convoi().get_id() == convoi_t::current_unreserver)
{
convoihandle_t ch;
Expand Down
13 changes: 1 addition & 12 deletions simfab.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1910,18 +1910,7 @@ void fabrik_t::smoke() const
const sint8 offsetx = ((rada->get_xy_off(rot).x) * OBJECT_OFFSET_STEPS) / 16;
const sint8 offsety = ((rada->get_xy_off(rot).y) * OBJECT_OFFSET_STEPS) / 16;
wolke_t* smoke = new wolke_t(gr->get_pos(), offsetx, offsety, rada->get_images());
#ifdef MULTI_THREAD
int can_get_lock = pthread_mutex_trylock(&karte_t::private_car_route_mutex);
#endif
if (!can_get_lock)
{
gr->obj_add(smoke);
#ifdef MULTI_THREAD
int error = pthread_mutex_unlock(&karte_t::private_car_route_mutex);
assert(error == 0);
(void)error;
#endif
}
gr->obj_add(smoke);
welt->sync_way_eyecandy.add(smoke);
}
// maybe sound?
Expand Down
10 changes: 0 additions & 10 deletions simplan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -237,17 +237,7 @@ void planquadrat_t::boden_ersetzen(grund_t *alt, grund_t *neu)
}
// transfer all objects
while( alt->get_top()>0 ) {
#ifdef MULTI_THREAD
int error = pthread_mutex_lock(&karte_t::private_car_route_mutex);
assert(error == 0);
(void)error;
#endif
neu->obj_add( alt->obj_remove_top() );
#ifdef MULTI_THREAD
error = pthread_mutex_unlock(&karte_t::private_car_route_mutex);
assert(error == 0);
(void)error;
#endif
}
delete alt;
}
Expand Down
1 change: 1 addition & 0 deletions simtool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7454,6 +7454,7 @@ const char *tool_build_roadsign_t::place_sign_intern( player_t *player, grund_t*
// Build signalboxes
const char* tool_signalbox_t::tool_signalbox_aux(player_t* player, koord3d pos, const building_desc_t* desc, sint64 cost)
{

karte_t::runway_info ri = welt->check_nearby_runways(pos.get_2d());
const uint8 height = welt->lookup_hgt(pos.get_2d());
if (pos.z >= height && ri.pos != koord::invalid && desc->get_allow_underground() != 1)
Expand Down
20 changes: 0 additions & 20 deletions simworld.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1316,17 +1316,7 @@ void karte_t::distribute_groundobjs_cities( settings_t const * const sets, sint1
const groundobj_desc_t *desc = groundobj_t::random_groundobj_for_climate( cl, gr->get_grund_hang() );
if(desc) {
queried = simrand(env_t::ground_object_probability*2-1, "karte_t::distribute_groundobjs_cities(), distributing groundobjs - 2nd instance");
#ifdef MULTI_THREAD
int error = pthread_mutex_lock(&karte_t::private_car_route_mutex);
assert(error == 0);
(void)error;
#endif
gr->obj_add( new groundobj_t( gr->get_pos(), desc ) );
#ifdef MULTI_THREAD
error = pthread_mutex_unlock(&karte_t::private_car_route_mutex);
assert(error == 0);
(void)error;
#endif
}
}
}
Expand Down Expand Up @@ -1355,17 +1345,7 @@ DBG_DEBUG("karte_t::distribute_groundobjs_cities()","distributing movingobjs");
if( desc && ( desc->get_waytype() != water_wt || gr->get_hoehe() <= get_water_hgt_nocheck(k) ) ) {
if(desc->get_speed()!=0) {
queried = simrand(max_queried, "karte_t::distribute_groundobjs_cities()");
#ifdef MULTI_THREAD
int error = pthread_mutex_lock(&karte_t::private_car_route_mutex);
assert(error == 0);
(void)error;
#endif
gr->obj_add( new movingobj_t( gr->get_pos(), desc ) );
#ifdef MULTI_THREAD
error = pthread_mutex_unlock(&karte_t::private_car_route_mutex);
assert(error == 0);
(void)error;
#endif
}
}
}
Expand Down
10 changes: 0 additions & 10 deletions vehicle/pedestrian.cc
Original file line number Diff line number Diff line change
Expand Up @@ -311,17 +311,7 @@ void pedestrian_t::hop(grund_t *gr)
// no need to call enter_tile()

// if this fails, the target tile is full, but this should already have been checked in hop_check
#ifdef MULTI_THREAD
int error = pthread_mutex_lock(&karte_t::private_car_route_mutex);
assert(error == 0);
(void)error;
#endif
const bool ok = gr->obj_add(this);
#ifdef MULTI_THREAD
error = pthread_mutex_unlock(&karte_t::private_car_route_mutex);
assert(error == 0);
(void)error;
#endif
assert(ok); (void)ok;

// determine pos_next
Expand Down
61 changes: 2 additions & 59 deletions vehicle/vehicle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -228,31 +228,13 @@ void vehicle_base_t::leave_tile()
grund_t *gr2 = welt->lookup(pos_next);
if(cr) {
if(gr2==NULL || gr2==gr || !gr2->ist_uebergang() || cr->get_logic()!=gr2->find<crossing_t>(2)->get_logic()) {
#ifdef MULTI_THREAD
int error = pthread_mutex_lock(&karte_t::private_car_route_mutex);
assert(error == 0);
(void)error;
#endif
cr->release_crossing(this);
#ifdef MULTI_THREAD
error = pthread_mutex_unlock(&karte_t::private_car_route_mutex);
assert(error == 0);
(void)error;
#endif
}
} else {
dbg->warning("vehicle_base_t::leave_tile()", "No crossing found at %s", gr->get_pos().get_str());
}
}
#ifdef MULTI_THREAD
int error = 0;
if (!get_flag(not_on_map) && gr)
{
error = pthread_mutex_lock(&karte_t::private_car_route_mutex);
}
assert(error == 0);
(void)error;
#endif

// then remove from ground (or search whole map, if failed)
if(!get_flag(not_on_map) && (gr==NULL || !gr->obj_remove(this)) ) {

Expand Down Expand Up @@ -289,11 +271,6 @@ void vehicle_base_t::leave_tile()
dbg->error("vehicle_base_t::leave_tile()","'%s' %p was not found on any map square!",get_name(), this);
}
}
#ifdef MULTI_THREAD
error = pthread_mutex_unlock(&karte_t::private_car_route_mutex);
assert(error == 0);
(void)error;
#endif
gr = NULL;
}

Expand All @@ -305,20 +282,10 @@ void vehicle_base_t::enter_tile(grund_t* gr)
gr = welt->lookup_kartenboden(get_pos().get_2d());
set_pos( gr->get_pos() );
}
#ifdef MULTI_THREAD
int error = pthread_mutex_lock(&karte_t::private_car_route_mutex);
assert(error == 0);
(void)error;
#endif
if(!gr->obj_add(this))
{
dbg->error("vehicle_base_t::enter_tile()","'%s failed to be added to the object list", get_name());
}
#ifdef MULTI_THREAD
error = pthread_mutex_unlock(&karte_t::private_car_route_mutex);
assert(error == 0);
(void)error;
#endif
weg = gr->get_weg(get_waytype());
}

Expand Down Expand Up @@ -1759,17 +1726,7 @@ void vehicle_t::hop(grund_t* gr)
weg->wear_way(desc->get_way_wear_factor());
}
hop_count ++;
#ifdef MULTI_THREAD
int error = pthread_mutex_lock(&karte_t::private_car_route_mutex);
assert(error == 0);
(void)error;
#endif
gr->set_all_obj_dirty();
#ifdef MULTI_THREAD
error = pthread_mutex_unlock(&karte_t::private_car_route_mutex);
assert(error == 0);
(void)error;
#endif
}

/* Calculates the modified speed limit of the current way,
Expand Down Expand Up @@ -2085,13 +2042,7 @@ void vehicle_t::make_smoke() const
// only produce smoke when heavily accelerating or steam engine
if( (cnv->get_akt_speed() < (sint32)((cnv->get_vehicle_summary().max_sim_speed * 7u) >> 3) && (route_index < cnv->get_route_infos().get_count() - 4)) || desc->get_engine_type() == vehicle_desc_t::steam ) {
grund_t* const gr = welt->lookup( get_pos() );
#ifdef MULTI_THREAD
// We use trylock here as we do not want to block the thread for something that does is just "eye candy".
const int can_get_lock = pthread_mutex_trylock(&karte_t::private_car_route_mutex);
# else
const int can_get_lock = 0;
#endif
if( gr && !can_get_lock) {
if( gr ) {
wolke_t* const abgas = new wolke_t( get_pos(),
get_xoff() + ((dx * (sint16)((uint16)steps * OBJECT_OFFSET_STEPS)) >> VEHICLE_STEPS_PER_TILE_SHIFT),
get_yoff() + ((dy * (sint16)((uint16)steps * OBJECT_OFFSET_STEPS)) >> VEHICLE_STEPS_PER_TILE_SHIFT) + get_hoff(), desc->get_smoke() );
Expand All @@ -2103,14 +2054,6 @@ void vehicle_t::make_smoke() const
welt->sync_way_eyecandy.add( abgas );
}
}
#ifdef MULTI_THREAD
if (!can_get_lock)
{
int error = pthread_mutex_unlock(&karte_t::private_car_route_mutex);
assert(error == 0);
(void)error;
}
#endif
}
}
}
Expand Down

0 comments on commit 2e76934

Please sign in to comment.