Files

55 lines
1.3 KiB
C

#ifndef TASK01_MUTEX_MODEL_H
#define TASK01_MUTEX_MODEL_H
#include <stddef.h>
#include <stdint.h>
typedef struct MutexEvidence
{
uint32_t sequence;
uint32_t event;
uint32_t tick;
uint32_t actor;
uint32_t value;
uint32_t committed;
} MutexEvidence;
static inline uint32_t fc08_digest( const MutexEvidence * events,
size_t count )
{
uint32_t hash = 2166136261U;
size_t index;
for( index = 0U; index < count; ++index )
{
hash = ( hash ^ events[ index ].event ) * 16777619U;
hash = ( hash ^ events[ index ].actor ) * 16777619U;
hash = ( hash ^ events[ index ].value ) * 16777619U;
hash = ( hash ^ events[ index ].committed ) * 16777619U;
}
return hash;
}
static inline int fc08_order_is_valid( const MutexEvidence * events,
size_t count )
{
size_t index;
if( events == NULL || count != 10U )
{
return 0;
}
for( index = 0U; index < count; ++index )
{
if( events[ index ].sequence != index + 1U ||
events[ index ].event != index + 1U ||
events[ index ].committed != ( 0xFC080000U | ( index + 1U ) ) )
{
return 0;
}
}
return 1;
}
#endif