This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// John M. Mellor-Crummey and Michael L. Scott. 1991. Algorithms for scalable | |
// synchronization on shared-memory multiprocessors. ACM Trans. Comput. Syst. 9, | |
// 1 (Feb. 1991), 21–65. DOI:https://doi.org/10.1145/103727.103729 | |
#include <stdlib.h> | |
#include <assert.h> | |
#include <errno.h> | |
typedef int tree_barrierattr_t; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define CE(A, B) \ | |
if ((A) > (B)) { \ | |
int tmp = (A); \ | |
(A) = (B); \ | |
(B) = tmp; \ | |
} | |
void network2(int *start) { | |
CE(start[0], start[1]); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stddef.h> | |
#include <stdint.h> | |
#include <stdlib.h> | |
#include <stdio.h> | |
#include <assert.h> | |
#include <string.h> | |
#define CEIL_DIV(n, d) (((n) / (d)) + (((n) % (d)) != 0)) | |
#define N_DIGITS(lg_base, elem) CEIL_DIV(64 - __builtin_clzll(elem), lg_base) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stddef.h> | |
#include <stdint.h> | |
#include <stdlib.h> | |
#include <stdio.h> | |
#include <assert.h> | |
#include <string.h> | |
#define CEIL_DIV(n, d) (((n) / (d)) + (((n) % (d)) != 0)) | |
#define N_DIGITS(lg_base, elem) CEIL_DIV(64 - __builtin_clzll(elem), lg_base) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Color { | |
ORANGE, | |
WHITE, | |
RED, | |
YELLOW, | |
GREEN, | |
}; | |
void swap(enum Color *a, enum Color *b) { | |
enum Color temp; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef SET_H | |
#define SET_H | |
#include <stdint.h> // uint8_t, uint32_t | |
#include <stdlib.h> // size_t, calloc, free | |
#include <stdbool.h> // bool | |
#include <assert.h> // assert | |
#include <stdio.h> // printf | |
#define TOKENPASTE(X, Y) X ## Y |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef MAP_H | |
#define MAP_H | |
#include <stdint.h> // uint8_t, uint32_t | |
#include <stdlib.h> // size_t, calloc, free | |
#include <stdbool.h> // bool | |
#include <assert.h> // assert | |
#include <stdio.h> // printf | |
#define TOKENPASTE(X, Y) X ## Y |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdint.h> | |
#include <stdlib.h> | |
uint64_t *uniq_rand(uint64_t m, uint64_t n) { | |
uint64_t *vs, im, in, rm, rn, rim, tmp; | |
vs = malloc(m * sizeof(uint64_t)); | |
// Knuth algorithm | |
for (im = 0, in = 0; im < m && in < n; in++) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef LIST_H | |
#define LIST_H | |
#include <stdlib.h> // size_t, malloc, realloc, free | |
#include <stdint.h> // uint32_t | |
#include <stdio.h> // printf | |
#include <stdbool.h> // bool | |
#define TOKENPASTE(X, Y) X ## Y | |
#define INDENT(DEPTH) printf("%*c", DEPTH * 2, ' ') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
// Header | |
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
#define IN /* IN */ | |
#define OUT /* OUT */ | |
#define INOUT /* INOUT */ |