Skip to content

Commit

Permalink
Update NUMA_NODE_RELATIONSHIP to new variable size structure
Browse files Browse the repository at this point in the history
  • Loading branch information
dbwiddis committed Aug 8, 2021
1 parent 7027e33 commit 901e443
Showing 1 changed file with 67 additions and 6 deletions.
73 changes: 67 additions & 6 deletions contrib/platform/src/com/sun/jna/platform/win32/WinNT.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
*/
package com.sun.jna.platform.win32;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import com.sun.jna.FromNativeContext;
import com.sun.jna.IntegerType;
import com.sun.jna.Memory;
Expand Down Expand Up @@ -3126,33 +3131,89 @@ public void read() {
/**
* Represents information about a NUMA node in a processor group.
*/
@FieldOrder({ "nodeNumber", "reserved", "groupMask" })
@FieldOrder({ "nodeNumber", "reserved", "groupCount", "groupMask", "groupMasks" })
public static class NUMA_NODE_RELATIONSHIP extends SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX {

/**
* Identifies the NUMA node. Valid values are {@code 0} to the highest
* NUMA node number inclusive. A non-NUMA multiprocessor system will
* report that all processors belong to one NUMA node.
* Identifies the NUMA node. Valid values are {@code 0} to the highest NUMA node
* number inclusive. A non-NUMA multiprocessor system will report that all
* processors belong to one NUMA node.
*/
public int nodeNumber;

/**
* This member is reserved.
*/
public byte[] reserved = new byte[20];
public byte[] reserved = new byte[18];

/**
* The number of groups included in the GroupMasks array. This field was
* introduced in TBD Release Iron. On earlier versions, this value is always 0.
*/
public short groupCount;

/**
* A {@link GROUP_AFFINITY} structure that specifies a group number and
* processor affinity within the group.
* processor affinity within the group. This member is only relevant if
* {@code groupCount} is 0.
*/
public GROUP_AFFINITY groupMask;

/**
* An array of {@link GROUP_AFFINITY} structures that specifies a group number
* and processor affinity within the group. This member is only relevant if
* {@code groupCount} is 1 or greater.
*/
public GROUP_AFFINITY[] groupMasks = new GROUP_AFFINITY[1];

public NUMA_NODE_RELATIONSHIP() {
}

public NUMA_NODE_RELATIONSHIP(Pointer memory) {
super(memory);
}

/*
* Since the groupMasks array always has at least one element we copy it to the
* groupMask field for backwards compatibility in the case groupCount is 0 or 1.
* Otherwise we resize the array.
*/
@Override
public void read() {
readField("groupCount");
if (groupCount > 1) {
groupMasks = new GROUP_AFFINITY[groupCount];
}
super.read();
// Copy first value from array to older version of structure
groupMask = groupMasks[0];
}

/*
* getFieldList and getFieldOrder are overridden because there are two versions
* of this structure. We will always populate the groupMasks field in the newer
* version, but we will copy groupMasks[0] to the groupMask field elsewhere for
* backwards compatibility.
*/
@Override
protected List<Field> getFieldList() {
List<Field> fields = new ArrayList<Field>(super.getFieldList());
Iterator<Field> fieldIterator = fields.iterator();
while (fieldIterator.hasNext()) {
Field field = fieldIterator.next();
if ("groupMask".equals(field.getName())) {
fieldIterator.remove();
}
}
return fields;
}

@Override
protected List<String> getFieldOrder() {
List<String> fieldOrder = new ArrayList<String>(super.getFieldOrder());
fieldOrder.remove("groupMask");
return fieldOrder;
}
}

/**
Expand Down

0 comments on commit 901e443

Please sign in to comment.