Skip to content

Commit 993bfa1

Browse files
committed
chore: tidy up config construction
1 parent c740a9a commit 993bfa1

File tree

7 files changed

+55
-24
lines changed

7 files changed

+55
-24
lines changed

include/mrdox/Config.hpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
#include <mrdox/Platform.hpp>
1616
#include <mrdox/Support/Error.hpp>
17-
#include <mrdox/Support/Thread.hpp>
1817
#include <functional>
1918
#include <memory>
2019
#include <string>
@@ -26,7 +25,7 @@
2625
namespace clang {
2726
namespace mrdox {
2827

29-
class ConfigImpl;
28+
class ThreadPool;
3029

3130
/** Configuration used to generate the Corpus and Docs
3231

include/mrdox/Support/Thread.hpp

+16
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,29 @@ class MRDOX_VISIBLE
4848
MRDOX_DECL
4949
~ThreadPool();
5050

51+
/** Constructor.
52+
53+
Default constructed thread pools may only
54+
be reset or destroyed.
55+
*/
56+
MRDOX_DECL
57+
explicit
58+
ThreadPool();
59+
5160
/** Constructor.
5261
*/
5362
MRDOX_DECL
5463
explicit
5564
ThreadPool(
5665
unsigned concurrency);
5766

67+
/** Reset the pool to the specified concurrency.
68+
*/
69+
MRDOX_DECL
70+
void
71+
reset(
72+
unsigned concurrency);
73+
5874
/** Return the number of threads in the pool.
5975
*/
6076
MRDOX_DECL

source/-adoc/AdocPagesBuilder.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <mrdox/Corpus.hpp>
1616
#include <mrdox/MetadataFwd.hpp>
1717
#include <mrdox/Support/Error.hpp>
18+
#include <mrdox/Support/Thread.hpp>
1819
#include <llvm/ADT/SmallString.h>
1920

2021
namespace clang {

source/-bitcode/BitcodeGenerator.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "Support/SafeNames.hpp"
1515
#include "AST/Bitcode.hpp"
1616
#include <mrdox/Support/Report.hpp>
17+
#include <mrdox/Support/Thread.hpp>
1718
#include <mrdox/Metadata.hpp>
1819

1920
namespace clang {

source/ConfigImpl.cpp

+23-18
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,8 @@ struct llvm::yaml::MappingTraits<
6767
namespace clang {
6868
namespace mrdox {
6969

70-
Error
7170
ConfigImpl::
72-
construct(
71+
ConfigImpl(
7372
llvm::StringRef workingDir_,
7473
llvm::StringRef configYaml_,
7574
llvm::StringRef extraYaml_)
@@ -78,7 +77,7 @@ construct(
7877
namespace path = llvm::sys::path;
7978

8079
if(! files::isAbsolute(workingDir_))
81-
return Error("path \"{}\" is not absolute", workingDir_);
80+
throw Error("path \"{}\" is not absolute", workingDir_);
8281
workingDir = files::makeDirsy(files::normalizePath(workingDir_));
8382
configYaml = configYaml_;
8483
extraYaml = extraYaml_;
@@ -89,14 +88,14 @@ construct(
8988
yin.setAllowUnknownKeys(true);
9089
yin >> *this;
9190
if(auto ec = yin.error())
92-
return Error(ec);
91+
throw Error(ec);
9392
}
9493
{
9594
llvm::yaml::Input yin(extraYaml, this, yamlDiagnostic);
9695
yin.setAllowUnknownKeys(true);
9796
yin >> *this;
9897
if(auto ec = yin.error())
99-
return Error(ec);
98+
throw Error(ec);
10099
}
101100

102101
// Post-process as needed
@@ -112,13 +111,7 @@ construct(
112111
name = files::makePosixStyle(
113112
files::makeAbsolute(name, workingDir));
114113

115-
return Error::success();
116-
}
117-
118-
ConfigImpl::
119-
ConfigImpl()
120-
: threadPool_(0)
121-
{
114+
threadPool_.reset(concurrency);
122115
}
123116

124117
//------------------------------------------------
@@ -174,10 +167,16 @@ createConfigFromYAML(
174167
llvm::StringRef configYaml,
175168
llvm::StringRef extraYaml)
176169
{
177-
auto config = std::make_shared<ConfigImpl>();
178-
if(auto err = config->construct(workingDir, configYaml, extraYaml))
170+
try
171+
{
172+
auto config = std::make_shared<ConfigImpl>(
173+
workingDir, configYaml, extraYaml);
174+
return config;
175+
}
176+
catch(Error err)
177+
{
179178
return err;
180-
return config;
179+
}
181180
}
182181

183182
Expected<std::shared_ptr<ConfigImpl const>>
@@ -202,10 +201,16 @@ loadConfigFile(
202201
auto workingDir = files::getParentDir(*absPath);
203202

204203
// attempt to create the config
205-
auto config = std::make_shared<ConfigImpl>();
206-
if(auto err = config->construct(workingDir, *text, extraYaml))
204+
try
205+
{
206+
auto config = std::make_shared<ConfigImpl>(
207+
workingDir, *text, extraYaml);
208+
return config;
209+
}
210+
catch(Error err)
211+
{
207212
return err;
208-
return config;
213+
}
209214
}
210215

211216
} // mrdox

source/ConfigImpl.hpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,12 @@ class ConfigImpl
5858
template<class T>
5959
friend struct llvm::yaml::MappingTraits;
6060

61-
Error construct(
61+
public:
62+
ConfigImpl(
6263
llvm::StringRef workingDir,
6364
llvm::StringRef configYaml,
6465
llvm::StringRef extraYaml);
6566

66-
public:
67-
ConfigImpl();
68-
6967
ThreadPool&
7068
threadPool() const noexcept override
7169
{

source/Support/Thread.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,20 @@ ThreadPool::
2727
{
2828
}
2929

30+
ThreadPool::
31+
ThreadPool() = default;
32+
3033
ThreadPool::
3134
ThreadPool(
3235
unsigned concurrency)
36+
{
37+
reset(concurrency);
38+
}
39+
40+
void
41+
ThreadPool::
42+
reset(
43+
unsigned concurrency)
3344
{
3445
llvm::ThreadPoolStrategy S;
3546
S.ThreadsRequested = concurrency;

0 commit comments

Comments
 (0)