|
|
1.1 root 1: //
2: // nono
3: // Copyright (C) 2020 nono project
4: // Licensed under nono-license.txt
5: //
6:
1.1.1.2 root 7: //
1.1 root 8: // pthread の OS ごとに違う部分を吸収する
1.1.1.2 root 9: //
1.1 root 10:
11: #pragma once
12:
13: #include "header.h"
1.1.1.2 root 14: #include <pthread.h>
1.1.1.3 ! root 15: #if defined(HAVE_SCHED_H)
! 16: #include <sched.h>
! 17: #endif
! 18: #if defined(HAVE_SYS_CPUSET_H)
! 19: #include <sys/cpuset.h>
! 20: #endif
1.1 root 21:
1.1.1.3 ! root 22: // cpu{,_}set_t とその関数群の違いを吸収するクラス
! 23: #if defined(HAVE_CPUSET_T_P) || defined(HAVE_CPU_SET_T)
! 24:
! 25: // 型は NetBSD/FreeBSD のほうに揃えておく。
! 26: #if defined(HAVE_CPU_SET_T) && !defined(HAVE_CPUSET_T)
! 27: #define cpuset_t cpu_set_t
! 28: #endif
! 29:
! 30: #define HAVE_MICPUSET 1
! 31:
! 32: class MICPUSet
! 33: {
! 34: public:
! 35: MICPUSet();
! 36: ~MICPUSet();
! 37:
! 38: // cpuset_t を返す
! 39: cpuset_t *Get() const { return set; }
! 40:
! 41: // サイズを返す
! 42: size_t Count() const;
! 43:
! 44: // CPU #n のビットをセットする
! 45: void Set(uint n);
! 46:
! 47: // CPU #n のビットを取得する
! 48: bool Get(uint n) const;
! 49:
! 50: private:
! 51: cpuset_t *set {};
! 52: #if !defined(HAVE_CPUSET_CREATE)
! 53: cpuset_t entity {};
! 54: #endif
! 55: };
! 56: #endif // HAVE_CPUSET_T_P || HAVE_CPU_SET_T
! 57:
! 58: #if defined(HAVE_PTHREAD_SETAFFINITY_NP)
! 59: extern int PTHREAD_SETAFFINITY(pthread_t, const MICPUSet&);
! 60: #endif
1.1.1.2 root 61: extern int PTHREAD_SETNAME(const char *name);
62: extern std::string PTHREAD_GETNAME(pthread_t thread = pthread_self());
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.