-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibs_poller.hpp
46 lines (37 loc) · 1.16 KB
/
libs_poller.hpp
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
#include <stdio.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <unistd.h>
#include <stdlib.h>
#include <ctype.h>
#include <csignal>
#include <pthread.h>
#include <iostream>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
#include <cstring>
#include <fcntl.h>
#define THR_LIMIT 100
using namespace std;
queue <int* > buffer;
vector<pair<string, string>> votes;
vector<string> names;
vector<string> political_parties;
int poll_log_file = -1;
int poll_stat_file = -1;
const char* poll_stat_name;
pthread_mutex_t buffer_lock = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t names_lock = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t parties_lock = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t votes_lock = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t poll_lock = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t buffer_nonempty = PTHREAD_COND_INITIALIZER; //empty buffer in worker
pthread_cond_t buffer_nonfull = PTHREAD_COND_INITIALIZER; //full buffer in master
void* get_vote(void* arg);
void signal_handler(int signum);
bool compare(pair<string, int>& a, pair<string, int>& b);