ekg/cbits/counter.c
2014-04-10 15:16:38 +02:00

15 lines
326 B
C

#include <stdlib.h>
#include "HsFFI.h"
StgInt* hs_counter_new(void) {
StgInt* counter = malloc(sizeof(StgInt));
*counter = 0;
return counter;
}
void hs_counter_add(volatile StgInt* counter, StgInt n) {
__sync_fetch_and_add(counter, n);
}
StgInt hs_counter_read(volatile const StgInt* counter) {
return *counter;
}