ホーム › System.Threading › SetThreadSelectedCpuSets
SetThreadSelectedCpuSets
関数スレッドに使用するCPUセットIDを設定する。
シグネチャ
// KERNEL32.dll
#include <windows.h>
BOOL SetThreadSelectedCpuSets(
HANDLE Thread,
const DWORD* CpuSetIds,
DWORD CpuSetIdCount
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| Thread | HANDLE | in | CPU セットの割り当てを設定する対象のスレッドを指定します。このハンドルには THREAD_SET_LIMITED_INFORMATION アクセス権が必要です。GetCurrentThread が返す値も使用できます。 |
| CpuSetIds | DWORD* | in | スレッドが選択する CPU セットとして設定する CPU セット ID のリストを指定します。これが NULL の場合、この API は割り当てをクリアし、プロセス既定の割り当てが設定されていればそれに戻します。 |
| CpuSetIdCount | DWORD | in | CpuSetIds 引数に渡されるリスト内の ID の数を指定します。その値が NULL の場合、これは 0 にする必要があります。 |
戻り値の型: BOOL
公式ドキュメント
指定したスレッドに対して、選択された CPU セットの割り当てを設定します。この割り当ては、プロセス既定の割り当てが設定されている場合、それを上書きします。(SetThreadSelectedCpuSets)
戻り値
関数が成功した場合、戻り値は 0 以外になります。
この関数は、有効なパラメーターが渡された場合は失敗しません。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// KERNEL32.dll
#include <windows.h>
BOOL SetThreadSelectedCpuSets(
HANDLE Thread,
const DWORD* CpuSetIds,
DWORD CpuSetIdCount
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", ExactSpelling = true)]
static extern bool SetThreadSelectedCpuSets(
IntPtr Thread, // HANDLE
ref uint CpuSetIds, // DWORD*
uint CpuSetIdCount // DWORD
);<DllImport("KERNEL32.dll", ExactSpelling:=True)>
Public Shared Function SetThreadSelectedCpuSets(
Thread As IntPtr, ' HANDLE
ByRef CpuSetIds As UInteger, ' DWORD*
CpuSetIdCount As UInteger ' DWORD
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' Thread : HANDLE
' CpuSetIds : DWORD*
' CpuSetIdCount : DWORD
Declare PtrSafe Function SetThreadSelectedCpuSets Lib "kernel32" ( _
ByVal Thread As LongPtr, _
ByRef CpuSetIds As Long, _
ByVal CpuSetIdCount As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SetThreadSelectedCpuSets = ctypes.windll.kernel32.SetThreadSelectedCpuSets
SetThreadSelectedCpuSets.restype = wintypes.BOOL
SetThreadSelectedCpuSets.argtypes = [
wintypes.HANDLE, # Thread : HANDLE
ctypes.POINTER(wintypes.DWORD), # CpuSetIds : DWORD*
wintypes.DWORD, # CpuSetIdCount : DWORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('KERNEL32.dll')
SetThreadSelectedCpuSets = Fiddle::Function.new(
lib['SetThreadSelectedCpuSets'],
[
Fiddle::TYPE_VOIDP, # Thread : HANDLE
Fiddle::TYPE_VOIDP, # CpuSetIds : DWORD*
-Fiddle::TYPE_INT, # CpuSetIdCount : DWORD
],
Fiddle::TYPE_INT)#[link(name = "kernel32")]
extern "system" {
fn SetThreadSelectedCpuSets(
Thread: *mut core::ffi::c_void, // HANDLE
CpuSetIds: *const u32, // DWORD*
CpuSetIdCount: u32 // DWORD
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll")]
public static extern bool SetThreadSelectedCpuSets(IntPtr Thread, ref uint CpuSetIds, uint CpuSetIdCount);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_SetThreadSelectedCpuSets' -Namespace Win32 -PassThru
# $api::SetThreadSelectedCpuSets(Thread, CpuSetIds, CpuSetIdCount)#uselib "KERNEL32.dll"
#func global SetThreadSelectedCpuSets "SetThreadSelectedCpuSets" sptr, sptr, sptr
; SetThreadSelectedCpuSets Thread, varptr(CpuSetIds), CpuSetIdCount ; 戻り値は stat
; Thread : HANDLE -> "sptr"
; CpuSetIds : DWORD* -> "sptr"
; CpuSetIdCount : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "KERNEL32.dll" #cfunc global SetThreadSelectedCpuSets "SetThreadSelectedCpuSets" sptr, var, int ; res = SetThreadSelectedCpuSets(Thread, CpuSetIds, CpuSetIdCount) ; Thread : HANDLE -> "sptr" ; CpuSetIds : DWORD* -> "var" ; CpuSetIdCount : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "KERNEL32.dll" #cfunc global SetThreadSelectedCpuSets "SetThreadSelectedCpuSets" sptr, sptr, int ; res = SetThreadSelectedCpuSets(Thread, varptr(CpuSetIds), CpuSetIdCount) ; Thread : HANDLE -> "sptr" ; CpuSetIds : DWORD* -> "sptr" ; CpuSetIdCount : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL SetThreadSelectedCpuSets(HANDLE Thread, DWORD* CpuSetIds, DWORD CpuSetIdCount) #uselib "KERNEL32.dll" #cfunc global SetThreadSelectedCpuSets "SetThreadSelectedCpuSets" intptr, var, int ; res = SetThreadSelectedCpuSets(Thread, CpuSetIds, CpuSetIdCount) ; Thread : HANDLE -> "intptr" ; CpuSetIds : DWORD* -> "var" ; CpuSetIdCount : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL SetThreadSelectedCpuSets(HANDLE Thread, DWORD* CpuSetIds, DWORD CpuSetIdCount) #uselib "KERNEL32.dll" #cfunc global SetThreadSelectedCpuSets "SetThreadSelectedCpuSets" intptr, intptr, int ; res = SetThreadSelectedCpuSets(Thread, varptr(CpuSetIds), CpuSetIdCount) ; Thread : HANDLE -> "intptr" ; CpuSetIds : DWORD* -> "intptr" ; CpuSetIdCount : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procSetThreadSelectedCpuSets = kernel32.NewProc("SetThreadSelectedCpuSets")
)
// Thread (HANDLE), CpuSetIds (DWORD*), CpuSetIdCount (DWORD)
r1, _, err := procSetThreadSelectedCpuSets.Call(
uintptr(Thread),
uintptr(CpuSetIds),
uintptr(CpuSetIdCount),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction SetThreadSelectedCpuSets(
Thread: THandle; // HANDLE
CpuSetIds: Pointer; // DWORD*
CpuSetIdCount: DWORD // DWORD
): BOOL; stdcall;
external 'KERNEL32.dll' name 'SetThreadSelectedCpuSets';result := DllCall("KERNEL32\SetThreadSelectedCpuSets"
, "Ptr", Thread ; HANDLE
, "Ptr", CpuSetIds ; DWORD*
, "UInt", CpuSetIdCount ; DWORD
, "Int") ; return: BOOL●SetThreadSelectedCpuSets(Thread, CpuSetIds, CpuSetIdCount) = DLL("KERNEL32.dll", "bool SetThreadSelectedCpuSets(void*, void*, dword)")
# 呼び出し: SetThreadSelectedCpuSets(Thread, CpuSetIds, CpuSetIdCount)
# Thread : HANDLE -> "void*"
# CpuSetIds : DWORD* -> "void*"
# CpuSetIdCount : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "kernel32" fn SetThreadSelectedCpuSets(
Thread: ?*anyopaque, // HANDLE
CpuSetIds: [*c]u32, // DWORD*
CpuSetIdCount: u32 // DWORD
) callconv(std.os.windows.WINAPI) i32;proc SetThreadSelectedCpuSets(
Thread: pointer, # HANDLE
CpuSetIds: ptr uint32, # DWORD*
CpuSetIdCount: uint32 # DWORD
): int32 {.importc: "SetThreadSelectedCpuSets", stdcall, dynlib: "KERNEL32.dll".}pragma(lib, "kernel32");
extern(Windows)
int SetThreadSelectedCpuSets(
void* Thread, // HANDLE
uint* CpuSetIds, // DWORD*
uint CpuSetIdCount // DWORD
);ccall((:SetThreadSelectedCpuSets, "KERNEL32.dll"), stdcall, Int32,
(Ptr{Cvoid}, Ptr{UInt32}, UInt32),
Thread, CpuSetIds, CpuSetIdCount)
# Thread : HANDLE -> Ptr{Cvoid}
# CpuSetIds : DWORD* -> Ptr{UInt32}
# CpuSetIdCount : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t SetThreadSelectedCpuSets(
void* Thread,
uint32_t* CpuSetIds,
uint32_t CpuSetIdCount);
]]
local kernel32 = ffi.load("kernel32")
-- kernel32.SetThreadSelectedCpuSets(Thread, CpuSetIds, CpuSetIdCount)
-- Thread : HANDLE
-- CpuSetIds : DWORD*
-- CpuSetIdCount : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('KERNEL32.dll');
const SetThreadSelectedCpuSets = lib.func('__stdcall', 'SetThreadSelectedCpuSets', 'int32_t', ['void *', 'uint32_t *', 'uint32_t']);
// SetThreadSelectedCpuSets(Thread, CpuSetIds, CpuSetIdCount)
// Thread : HANDLE -> 'void *'
// CpuSetIds : DWORD* -> 'uint32_t *'
// CpuSetIdCount : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("KERNEL32.dll", {
SetThreadSelectedCpuSets: { parameters: ["pointer", "pointer", "u32"], result: "i32" },
});
// lib.symbols.SetThreadSelectedCpuSets(Thread, CpuSetIds, CpuSetIdCount)
// Thread : HANDLE -> "pointer"
// CpuSetIds : DWORD* -> "pointer"
// CpuSetIdCount : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t SetThreadSelectedCpuSets(
void* Thread,
uint32_t* CpuSetIds,
uint32_t CpuSetIdCount);
C, "KERNEL32.dll");
// $ffi->SetThreadSelectedCpuSets(Thread, CpuSetIds, CpuSetIdCount);
// Thread : HANDLE
// CpuSetIds : DWORD*
// CpuSetIdCount : DWORD
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Kernel32 extends StdCallLibrary {
Kernel32 INSTANCE = Native.load("kernel32", Kernel32.class);
boolean SetThreadSelectedCpuSets(
Pointer Thread, // HANDLE
IntByReference CpuSetIds, // DWORD*
int CpuSetIdCount // DWORD
);
}@[Link("kernel32")]
lib LibKERNEL32
fun SetThreadSelectedCpuSets = SetThreadSelectedCpuSets(
Thread : Void*, # HANDLE
CpuSetIds : UInt32*, # DWORD*
CpuSetIdCount : UInt32 # DWORD
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef SetThreadSelectedCpuSetsNative = Int32 Function(Pointer<Void>, Pointer<Uint32>, Uint32);
typedef SetThreadSelectedCpuSetsDart = int Function(Pointer<Void>, Pointer<Uint32>, int);
final SetThreadSelectedCpuSets = DynamicLibrary.open('KERNEL32.dll')
.lookupFunction<SetThreadSelectedCpuSetsNative, SetThreadSelectedCpuSetsDart>('SetThreadSelectedCpuSets');
// Thread : HANDLE -> Pointer<Void>
// CpuSetIds : DWORD* -> Pointer<Uint32>
// CpuSetIdCount : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SetThreadSelectedCpuSets(
Thread: THandle; // HANDLE
CpuSetIds: Pointer; // DWORD*
CpuSetIdCount: DWORD // DWORD
): BOOL; stdcall;
external 'KERNEL32.dll' name 'SetThreadSelectedCpuSets';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SetThreadSelectedCpuSets"
c_SetThreadSelectedCpuSets :: Ptr () -> Ptr Word32 -> Word32 -> IO CInt
-- Thread : HANDLE -> Ptr ()
-- CpuSetIds : DWORD* -> Ptr Word32
-- CpuSetIdCount : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let setthreadselectedcpusets =
foreign "SetThreadSelectedCpuSets"
((ptr void) @-> (ptr uint32_t) @-> uint32_t @-> returning int32_t)
(* Thread : HANDLE -> (ptr void) *)
(* CpuSetIds : DWORD* -> (ptr uint32_t) *)
(* CpuSetIdCount : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library kernel32 (t "KERNEL32.dll"))
(cffi:use-foreign-library kernel32)
(cffi:defcfun ("SetThreadSelectedCpuSets" set-thread-selected-cpu-sets :convention :stdcall) :int32
(thread :pointer) ; HANDLE
(cpu-set-ids :pointer) ; DWORD*
(cpu-set-id-count :uint32)) ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SetThreadSelectedCpuSets = Win32::API::More->new('KERNEL32',
'BOOL SetThreadSelectedCpuSets(HANDLE Thread, LPVOID CpuSetIds, DWORD CpuSetIdCount)');
# my $ret = $SetThreadSelectedCpuSets->Call($Thread, $CpuSetIds, $CpuSetIdCount);
# Thread : HANDLE -> HANDLE
# CpuSetIds : DWORD* -> LPVOID
# CpuSetIdCount : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。