<commit_before>#ifndef UTIL_H
#define UTIL_H

#include "fibrile.h"

/** Atomics. */
#define fence() fibrile_fence()
#define fadd(ptr, n) __sync_fetch_and_add(ptr, n)
#define cas(...) __sync_val_compare_and_swap(__VA_ARGS__)

/** Lock. */
#define lock(ptr)   fibrile_lock(ptr)
#define unlock(ptr) fibrile_unlock(ptr)
#define trylock(ptr) (!__sync_lock_test_and_set(ptr, 1))

/** Barrier. */
static inline void barrier(int n)
{
  static volatile int count = 0;
  static volatile int sense = 0;

  int local_sense = !fibrile_deq.sense;

  if (fadd(&count, 1) == n - 1) {
    count = 0;
    sense = local_sense;
  }

  while (sense != local_sense);
}

/** Others. */

typedef struct _frame_t {
  void * rsp;
  void * rip;
} frame_t;

#define this_frame() ((frame_t *) __builtin_frame_address(0))
#define unreachable() __builtin_unreachable()

#define adjust(addr, offset) ((void *) addr - offset)

#endif /* end of include guard: UTIL_H */<commit_msg>Add a fence in barrier.<commit_after>#ifndef UTIL_H
#define UTIL_H

#include "fibrile.h"

/** Atomics. */
#define fence() fibrile_fence()
#define fadd(ptr, n) __sync_fetch_and_add(ptr, n)
#define cas(...) __sync_val_compare_and_swap(__VA_ARGS__)

/** Lock. */
#define lock(ptr)   fibrile_lock(ptr)
#define unlock(ptr) fibrile_unlock(ptr)
#define trylock(ptr) (!__sync_lock_test_and_set(ptr, 1))

/** Barrier. */
static inline void barrier(int n)
{
  static volatile int count = 0;
  static volatile int sense = 0;

  int local_sense = !fibrile_deq.sense;

  if (fadd(&count, 1) == n - 1) {
    count = 0;
    sense = local_sense;
  }

  while (sense != local_sense);
  fence();
}

/** Others. */

typedef struct _frame_t {
  void * rsp;
  void * rip;
} frame_t;

#define this_frame() ((frame_t *) __builtin_frame_address(0))
#define unreachable() __builtin_unreachable()

#define adjust(addr, offset) ((void *) addr - offset)

#endif /* end of include guard: UTIL_H */
{'fraction_non_alphanumeric': 0.1503916449086162, 'fraction_numerical': 0.007310704960835509, 'mean_word_length': 4.337047353760446, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2412125', 'n_tokens_mistral': 757, 'n_tokens_neox': 719, 'n_words': 181}