aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2022-02-10 11:52:34 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2022-02-10 11:52:34 +0200
commitdd25960e27d2f127e05d9f992eb577bc20e395ab (patch)
tree9a90b6f0a37081e3dbeacdbbf6439d5d5af5e71a
parentafe22af6ad346c653ed02109835e88348f4ecf5b (diff)
Make few global types separately constructible/initializable
-rw-r--r--libbuild2/build/script/parser.test.cxx2
-rw-r--r--libbuild2/context.hxx14
-rw-r--r--libbuild2/file-cache.hxx7
-rw-r--r--libbuild2/file-cache.ixx8
-rw-r--r--libbuild2/function.test.cxx2
-rw-r--r--libbuild2/test/script/parser.test.cxx2
-rw-r--r--tests/libbuild2/driver.cxx2
7 files changed, 29 insertions, 8 deletions
diff --git a/libbuild2/build/script/parser.test.cxx b/libbuild2/build/script/parser.test.cxx
index 4089efa..63d41ff 100644
--- a/libbuild2/build/script/parser.test.cxx
+++ b/libbuild2/build/script/parser.test.cxx
@@ -182,7 +182,7 @@ namespace build2
//
scheduler sched (1);
global_mutexes mutexes (1);
- file_cache fcache;
+ file_cache fcache (true);
context ctx (sched, mutexes, fcache);
try
diff --git a/libbuild2/context.hxx b/libbuild2/context.hxx
index c4d85c9..9df7a88 100644
--- a/libbuild2/context.hxx
+++ b/libbuild2/context.hxx
@@ -94,8 +94,18 @@ namespace build2
explicit
global_mutexes (size_t vc)
- : variable_cache_size (vc),
- variable_cache (new shared_mutex[variable_cache_size]) {}
+ {
+ init (vc);
+ }
+
+ global_mutexes () = default; // Create uninitialized instance.
+
+ void
+ init (size_t vc)
+ {
+ variable_cache_size = vc;
+ variable_cache.reset (new shared_mutex[vc]);
+ }
};
// A build context encapsulates the state of a build. It is possible to have
diff --git a/libbuild2/file-cache.hxx b/libbuild2/file-cache.hxx
index d6904ed..d210685 100644
--- a/libbuild2/file-cache.hxx
+++ b/libbuild2/file-cache.hxx
@@ -92,7 +92,12 @@ namespace build2
// to the noop implementation.
//
explicit
- file_cache (bool compress = true);
+ file_cache (bool compress);
+
+ file_cache () = default; // Create uninitialized instance.
+
+ void
+ init (bool compress);
class entry;
diff --git a/libbuild2/file-cache.ixx b/libbuild2/file-cache.ixx
index 8385c90..b4773e7 100644
--- a/libbuild2/file-cache.ixx
+++ b/libbuild2/file-cache.ixx
@@ -173,9 +173,15 @@ namespace build2
: string ();
}
+ inline void file_cache::
+ init (bool compress)
+ {
+ compress_ = compress;
+ }
+
inline file_cache::
file_cache (bool compress)
- : compress_ (compress)
{
+ init (compress);
}
}
diff --git a/libbuild2/function.test.cxx b/libbuild2/function.test.cxx
index b09e4f7..0b3c922 100644
--- a/libbuild2/function.test.cxx
+++ b/libbuild2/function.test.cxx
@@ -50,7 +50,7 @@ namespace build2
//
scheduler sched (1);
global_mutexes mutexes (1);
- file_cache fcache;
+ file_cache fcache (true);
context ctx (sched, mutexes, fcache);
auto& functions (ctx.functions);
diff --git a/libbuild2/test/script/parser.test.cxx b/libbuild2/test/script/parser.test.cxx
index 47d56ce..eb4a59b 100644
--- a/libbuild2/test/script/parser.test.cxx
+++ b/libbuild2/test/script/parser.test.cxx
@@ -168,7 +168,7 @@ namespace build2
//
scheduler sched (1);
global_mutexes mutexes (1);
- file_cache fcache;
+ file_cache fcache (true);
context ctx (sched, mutexes, fcache);
bool scope (false);
diff --git a/tests/libbuild2/driver.cxx b/tests/libbuild2/driver.cxx
index 9a8db9e..7cb194d 100644
--- a/tests/libbuild2/driver.cxx
+++ b/tests/libbuild2/driver.cxx
@@ -41,7 +41,7 @@ main (int, char* argv[])
//
scheduler sched (1);
global_mutexes mutexes (1);
- file_cache fcache;
+ file_cache fcache (true);
context ctx (sched, mutexes, fcache);
return 0;