-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroutine.c
More file actions
62 lines (57 loc) · 2.1 KB
/
Copy pathroutine.c
File metadata and controls
62 lines (57 loc) · 2.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
50
51
52
53
54
55
56
57
58
59
60
61
62
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* routine.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dporhomo <dporhomo@student.42prague.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/06/08 18:44:17 by dporhomo #+# #+# */
/* Updated: 2026/06/15 13:37:34 by dporhomo ### ########.fr */
/* */
/* ************************************************************************** */
#include "codexion.h"
static void *handle_single_coder(t_coder *coder)
{
pthread_mutex_lock(&coder->prog->dongles[coder->left_dongle]);
print_status(coder, "has taken a dongle");
while (read_sim_active(coder->prog))
ft_usleep(10);
pthread_mutex_unlock(&coder->prog->dongles[coder->left_dongle]);
return (NULL);
}
/* The core operation of the coder routine */
static int perform_coder_cycle(t_coder *coder)
{
if (!grab_dongles(coder))
return (0);
print_status(coder, "is compiling");
update_last_compile(coder);
ft_usleep(coder->prog->t_compile);
drop_dongles(coder);
increment_compiles_done(coder);
if (read_compiles_done(coder) >= coder->prog->req_compiles)
return (0);
print_status(coder, "is debugging");
ft_usleep(coder->prog->t_debug);
print_status(coder, "is refactoring");
ft_usleep(coder->prog->t_refactor);
return (1);
}
/* Conditional caller of the coder routine */
void *coder_routine(void *arg)
{
t_coder *coder;
coder = (t_coder *)arg;
if (coder->prog->req_compiles == 0)
return (NULL);
if (coder->prog->num_coders == 1)
return (handle_single_coder(coder));
if (coder->id % 2 == 0)
ft_usleep(10);
while (read_sim_active(coder->prog))
{
if (!perform_coder_cycle(coder))
break ;
}
return (NULL);
}