[openrtm-commit:03304] r3270 - trunk/OpenRTM-aist/src/lib/coil/win32/coil
openrtm @ openrtm.org
openrtm @ openrtm.org
2018年 3月 28日 (水) 12:51:08 JST
Author: miyamoto
Date: 2018-03-28 12:51:07 +0900 (Wed, 28 Mar 2018)
New Revision: 3270
Added:
trunk/OpenRTM-aist/src/lib/coil/win32/coil/Affinity.cpp
trunk/OpenRTM-aist/src/lib/coil/win32/coil/Affinity.h
Modified:
trunk/OpenRTM-aist/src/lib/coil/win32/coil/Makefile.am
Log:
[merge] r3178-3180 have been merged from RELENG_1_2.
Copied: trunk/OpenRTM-aist/src/lib/coil/win32/coil/Affinity.cpp (from rev 3180, branches/RELENG_1_2/OpenRTM-aist/src/lib/coil/win32/coil/Affinity.cpp)
===================================================================
--- trunk/OpenRTM-aist/src/lib/coil/win32/coil/Affinity.cpp (rev 0)
+++ trunk/OpenRTM-aist/src/lib/coil/win32/coil/Affinity.cpp 2018-03-28 03:51:07 UTC (rev 3270)
@@ -0,0 +1,121 @@
+// -*- C++ -*-
+/*!
+ * @file Affinity.cpp
+ * @brief Processor affinity operation class
+ * @date $Date$
+ * @author Nobuhiko Miyamoto <n-miyamoto at aist.go.jp>
+ *
+ * Copyright (C) 2018
+ * Nobuhiko Miyamoto
+ * National Institute of
+ * Advanced Industrial Science and Technology (AIST), Japan
+ * All rights reserved.
+ *
+ * $Id$
+ *
+ */
+
+
+#include <windows.h>
+#include <coil/stringutil.h>
+#include <coil/Affinity.h>
+
+namespace coil
+{
+ DWORD listToCUPNUM(CpuMask &cpu_mask)
+ {
+ DWORD cpu_num = 0;
+ for(CpuMask::iterator itr = cpu_mask.begin(); itr != cpu_mask.end(); ++itr) {
+ DWORD_PTR p = 0x01 << (*itr);
+ cpu_num += p;
+ }
+ return cpu_num;
+ }
+ bool getProcCpuAffinity(CpuMask& cpu_mask)
+ {
+ DWORD cpu_num = listToCUPNUM(cpu_mask);
+ DWORD processMask, systemMask = 0;
+ HANDLE h = GetCurrentProcess();
+ BOOL success = GetProcessAffinityMask(h, &processMask, &systemMask);
+ if (success)
+ {
+ for (int i = 0; i < 32; i++)
+ {
+ if (processMask & (0x00000001 << i))
+ {
+ cpu_mask.push_back(i);
+ }
+ }
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ bool setProcCpuAffinity(std::vector<unsigned int> mask)
+ {
+ DWORD cpu_num = listToCUPNUM(mask);
+ HANDLE h = GetCurrentProcess();
+ BOOL success = SetProcessAffinityMask(h, cpu_num);
+ if (success)
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ bool setProcCpuAffinity(std::string cpu_mask)
+ {
+ coil::vstring tmp = coil::split(cpu_mask, ",", true);
+ CpuMask mask;
+ for (size_t i(0); i < tmp.size(); ++i)
+ {
+ int num;
+ if (coil::stringTo(num, tmp[i].c_str()))
+ {
+ mask.push_back(num);
+ }
+ }
+ return setProcCpuAffinity(mask);
+ }
+
+ bool getThreadCpuAffinity(CpuMask& cpu_mask)
+ {
+ return true;
+ }
+
+ bool setThreadCpuAffinity(std::vector<unsigned int> mask)
+ {
+ DWORD cpu_num = listToCUPNUM(mask);
+ HANDLE h = GetCurrentThread();
+ BOOL success = SetThreadAffinityMask(h, cpu_num);
+ if (success)
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ bool setThreadCpuAffinity(std::string cpu_mask)
+ {
+ coil::vstring tmp = coil::split(cpu_mask, ",", true);
+ CpuMask mask;
+ for (size_t i(0); i < tmp.size(); ++i)
+ {
+ int num;
+ if (coil::stringTo(num, tmp[i].c_str()))
+ {
+ mask.push_back(num);
+ }
+ }
+ return setThreadCpuAffinity(mask);
+ }
+}; // namespace coil
Copied: trunk/OpenRTM-aist/src/lib/coil/win32/coil/Affinity.h (from rev 3180, branches/RELENG_1_2/OpenRTM-aist/src/lib/coil/win32/coil/Affinity.h)
===================================================================
--- trunk/OpenRTM-aist/src/lib/coil/win32/coil/Affinity.h (rev 0)
+++ trunk/OpenRTM-aist/src/lib/coil/win32/coil/Affinity.h 2018-03-28 03:51:07 UTC (rev 3270)
@@ -0,0 +1,123 @@
+// -*- C++ -*-
+/*!
+ * @file Affinity.h
+ * @brief Processor affinity operation class
+ * @date $Date$
+ * @author Noriaki Ando <n-ando at aist.go.jp>
+ *
+ * Copyright (C) 2016
+ * Noriaki Ando
+ * National Institute of
+ * Advanced Industrial Science and Technology (AIST), Japan
+ * All rights reserved.
+ *
+ * $Id$
+ *
+ */
+
+#ifndef COIL_AFFINITY_H
+#define COIL_AFFINITY_H
+
+#include <string>
+#include <vector>
+#include <coil/Singleton.h>
+#include <coil/TimeValue.h>
+#include <coil/Mutex.h>
+#include <coil/Guard.h>
+
+
+namespace coil
+{
+ typedef std::vector<unsigned int> CpuMask;
+ /*!
+ * @if jp
+ * @brief プロセスのCPU affinityを取得する
+ * @prop cpu_mask 現在設定されている affinity が CPU IDの
+ * std::vector<unsigned int> で返される。
+ * @return True: 成功、False: 失敗
+ * @else
+ * @brief Getting current process CPU affinity
+ * @prop cpu_mask Current CPU affinity mask is returned as CPU ID in
+ * std::vector<unsigned int>.
+ * @return True: success, False: fail
+ * @endif
+ */
+ bool getProcCpuAffinity(CpuMask& cpu_mask);
+
+ /*!
+ * @if jp
+ * @brief プロセスのCPU affinityを設定する
+ * @prop cpu_mask 設定する CPU affinity を CPU ID の
+ * std::vector<unsigned int> リストで与える
+ * @return True: 成功、False: 失敗
+ * @else
+ * @brief Setting process CPU affinity
+ * @prop cpu_mask CPU affinity mask to be set is given with CPU ID in
+ * std::vector<unsigned int> list.
+ * @return True: success, False: fail
+ * @endif
+ */
+ bool setProcCpuAffinity(const CpuMask cpu_mask);
+
+ /*!
+ * @if jp
+ * @brief プロセスのCPU affinityを文字列で設定する
+ * @prop cpu_mask 設定する CPU affinity を CPU ID のカンマ区切り文字
+ * 列のリストで与える
+ * @return True: 成功、False: 失敗
+ * @else
+ * @brief Setting process CPU affinity with string
+ * @prop cpu_mask CPU affinity mask to be set is given with comma
+ * separated CPU ID string.
+ * @return True: success, False: fail
+ * @endif
+ */
+ bool setProcCpuAffinity(std::string cpu_mask);
+
+ /*!
+ * @if jp
+ * @brief スレッドのCPU affinityを取得する
+ * @prop cpu_mask 現在設定されている affinity が CPU IDの
+ * std::vector<unsigned int> で返される。
+ * @return True: 成功、False: 失敗
+ * @else
+ * @brief Getting current process CPU affinity
+ * @prop cpu_mask Current CPU affinity mask is returned as CPU ID in
+ * std::vector<unsigned int>.
+ * @return True: success, False: fail
+ * @endif
+ */
+ bool getThreadCpuAffinity(CpuMask& cpu_mask);
+
+ /*!
+ * @if jp
+ * @brief スレッドのCPU affinityを設定する
+ * @prop cpu_mask 設定する CPU affinity を CPU ID の
+ * std::vector<unsigned int> リストで与える
+ * @return True: 成功、False: 失敗
+ * @else
+ * @brief Setting process CPU affinity
+ * @prop cpu_mask CPU affinity mask to be set is given with CPU ID in
+ * std::vector<unsigned int> list.
+ * @return True: success, False: fail
+ * @endif
+ */
+ bool setThreadCpuAffinity(const CpuMask cpu_mask);
+
+ /*!
+ * @if jp
+ * @brief スレッドのCPU affinityを文字列で設定する
+ * @prop cpu_mask 設定する CPU affinity を CPU ID のカンマ区切り文字
+ * 列のリストで与える
+ * @return True: 成功、False: 失敗
+ * @else
+ * @brief Setting process CPU affinity with string
+ * @prop cpu_mask CPU affinity mask to be set is given with comma
+ * separated CPU ID string.
+ * @return True: success, False: fail
+ * @endif
+ */
+ bool setThreadCpuAffinity(std::string mask);
+
+}; // namespace coil
+#endif // COIL_AFFINITY_H
Modified: trunk/OpenRTM-aist/src/lib/coil/win32/coil/Makefile.am
===================================================================
--- trunk/OpenRTM-aist/src/lib/coil/win32/coil/Makefile.am 2018-03-28 03:50:22 UTC (rev 3269)
+++ trunk/OpenRTM-aist/src/lib/coil/win32/coil/Makefile.am 2018-03-28 03:51:07 UTC (rev 3270)
@@ -16,7 +16,8 @@
Task.cpp \
Time.cpp \
UUID.cpp \
- SharedMemory.cpp
+ SharedMemory.cpp \
+ Affinity.cpp
# Win32 API dependent headers
COIL_PLATFORM_H = \
openrtm-commit メーリングリストの案内