This repository has been archived by the owner on Jan 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
sexpr.cc
88 lines (73 loc) · 1.67 KB
/
sexpr.cc
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
/* Copyright © 2008-2018 Jakub Wilk <jwilk@jwilk.net>
*
* This file is part of pdf2djvu.
*
* pdf2djvu is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* pdf2djvu is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*/
#include "sexpr.hh"
#include <cstdio>
#include <libdjvu/ddjvuapi.h>
#include <libdjvu/miniexp.h>
static int my_puts(miniexp_io_t* io, const char *s)
{
std::ostream *puts_stream = reinterpret_cast<std::ostream*>(io->data[0]);
*puts_stream << s;
return puts_stream->good() ? 0 : EOF;
}
namespace sexpr
{
std::ostream &operator<<(std::ostream &stream, const sexpr::Ref &expr)
{
miniexp_io_t io;
miniexp_io_init(&io);
io.fputs = my_puts;
io.data[0] = &stream;
miniexp_prin_r(&io, expr);
return stream;
}
}
#if _OPENMP && DDJVUAPI_VERSION < 23
#include <omp.h>
class OmpLock
{
private:
omp_lock_t m_lock;
public:
OmpLock()
{
omp_init_lock(&this->m_lock);
}
void lock()
{
omp_set_lock(&this->m_lock);
}
void unlock()
{
omp_unset_lock(&this->m_lock);
}
~OmpLock()
{
omp_destroy_lock(&this->m_lock);
}
};
static OmpLock omp_lock;
sexpr::Guard::Guard()
{
omp_lock.lock();
}
sexpr::Guard::~Guard()
{
omp_lock.unlock();
}
#else
sexpr::Guard::Guard() { }
sexpr::Guard::~Guard() { }
#endif
// vim:ts=4 sts=4 sw=4 et