-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuzzlock.h
More file actions
49 lines (44 loc) · 1 KB
/
buzzlock.h
File metadata and controls
49 lines (44 loc) · 1 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
49
#include <unistd.h>
#include <sys/types.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <pthread.h>
#include <sys/time.h>
#include <time.h>
#include <sys/syscall.h>
#include <string.h>
#define BZZ_BLACK 0
#define BZZ_GOLD 1
#define SYSBZZ_INIT 0
#define SYSBZZ_COLOR 1
#define SYSBZZ_LOCK 2
#define SYSBZZ_RELEASE 3
#define SYSBZZ_KILL 4
#ifdef BZZ_KERNEL_MODE
// TODO: kernel mode structures
typedef void* bzz_t;
#else
typedef struct _bzz_thread {
pthread_cond_t cond;
int color;
struct timeval time_created;
pid_t tid;
struct _bzz_thread* next;
} bzz_thread;
typedef struct {
bzz_thread* gold_threads;
bzz_thread* gold_end;
bzz_thread* black_threads;
bzz_thread* black_end;
bzz_thread* unqueued_threads;
bzz_thread* current_locked;
useconds_t timeout;
pthread_mutex_t mutex;
} bzz_t;
#endif
void init_bzz(bzz_t *lock, int num_threads, useconds_t timeout);
void bzz_color(int color, bzz_t *lock);
void bzz_lock(bzz_t *lock);
void bzz_release(bzz_t *lock);
void bzz_kill(bzz_t *lock);