File:  [Isaki's NoNo m68k/m88k emulator] / nono / lib / mythread.h
Revision 1.1.1.3 (vendor branch): download - view: text, annotated - select for diffs
Wed Apr 29 17:05:26 2026 UTC (2 months, 3 weeks ago) by root
Branches: MAIN, Isaki
CVS tags: v027, v026, v025, v024, v023, v022, v021, v020, HEAD
nono 1.0.0

//
// nono
// Copyright (C) 2020 nono project
// Licensed under nono-license.txt
//

//
// pthread の OS ごとに違う部分を吸収する
//

#pragma once

#include "header.h"
#include <pthread.h>
#if defined(HAVE_SCHED_H)
#include <sched.h>
#endif
#if defined(HAVE_SYS_CPUSET_H)
#include <sys/cpuset.h>
#endif

// cpu{,_}set_t とその関数群の違いを吸収するクラス
#if defined(HAVE_CPUSET_T_P) || defined(HAVE_CPU_SET_T)

// 型は NetBSD/FreeBSD のほうに揃えておく。
#if defined(HAVE_CPU_SET_T) && !defined(HAVE_CPUSET_T)
#define cpuset_t	cpu_set_t
#endif

#define HAVE_MICPUSET 1

class MICPUSet
{
 public:
	MICPUSet();
	~MICPUSet();

	// cpuset_t を返す
	cpuset_t *Get() const { return set; }

	// サイズを返す
	size_t Count() const;

	// CPU #n のビットをセットする
	void Set(uint n);

	// CPU #n のビットを取得する
	bool Get(uint n) const;

 private:
	cpuset_t *set {};
#if !defined(HAVE_CPUSET_CREATE)
	cpuset_t entity {};
#endif
};
#endif // HAVE_CPUSET_T_P || HAVE_CPU_SET_T

#if defined(HAVE_PTHREAD_SETAFFINITY_NP)
extern int PTHREAD_SETAFFINITY(pthread_t, const MICPUSet&);
#endif
extern int PTHREAD_SETNAME(const char *name);
extern std::string PTHREAD_GETNAME(pthread_t thread = pthread_self());

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.