forked from ceph/ceph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdout.h
106 lines (88 loc) · 2.62 KB
/
dout.h
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
/*
* Ceph - scalable distributed file system
*
* Copyright (C) 2004-2010 Sage Weil <[email protected]>
* Copyright (C) 2010 Dreamhost
*
* This is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software
* Foundation. See file COPYING.
*
*/
#ifndef CEPH_DOUT_H
#define CEPH_DOUT_H
#include "global/global_context.h"
#include "common/DoutStreambuf.h"
#include "common/config.h"
#include "common/likely.h"
#include "include/assert.h"
#include <iostream>
#include <pthread.h>
#include <streambuf>
extern void dout_emergency(const char * const str);
extern void dout_emergency(const std::string &str);
class DoutLocker
{
public:
DoutLocker(pthread_mutex_t *lock_)
: lock(lock_)
{
pthread_mutex_lock(lock);
}
DoutLocker()
: lock(NULL)
{
}
~DoutLocker() {
if (lock)
pthread_mutex_unlock(lock);
}
pthread_mutex_t *lock;
};
static inline void _dout_begin_line(CephContext *cct, signed int prio) {
// Put priority information into dout
cct->_doss->sputc(prio + 12);
// Some information that goes in every dout message
cct->_dout << std::hex << pthread_self() << std::dec << " ";
}
// intentionally conflict with endl
class _bad_endl_use_dendl_t { public: _bad_endl_use_dendl_t(int) {} };
static const _bad_endl_use_dendl_t endl = 0;
inline std::ostream& operator<<(std::ostream& out, _bad_endl_use_dendl_t) {
assert(0 && "you are using the wrong endl.. use std::endl or dendl");
return out;
}
// generic macros
#define debug_DOUT_SUBSYS debug
#define dout_prefix *_dout
#define DOUT_CONDVAR(cct, x) cct->_conf->debug_ ## x
#define XDOUT_CONDVAR(cct, x) DOUT_CONDVAR(cct, x)
#define DOUT_COND(cct, l) l <= XDOUT_CONDVAR(cct, DOUT_SUBSYS)
// The array declaration will trigger a compiler error if 'l' is
// out of range
#define dout_impl(cct, v) \
if (0) {\
char __array[((v >= -1) && (v <= 200)) ? 0 : -1] __attribute__((unused)); \
}\
DoutLocker __dout_locker; \
cct->dout_lock(&__dout_locker); \
_dout_begin_line(cct, v); \
#define ldout(cct, v) \
do { if (DOUT_COND(cct, v)) {\
dout_impl(cct, v) \
std::ostream* _dout = &(cct->_dout); \
dout_prefix
#define lpdout(cct, v, p) \
do { if ((v) <= (p)) {\
dout_impl(cct, v) \
std::ostream* _dout = &(cct->_dout); \
*_dout
#define lgeneric_dout(cct, v) \
lpdout(cct, v, cct->_conf->debug)
#define lderr(cct) ldout(cct, -1)
#define lgeneric_derr(cct) lgeneric_dout(cct, -1)
#define dendl std::endl; } } while (0)
#endif