175 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
48 lines
1.6 KiB
C
48 lines
1.6 KiB
C
#ifndef GW_WIRE_PUBLIC_HASH_V1_PRIVATE_H
|
|
#define GW_WIRE_PUBLIC_HASH_V1_PRIVATE_H
|
|
|
|
#include <windows.h>
|
|
#include <stdint.h>
|
|
#include <string.h>
|
|
|
|
/* Additive Wire-owned public login input. The existing account ABI is unchanged.
|
|
* State 0 empty, -1 publishing, 1 published, -2 consuming, 2 consumed. */
|
|
struct GwWirePublicHashV1 {
|
|
uint32_t abi, size;
|
|
volatile LONG state;
|
|
uint32_t generation;
|
|
uint8_t bytes[20];
|
|
uint32_t reserved;
|
|
};
|
|
_Static_assert(sizeof(struct GwWirePublicHashV1) == 40,
|
|
"Public hash row ABI changed");
|
|
|
|
static inline int gw_wire_public_hash_publish(struct GwWirePublicHashV1 *row,
|
|
uint32_t generation,
|
|
const uint8_t bytes[20]) {
|
|
if (!row || !bytes || !generation || row->abi != 1 ||
|
|
row->size != sizeof(*row) || row->generation || row->reserved ||
|
|
InterlockedCompareExchange(&row->state, -1, 0) != 0)
|
|
return 0;
|
|
memcpy(row->bytes, bytes, 20);
|
|
row->generation = generation;
|
|
MemoryBarrier();
|
|
InterlockedExchange(&row->state, 1);
|
|
return 1;
|
|
}
|
|
|
|
static inline int gw_wire_public_hash_take(struct GwWirePublicHashV1 *row,
|
|
uint32_t generation,
|
|
uint8_t bytes[20]) {
|
|
if (!row || !bytes || !generation || row->abi != 1 ||
|
|
row->size != sizeof(*row) || row->generation != generation ||
|
|
row->reserved ||
|
|
InterlockedCompareExchange(&row->state, -2, 1) != 1)
|
|
return 0;
|
|
memcpy(bytes, row->bytes, 20);
|
|
InterlockedExchange(&row->state, 2);
|
|
return 1;
|
|
}
|
|
|
|
#endif
|