-
Notifications
You must be signed in to change notification settings - Fork 0
/
log_generator.c
51 lines (40 loc) · 1.12 KB
/
log_generator.c
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
/*
@author: Abdul-Rasheed Audu
@course: COMP 3430 - Operating Systems
@title: log_generator.c
@purpose: Thread that generates logs on a specified row.
*/
#include <stdlib.h>
#include <pthread.h>
#include <stdio.h>
#include "common.h"
#include "single_log.h"
#include "log_generator.h"
#include "console.h"
extern pthread_mutex_t draw_mutex;
extern pthread_cond_t wait_for_console;
extern bool is_game_over;
LogGeneratorParam create_log_generator_params(int index) {
LogGeneratorParam params = malloc(sizeof(struct LOG_GENERATOR_PARAMS));
if (params != NULL ){
params->index = index;
}
return params;
}
void *log_generator_run(void *arg) {
LogGeneratorParam param = (LogGeneratorParam) arg;
if (param == NULL) {
pthread_exit(NULL);
}
int index = param->index;
SingleLogArgs s_args = malloc(sizeof(struct SINGLE_LOG_ARGS));
s_args->row = index;
s_args->direction = (index % 2) ? 1 : -1;
s_args->refresh_ticks = 25;
while ( ! is_game_over ) {
create_thread_object(single_log_run, s_args);
sleepTicks(200);
}
free(s_args);
pthread_exit(NULL);
}