Repository navigation
Expand file tree
/
Copy pathhelp.h
More file actions
105 lines (83 loc) · 2.56 KB
/
Copy pathhelp.h
File metadata and controls
105 lines (83 loc) · 2.56 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#ifndef _THRLAB_HELP_H_
#define _THRLAB_HELP_H_
#include <pthread.h>
#include <semaphore.h>
/******************************************************************************
* Initialization & Cleanup
*****************************************************************************/
/**
* Initialize the thrlab environment.
*
* Must be called before any other thrlab function.
*/
void thrlab_setup (int *argc, char ***argv);
/**
* Clean up resources used by the thrlab environment.
*
* No thrlab function may be called after a cleanup.
*/
void thrlab_cleanup ();
/******************************************************************************
* Barbershop Information
*****************************************************************************/
/**
* Get the number of barbers on duty.
*/
unsigned int thrlab_get_num_barbers ();
/**
* Get the number of waiting chairs in the building.
*/
unsigned int thrlab_get_num_chairs ();
/******************************************************************************
* Helper Functions
*****************************************************************************/
/**
* Pause the current thread for at least `ms` milliseconds.
*/
void thrlab_sleep (int ms);
/******************************************************************************
* Customer Management
*****************************************************************************/
/**
* Information about a customer.
*/
struct customer
{
/* the customer's thread */
pthread_t thread;
/* name of the customer */
const char *name;
/* a unique customer identifier */
unsigned int id;
/* length of the customer's hair in millimetres */
unsigned int hair_length;
/* desired hair length in millimetres */
unsigned int hair_goal;
/* A mutex that you are free to use */
sem_t mutex;
};
/**
* Blocks the current thread, calling `callback` in a new thread each time a
* new customer arrives, until it's time to close down the shop.
*/
void thrlab_wait_for_customers
( void (*callback) (struct customer *, void *)
, void *ud
);
/**
* Accept the customer and place him in the waiting room.
*/
void thrlab_accept_customer (struct customer *customer);
/**
* Reject the customer; the waiting room's full.
*/
void thrlab_reject_customer (struct customer *customer);
/**
* Prepare the customer for a nice haircut in room `room`.
*/
void thrlab_prepare_customer (struct customer *customer, unsigned int room);
/**
* Dismiss the customer from room `room`; their hair has been cut.
*/
void thrlab_dismiss_customer (struct customer *customer, unsigned int room);
#endif