-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathres.h
More file actions
48 lines (38 loc) · 1.35 KB
/
res.h
File metadata and controls
48 lines (38 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* This file is made available under the Creative Commons CC0 1.0
* Universal Public Domain Dedication.
*
* The person who associated a work with this deed has dedicated the
* work to the public domain by waiving all of his or her rights to
* the work worldwide under copyright law, including all related and
* neighboring rights, to the extent allowed by law. You can copy,
* modify, distribute and perform the work, even for commercial
* purposes, all without asking permission.
*/
#pragma once
#include <pthread.h>
#include <stdbool.h>
#include <stdint.h>
#define BASE_BITMASK (~RESOURCE_BITMASK)
#define RESOURCE_BITSHIFT (3)
#define RESOURCE_NBYTES (1ul << RESOURCE_BITSHIFT)
#define RESOURCE_BITMASK ((1ul << RESOURCE_BITSHIFT) - 1)
/**
* A value with an associated owner.
*/
struct resource {
uintptr_t base;
uint8_t local_value[RESOURCE_NBYTES];
uint8_t local_bits;
uint8_t flags;
pthread_t owner;
pthread_mutex_t lock;
};
#define NRESOURCES_BITSHIFT (10)
#define NRESOURCES (1ul << NRESOURCES_BITSHIFT)
#define NRESOURCES_BITMASK ((1ul << NRESOURCES_BITSHIFT) - 1)
#define RESOURCE_FLAG_WRITE_THROUGH (1ul)
extern struct resource g_resource[NRESOURCES];
struct resource*
acquire_resource(uintptr_t base);
void
release_resource(struct resource* res, bool commit);