-
Notifications
You must be signed in to change notification settings - Fork 3
/
message.c
69 lines (57 loc) · 1.43 KB
/
message.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "message.h"
#include <assert.h>
#include <pthread.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
void die (const char *fmt, ...) {
acquire_message_lock ();
fputs ("gimsatul: error: ", stderr);
va_list ap;
va_start (ap, fmt);
vfprintf (stderr, fmt, ap);
va_end (ap);
fputc ('\n', stderr);
fflush (stderr);
release_message_lock ();
exit (1);
}
void fatal_error (const char *fmt, ...) {
acquire_message_lock ();
fputs ("gimsatul: fatal error: ", stderr);
va_list ap;
va_start (ap, fmt);
vfprintf (stderr, fmt, ap);
va_end (ap);
fputc ('\n', stderr);
fflush (stderr);
release_message_lock ();
abort ();
}
#ifndef QUIET
int verbosity;
static pthread_mutex_t message_mutex = PTHREAD_MUTEX_INITIALIZER;
static void message_lock_failure (const char *str) {
char buffer[128];
sprintf (buffer, "gimsatul: fatal message locking error: %s\n", str);
size_t len = strlen (buffer);
assert (len < sizeof buffer);
if (write (1, buffer, len) != len)
abort ();
abort ();
}
void acquire_message_lock (void) {
if (pthread_mutex_lock (&message_mutex))
message_lock_failure ("failed to acquire message lock");
}
void release_message_lock (void) {
if (pthread_mutex_unlock (&message_mutex))
message_lock_failure ("failed to release message lock");
}
const char *prefix_format = "c%-2u ";
#ifdef LOGGING
_Atomic (uint64_t) clause_ids;
#endif
#endif