This is an automated email from the ASF dual-hosted git repository.

bmahler pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mesos.git


The following commit(s) were added to refs/heads/master by this push:
     new 67fbfe0c4 [cgroups2] Convert cgroups2::read/write to template 
functions.
67fbfe0c4 is described below

commit 67fbfe0c4fc37548399378cd4e89d6bdd2b03335
Author: Devin Leamy <dle...@twitter.com>
AuthorDate: Tue Mar 19 18:04:42 2024 -0400

    [cgroups2] Convert cgroups2::read/write to template functions.
    
    To allow overloading of `read` by return type alone, we define
    `cgroups::read` as a template function. For consistency, we do
    the same for `cgroups::write`.
    
    This closes #526
---
 src/linux/cgroups2.cpp | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/src/linux/cgroups2.cpp b/src/linux/cgroups2.cpp
index e599c8c62..88060e02b 100644
--- a/src/linux/cgroups2.cpp
+++ b/src/linux/cgroups2.cpp
@@ -44,14 +44,16 @@ const string FILE_SYSTEM = "cgroup2";
 // Mount point for the cgroups2 file system.
 const string MOUNT_POINT = "/sys/fs/cgroup";
 
-// Forward declaration.
-Try<string> read(const string& cgroup, const string& control);
 
-// Forward declaration.
+template <typename T>
+Try<T> read(const string& cgroup, const string& control);
+
+template <typename T>
 Try<Nothing> write(
     const string& cgroup,
     const string& control,
-    const string& value);
+    const T& value);
+
 
 namespace control {
 
@@ -141,16 +143,18 @@ std::ostream& operator<<(std::ostream& stream, const 
State& state)
 } // namespace control {
 
 
+template <>
 Try<string> read(const string& cgroup, const string& control)
 {
   return os::read(path::join(cgroups2::MOUNT_POINT, cgroup, control));
 }
 
 
+template <>
 Try<Nothing> write(
-  const string& cgroup,
-  const string& control,
-  const string& value)
+    const string& cgroup,
+    const string& control,
+    const string& value)
 {
   return os::write(path::join(cgroups2::MOUNT_POINT, cgroup, control), value);
 }
@@ -328,7 +332,8 @@ namespace controllers {
 
 Try<set<string>> available(const string& cgroup)
 {
-  Try<string> contents = cgroups2::read(cgroup, 
cgroups2::control::CONTROLLERS);
+  Try<string> contents =
+    cgroups2::read<string>(cgroup, cgroups2::control::CONTROLLERS);
 
   if (contents.isError()) {
     return Error("Failed to read cgroup.controllers in '" + cgroup + "': "
@@ -345,7 +350,7 @@ Try<set<string>> available(const string& cgroup)
 Try<Nothing> enable(const string& cgroup, const vector<string>& controllers)
 {
   Try<string> contents =
-    cgroups2::read(cgroup, cgroups2::control::SUBTREE_CONTROLLERS);
+    cgroups2::read<string>(cgroup, cgroups2::control::SUBTREE_CONTROLLERS);
 
   if (contents.isError()) {
     return Error(contents.error());
@@ -364,7 +369,7 @@ Try<Nothing> enable(const string& cgroup, const 
vector<string>& controllers)
 Try<set<string>> enabled(const string& cgroup)
 {
   Try<string> contents =
-    cgroups2::read(cgroup, cgroups2::control::SUBTREE_CONTROLLERS);
+    cgroups2::read<string>(cgroup, cgroups2::control::SUBTREE_CONTROLLERS);
   if (contents.isError()) {
     return Error("Failed to read 'cgroup.subtree_control' in '" + cgroup + "'"
                  ": " + contents.error());

Reply via email to