Skip to content

Commit 9a8ba9e

Browse files
authored
Merge pull request #866 from denravonska/data-race-fixes
Data race fixes
2 parents 6b526b0 + cf3b109 commit 9a8ba9e

File tree

7 files changed

+15
-41
lines changed

7 files changed

+15
-41
lines changed

src/global_objects_noui.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
extern int nBoincUtilization;
88
extern std::string sRegVer;
99
extern int nRegVersion;
10-
extern bool bCPIDsLoaded;
11-
extern bool bProjectsInitialized;
1210
extern bool bNetAveragesLoaded;
1311
extern bool bForceUpdate;
1412
extern bool bGlobalcomInitialized;

src/init.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ void BusyWaitForTally_retired();
2727
void TallyNetworkAverages_v9();
2828
extern void ThreadAppInit2(void* parg);
2929

30-
void LoadCPIDsInBackground();
30+
void LoadCPIDs();
3131
bool IsConfigFileEmpty();
3232

3333
#ifndef WIN32
@@ -990,8 +990,7 @@ bool AppInit2(ThreadHandlerPtr threads)
990990
uiInterface.InitMessage(_("Compute Neural Network Hashes..."));
991991
ComputeNeuralNetworkSupermajorityHashes();
992992

993-
printf("Starting CPID thread...");
994-
LoadCPIDsInBackground(); //This calls HarvesCPIDs(true)
993+
LoadCPIDs();
995994

996995
uiInterface.InitMessage(_("Finding first applicable Research Project..."));
997996

src/main.cpp

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ int64_t nLastPing = 0;
149149
int64_t nLastAskedForBlocks = 0;
150150
int64_t nBootup = 0;
151151
int64_t nLastLoadAdminMessages = 0;
152-
int64_t nCPIDsLoaded = 0;
153152
int64_t nLastGRCtallied = 0;
154153
int64_t nLastCleaned = 0;
155154

@@ -262,7 +261,6 @@ bool bGridcoinGUILoaded = false;
262261
extern double LederstrumpfMagnitude2(double Magnitude, int64_t locktime);
263262

264263
extern void WriteAppCache(std::string key, std::string value);
265-
extern void LoadCPIDsInBackground();
266264

267265
extern void ThreadCPIDs();
268266
extern void GetGlobalStatus();
@@ -649,14 +647,13 @@ MiningCPID GetNextProject(bool bForce)
649647

650648

651649

652-
if ( (IsInitialBlockDownload() || !bCPIDsLoaded) && !bForce)
650+
if (IsInitialBlockDownload() && !bForce)
653651
{
654-
if (LessVerbose(100)) printf("CPUMiner: Gridcoin is downloading blocks Or CPIDs are not yet loaded...");
655-
MilliSleep(1);
656-
return GlobalCPUMiningCPID;
652+
if (LessVerbose(100)) printf("CPUMiner: Gridcoin is downloading blocks Or CPIDs are not yet loaded...");
653+
MilliSleep(1);
654+
return GlobalCPUMiningCPID;
657655
}
658656

659-
660657
try
661658
{
662659

@@ -7715,33 +7712,15 @@ void HarvestCPIDs(bool cleardata)
77157712
{
77167713
printf("Error while harvesting CPIDs 2.\r\n");
77177714
}
7718-
7719-
7720-
77217715
}
77227716

7723-
7724-
7725-
void ThreadCPIDs()
7717+
void LoadCPIDs()
77267718
{
7727-
RenameThread("grc-cpids");
7728-
bCPIDsLoaded = false;
7719+
printf("Load CPID");
77297720
HarvestCPIDs(true);
7730-
bCPIDsLoaded = true;
7731-
//CreditCheck(GlobalCPUMiningCPID.cpid,false);
77327721
printf("Getting first project");
77337722
GetNextProject(false);
77347723
printf("Finished getting first project");
7735-
bProjectsInitialized = true;
7736-
}
7737-
7738-
7739-
void LoadCPIDsInBackground()
7740-
{
7741-
if (IsLockTimeWithinMinutes(nCPIDsLoaded,10)) return;
7742-
nCPIDsLoaded = GetAdjustedTime();
7743-
cpidThreads = new boost::thread_group();
7744-
cpidThreads->create_thread(boost::bind(&ThreadCPIDs));
77457724
}
77467725

77477726
StructCPID GetStructCPID()

src/miner.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,6 @@ void StakeMiner(CWallet *pwallet)
851851

852852
while (!fShutdown)
853853
{
854-
855854
//wait for next round
856855
MilliSleep(nMinerSleep);
857856

@@ -880,6 +879,10 @@ void StakeMiner(CWallet *pwallet)
880879
continue;
881880
}
882881

882+
// Lock main lock since GetNextProject and subsequent calls
883+
// require the state to be static.
884+
LOCK(cs_main);
885+
883886
GetNextProject(true);
884887

885888
// * Create a bare block
@@ -920,7 +923,6 @@ void StakeMiner(CWallet *pwallet)
920923
}
921924

922925
// * delegate to ProcessBlock
923-
LOCK(cs_main);
924926
if (!ProcessBlock(NULL, &StakeBlock, true))
925927
{
926928
{ LOCK(MinerStatus.lock);

src/net.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1723,10 +1723,6 @@ void static ThreadStakeMiner(void* parg)
17231723

17241724
if (fDebug10) printf("ThreadStakeMiner started\n");
17251725
CWallet* pwallet = (CWallet*)parg;
1726-
while (!bCPIDsLoaded)
1727-
{
1728-
MilliSleep(100);
1729-
}
17301726
try
17311727
{
17321728
StakeMiner(pwallet);

src/rpcblockchain.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include <fstream>
2323
#include <algorithm>
2424

25+
26+
bool TallyResearchAverages_v9();
2527
using namespace json_spirit;
2628
using namespace std;
2729
extern std::string YesNo(bool bin);
@@ -2046,7 +2048,7 @@ Value execute(const Array& params, bool fHelp)
20462048
else if (sItem == "tally")
20472049
{
20482050
bNetAveragesLoaded_retired = false;
2049-
TallyResearchAverages_retired(true);
2051+
TallyResearchAverages_v9();
20502052
entry.push_back(Pair("Tally Network Averages",1));
20512053
results.push_back(entry);
20522054
}

src/rpcmining.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ int64_t GetCoinYearReward(int64_t nTime);
2020

2121
double GRCMagnitudeUnit(int64_t locktime);
2222
std::string qtGetNeuralHash(std::string data);
23-
bool bCPIDsLoaded;
24-
bool bProjectsInitialized;
2523
std::string GetNeuralNetworkSupermajorityHash(double& out_popularity);
2624

2725
int64_t GetRSAWeightByCPID(std::string cpid);

0 commit comments

Comments
 (0)