Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
S
spdlog
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
spdlog
Commits
d60e971d
Commit
d60e971d
authored
Feb 08, 2014
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
removed un needed mutex, and added copy ctors to line logger and friends
parent
514526ed
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
210 additions
and
208 deletions
+210
-208
makefile
build/gcc/makefile
+2
-2
fast_oss.h
include/c11log/details/fast_oss.h
+58
-50
line_logger.h
include/c11log/details/line_logger.h
+34
-16
logger.h
include/c11log/logger.h
+67
-69
base_sink.h
include/c11log/sinks/base_sink.h
+1
-1
stdafx.h
include/stdafx.h
+28
-27
factory.cpp
src/factory.cpp
+1
-0
line_logger.cpp
src/line_logger.cpp
+0
-21
test.cpp
src/test.cpp
+19
-22
No files found.
build/gcc/makefile
View file @
d60e971d
SRC_DIR
=
../../src
SRC_DIR
=
../../src
_SOURCES
=
factory.cpp formatters.cpp
line_logger.cpp
os.cpp
_SOURCES
=
factory.cpp formatters.cpp os.cpp
SOURCES
=
$
(
patsubst %,
$(SRC_DIR)
/%,
$(_SOURCES)
)
SOURCES
=
$
(
patsubst %,
$(SRC_DIR)
/%,
$(_SOURCES)
)
OBJS_RELEASE
=
$
(
patsubst %.cpp,release/%.o,
$(_SOURCES)
)
OBJS_RELEASE
=
$
(
patsubst %.cpp,release/%.o,
$(_SOURCES)
)
...
@@ -8,7 +8,7 @@ OBJS_DEBUG = $(patsubst %.cpp,debug/%.o,$(_SOURCES))
...
@@ -8,7 +8,7 @@ OBJS_DEBUG = $(patsubst %.cpp,debug/%.o,$(_SOURCES))
CXX
=
g++
CXX
=
g++
CXXFLAGS
=
-march
=
native
-Wall
-std
=
c++11
-pthread
-I
../../include
CXXFLAGS
=
-march
=
native
-Wall
-
Wextra
-Wshadow
-pedantic
-
std
=
c++11
-pthread
-I
../../include
CXX_RELEASE_FLAGS
=
-O2
-flto
-g
CXX_RELEASE_FLAGS
=
-O2
-flto
-g
CXX_DEBUG_FLAGS
=
-g
CXX_DEBUG_FLAGS
=
-g
...
...
include/c11log/details/fast_oss.h
View file @
d60e971d
...
@@ -2,72 +2,80 @@
...
@@ -2,72 +2,80 @@
#include<streambuf>
#include<streambuf>
#include<string>
#include<string>
namespace
c11log
{
namespace
c11log
namespace
details
{
{
namespace
details
{
class
str_devicebuf
:
public
std
::
streambuf
{
class
str_devicebuf
:
public
std
::
streambuf
{
public
:
public
:
str_devicebuf
()
=
default
;
str_devicebuf
()
=
default
;
~
str_devicebuf
()
=
default
;
~
str_devicebuf
()
=
default
;
str_devicebuf
(
const
str_devicebuf
&
)
=
delete
;
str_devicebuf
(
const
str_devicebuf
&
other
)
:
std
::
streambuf
(),
_str
(
other
.
_str
)
{}
str_devicebuf
&
operator
=
(
const
str_devicebuf
&
)
=
delete
;
str_devicebuf
&
operator
=
(
const
str_devicebuf
other
)
{
if
(
this
!=
&
other
)
_str
=
other
.
_str
;
return
*
this
;
}
const
std
::
string
&
str_ref
()
const
const
std
::
string
&
str_ref
()
const
{
{
return
_str
;
return
_str
;
}
}
void
clear
()
void
clear
()
{
{
_str
.
clear
();
_str
.
clear
();
}
}
protected
:
protected
:
virtual
int
sync
()
override
virtual
int
sync
()
override
{
{
return
0
;
return
0
;
}
}
virtual
std
::
streamsize
xsputn
(
const
char_type
*
s
,
std
::
streamsize
count
)
override
virtual
std
::
streamsize
xsputn
(
const
char_type
*
s
,
std
::
streamsize
count
)
override
{
{
_str
.
append
(
s
,
static_cast
<
unsigned
int
>
(
count
));
_str
.
append
(
s
,
static_cast
<
unsigned
int
>
(
count
));
return
count
;
return
count
;
}
}
virtual
int_type
overflow
(
int_type
ch
)
override
virtual
int_type
overflow
(
int_type
ch
)
override
{
{
if
(
ch
!=
traits_type
::
eof
())
if
(
ch
!=
traits_type
::
eof
())
_str
.
append
((
char
*
)
&
ch
,
1
);
_str
.
append
((
char
*
)
&
ch
,
1
);
return
1
;
return
1
;
}
}
private
:
private
:
std
::
string
_str
;
std
::
string
_str
;
};
};
class
fast_oss
:
public
std
::
ostream
{
class
fast_oss
:
public
std
::
ostream
{
public
:
public
:
fast_oss
()
:
std
::
ostream
(
&
_dev
){}
fast_oss
()
:
std
::
ostream
(
&
_dev
)
{}
~
fast_oss
()
=
default
;
~
fast_oss
()
=
default
;
fast_oss
(
const
fast_oss
&
)
=
delete
;
fast_oss
(
const
fast_oss
&
other
)
:
std
::
basic_ios
<
char
>
(),
std
::
ostream
(),
_dev
(
other
.
_dev
)
{}
fast_oss
operator
=
(
const
fast_oss
&
)
=
delete
;
fast_oss
operator
=
(
const
fast_oss
&
other
)
{
if
(
&
other
!=
this
)
_dev
=
other
.
_dev
;
return
*
this
;
}
const
std
::
string
&
str_ref
()
const
const
std
::
string
&
str_ref
()
const
{
{
return
_dev
.
str_ref
();
return
_dev
.
str_ref
();
}
}
const
std
::
string
str
()
const
const
std
::
string
str
()
const
{
{
return
_dev
.
str_ref
();
return
_dev
.
str_ref
();
}
}
void
clear
()
void
clear
()
{
{
_dev
.
clear
();
_dev
.
clear
();
}
}
private
:
private
:
str_devicebuf
_dev
;
str_devicebuf
_dev
;
};
};
}
}
}
}
include/c11log/details/line_logger.h
View file @
d60e971d
#pragma once
#pragma once
#include "../level.h"
#include "../level.h"
#include "../logger.h"
#include "fast_oss.h"
#include "fast_oss.h"
namespace
c11log
{
namespace
c11log
{
class
logger
;
class
logger
;
namespace
details
{
namespace
details
{
class
line_logger
{
class
line_logger
{
public
:
public
:
line_logger
(
logger
*
callback_logger
,
level
::
level_enum
msg_level
);
line_logger
(
logger
*
callback_logger
,
level
::
level_enum
msg_level
)
{
line_logger
(
logger
*
callback_logger
)
:
_callback_logger
(
nullptr
)
{};
callback_logger
->
formatter_
->
format_header
(
callback_logger
->
logger_name_
,
line_logger
(
const
line_logger
&
){};
msg_level
,
~
line_logger
();
c11log
::
formatters
::
clock
::
now
(),
_oss
);
}
line_logger
(
logger
*
)
:
_callback_logger
(
nullptr
)
{};
line_logger
(
const
line_logger
&
other
)
:
_callback_logger
(
other
.
_callback_logger
),
_oss
(
other
.
_oss
),
_level
(
other
.
_level
)
{};
line_logger
&
operator
=
(
const
line_logger
&
)
=
delete
;
~
line_logger
()
{
if
(
_callback_logger
)
{
_oss
<<
'\n'
;
_callback_logger
->
log_it_
(
_oss
.
str_ref
());
}
}
template
<
typename
T
>
template
<
typename
T
>
line_logger
&
operator
<<
(
const
T
&
msg
)
line_logger
&
operator
<<
(
const
T
&
msg
)
{
{
if
(
_callback_logger
)
if
(
_callback_logger
)
_oss
<<
msg
;
_oss
<<
msg
;
return
*
this
;
return
*
this
;
}
}
private
:
private
:
logger
*
_callback_logger
;
logger
*
_callback_logger
;
details
::
fast_oss
_oss
;
details
::
fast_oss
_oss
;
level
::
level_enum
_level
;
};
};
}
//Namespace details
}
//Namespace details
...
...
include/c11log/logger.h
View file @
d60e971d
...
@@ -10,157 +10,155 @@
...
@@ -10,157 +10,155 @@
#include "level.h"
#include "level.h"
#include "sinks/base_sink.h"
#include "sinks/base_sink.h"
#include "details/line_logger.h"
#include "details/factory.h"
#include "details/factory.h"
namespace
c11log
{
namespace
details
{
class
line_logger
;
}
class
logger
{
namespace
c11log
{
class
logger
{
public
:
public
:
typedef
std
::
shared_ptr
<
sinks
::
base_sink
>
sink_ptr_t
;
typedef
std
::
shared_ptr
<
sinks
::
base_sink
>
sink_ptr_t
;
typedef
std
::
vector
<
sink_ptr_t
>
sinks_vector_t
;
typedef
std
::
vector
<
sink_ptr_t
>
sinks_vector_t
;
explicit
logger
(
const
std
::
string
&
name
)
:
logger_name_
(
name
),
explicit
logger
(
const
std
::
string
&
name
)
:
logger_name_
(
name
),
formatter_
(
std
::
make_unique
<
formatters
::
default_formatter
>
())
formatter_
(
std
::
make_unique
<
formatters
::
default_formatter
>
())
{
{
atomic_level_
.
store
(
level
::
INFO
);
atomic_level_
.
store
(
level
::
INFO
);
}
}
~
logger
()
=
default
;
~
logger
()
=
default
;
logger
(
const
logger
&
)
=
delete
;
logger
(
const
logger
&
)
=
delete
;
logger
&
operator
=
(
const
logger
&
)
=
delete
;
logger
&
operator
=
(
const
logger
&
)
=
delete
;
void
set_name
(
const
std
::
string
&
name
);
void
set_name
(
const
std
::
string
&
name
);
const
std
::
string
&
get_name
();
const
std
::
string
&
get_name
();
void
add_sink
(
sink_ptr_t
sink_ptr
);
void
add_sink
(
sink_ptr_t
sink_ptr
);
void
remove_sink
(
sink_ptr_t
sink_ptr
);
void
remove_sink
(
sink_ptr_t
sink_ptr
);
void
set_formatter
(
std
::
unique_ptr
<
formatters
::
formatter
>
formatter
);
void
set_formatter
(
std
::
unique_ptr
<
formatters
::
formatter
>
formatter
);
void
set_level
(
c11log
::
level
::
level_enum
level
);
void
set_level
(
c11log
::
level
::
level_enum
level
);
c11log
::
level
::
level_enum
get_level
()
const
;
c11log
::
level
::
level_enum
get_level
()
const
;
bool
should_log
(
c11log
::
level
::
level_enum
level
)
const
;
bool
should_log
(
c11log
::
level
::
level_enum
level
)
const
;
details
::
line_logger
log
(
level
::
level_enum
level
);
details
::
line_logger
log
(
level
::
level_enum
level
);
details
::
line_logger
debug
();
details
::
line_logger
debug
();
details
::
line_logger
info
();
details
::
line_logger
info
();
details
::
line_logger
warn
();
details
::
line_logger
warn
();
details
::
line_logger
error
();
details
::
line_logger
error
();
details
::
line_logger
fatal
();
details
::
line_logger
fatal
();
private
:
private
:
friend
details
::
line_logger
;
friend
details
::
line_logger
;
std
::
string
logger_name_
=
""
;
std
::
string
logger_name_
=
""
;
std
::
unique_ptr
<
c11log
::
formatters
::
formatter
>
formatter_
;
std
::
unique_ptr
<
c11log
::
formatters
::
formatter
>
formatter_
;
sinks_vector_t
sinks_
;
sinks_vector_t
sinks_
;
std
::
mutex
mutex_
;
std
::
mutex
mutex_
;
std
::
atomic_int
atomic_level_
;
std
::
atomic_int
atomic_level_
;
void
log_it_
(
const
std
::
string
&
msg
);
void
log_it_
(
const
std
::
string
&
msg
);
};
};
logger
&
get_logger
(
const
std
::
string
&
name
);
logger
&
get_logger
(
const
std
::
string
&
name
);
}
}
#include "details/line_logger.h"
//
//
// Logger inline impl
// Logger inline impl
//
//
inline
c11log
::
details
::
line_logger
c11log
::
logger
::
log
(
c11log
::
level
::
level_enum
msg_level
)
inline
c11log
::
details
::
line_logger
c11log
::
logger
::
log
(
c11log
::
level
::
level_enum
msg_level
)
{
{
if
(
msg_level
>=
atomic_level_
.
load
())
if
(
msg_level
>=
atomic_level_
)
{
{
return
details
::
line_logger
(
this
,
msg_level
);
std
::
lock_guard
<
std
::
mutex
>
lock
(
mutex_
);
}
else
{
return
details
::
line_logger
(
this
,
msg_level
);
return
details
::
line_logger
(
nullptr
);
}
}
else
{
return
details
::
line_logger
(
nullptr
);
}
}
}
inline
c11log
::
details
::
line_logger
c11log
::
logger
::
debug
()
inline
c11log
::
details
::
line_logger
c11log
::
logger
::
debug
()
{
{
return
log
(
c11log
::
level
::
DEBUG
);
return
log
(
c11log
::
level
::
DEBUG
);
}
}
inline
c11log
::
details
::
line_logger
c11log
::
logger
::
info
()
inline
c11log
::
details
::
line_logger
c11log
::
logger
::
info
()
{
{
return
log
(
c11log
::
level
::
INFO
);
return
log
(
c11log
::
level
::
INFO
);
}
}
inline
c11log
::
details
::
line_logger
c11log
::
logger
::
warn
()
inline
c11log
::
details
::
line_logger
c11log
::
logger
::
warn
()
{
{
return
log
(
c11log
::
level
::
WARNING
);
return
log
(
c11log
::
level
::
WARNING
);
}
}
inline
c11log
::
details
::
line_logger
c11log
::
logger
::
error
()
inline
c11log
::
details
::
line_logger
c11log
::
logger
::
error
()
{
{
return
log
(
level
::
ERROR
);
return
log
(
level
::
ERROR
);
}
}
inline
c11log
::
details
::
line_logger
c11log
::
logger
::
fatal
()
inline
c11log
::
details
::
line_logger
c11log
::
logger
::
fatal
()
{
{
return
log
(
c11log
::
level
::
FATAL
);
return
log
(
c11log
::
level
::
FATAL
);
}
}
inline
void
c11log
::
logger
::
set_name
(
const
std
::
string
&
name
)
inline
void
c11log
::
logger
::
set_name
(
const
std
::
string
&
name
)
{
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
mutex_
);
std
::
lock_guard
<
std
::
mutex
>
lock
(
mutex_
);
logger_name_
=
name
;
logger_name_
=
name
;
}
}
inline
const
std
::
string
&
c11log
::
logger
::
get_name
()
inline
const
std
::
string
&
c11log
::
logger
::
get_name
()
{
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
mutex_
);
std
::
lock_guard
<
std
::
mutex
>
lock
(
mutex_
);
return
logger_name_
;
return
logger_name_
;
}
}
inline
void
c11log
::
logger
::
add_sink
(
sink_ptr_t
sink_ptr
)
inline
void
c11log
::
logger
::
add_sink
(
sink_ptr_t
sink_ptr
)
{
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
mutex_
);
std
::
lock_guard
<
std
::
mutex
>
lock
(
mutex_
);
sinks_
.
push_back
(
sink_ptr
);
sinks_
.
push_back
(
sink_ptr
);
}
}
inline
void
c11log
::
logger
::
remove_sink
(
sink_ptr_t
sink_ptr
)
inline
void
c11log
::
logger
::
remove_sink
(
sink_ptr_t
sink_ptr
)
{
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
mutex_
);
std
::
lock_guard
<
std
::
mutex
>
lock
(
mutex_
);
sinks_
.
erase
(
std
::
remove
(
sinks_
.
begin
(),
sinks_
.
end
(),
sink_ptr
),
sinks_
.
end
());
sinks_
.
erase
(
std
::
remove
(
sinks_
.
begin
(),
sinks_
.
end
(),
sink_ptr
),
sinks_
.
end
());
}
}
inline
void
c11log
::
logger
::
set_formatter
(
std
::
unique_ptr
<
formatters
::
formatter
>
formatter
)
inline
void
c11log
::
logger
::
set_formatter
(
std
::
unique_ptr
<
formatters
::
formatter
>
formatter
)
{
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
mutex_
);
std
::
lock_guard
<
std
::
mutex
>
lock
(
mutex_
);
formatter_
=
std
::
move
(
formatter
);
formatter_
=
std
::
move
(
formatter
);
}
}
inline
void
c11log
::
logger
::
set_level
(
c11log
::
level
::
level_enum
level
)
inline
void
c11log
::
logger
::
set_level
(
c11log
::
level
::
level_enum
level
)
{
{
atomic_level_
.
store
(
level
);
atomic_level_
.
store
(
level
);
}
}
inline
c11log
::
level
::
level_enum
c11log
::
logger
::
get_level
()
const
inline
c11log
::
level
::
level_enum
c11log
::
logger
::
get_level
()
const
{
{
return
static_cast
<
c11log
::
level
::
level_enum
>
(
atomic_level_
.
load
());
return
static_cast
<
c11log
::
level
::
level_enum
>
(
atomic_level_
.
load
());
}
}
inline
bool
c11log
::
logger
::
should_log
(
c11log
::
level
::
level_enum
level
)
const
inline
bool
c11log
::
logger
::
should_log
(
c11log
::
level
::
level_enum
level
)
const
{
{
return
level
>=
atomic_level_
.
load
();
return
level
>=
atomic_level_
.
load
();
}
}
inline
void
c11log
::
logger
::
log_it_
(
const
std
::
string
&
msg
)
inline
void
c11log
::
logger
::
log_it_
(
const
std
::
string
&
msg
)
{
{
level
::
level_enum
level
=
static_cast
<
level
::
level_enum
>
(
atomic_level_
.
load
());
level
::
level_enum
level
=
static_cast
<
level
::
level_enum
>
(
atomic_level_
.
load
());
std
::
lock_guard
<
std
::
mutex
>
lock
(
mutex_
);
std
::
lock_guard
<
std
::
mutex
>
lock
(
mutex_
);
for
(
auto
&
sink
:
sinks_
)
for
(
auto
&
sink
:
sinks_
)
sink
->
log
(
msg
,
level
);
sink
->
log
(
msg
,
level
);
}
}
// Static factory function
// Static factory function
inline
c11log
::
logger
&
c11log
::
get_logger
(
const
std
::
string
&
name
)
inline
c11log
::
logger
&
c11log
::
get_logger
(
const
std
::
string
&
name
)
{
{
return
*
(
c11log
::
details
::
factory
::
instance
().
get_logger
(
name
));
return
*
(
c11log
::
details
::
factory
::
instance
().
get_logger
(
name
));
}
}
include/c11log/sinks/base_sink.h
View file @
d60e971d
...
@@ -37,7 +37,7 @@ protected:
...
@@ -37,7 +37,7 @@ protected:
class
null_sink
:
public
base_sink
{
class
null_sink
:
public
base_sink
{
protected
:
protected
:
void
sink_it_
(
const
std
::
string
&
msg
)
override
void
sink_it_
(
const
std
::
string
&
)
override
{}
{}
};
};
}
}
...
...
include/stdafx.h
View file @
d60e971d
// stdafx.h : include file for standard system include files,
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// or project specific include files that are used frequently, but
// are changed infrequently
// are changed infrequently
//
//
#pragma once
#pragma once
#ifdef _MSC_VER
#ifdef _MSC_VER
#include "targetver.h"
#include "targetver.h"
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#endif
#endif
#include <string>
#include <string>
#include <chrono>
#include <chrono>
#include <ctime>
#include <ctime>
#include <memory>
#include <memory>
#include <iostream>
#include <iostream>
#ifndef _MSC_VER
#ifndef _MSC_VER
namespace
std
{
namespace
std
template
<
typename
T
,
typename
...
Args
>
{
std
::
unique_ptr
<
T
>
make_unique
(
Args
&&
...
args
)
template
<
typename
T
,
typename
...
Args
>
{
std
::
unique_ptr
<
T
>
make_unique
(
Args
&&
...
args
)
return
std
::
unique_ptr
<
T
>
(
new
T
(
std
::
forward
<
Args
>
(
args
)...
)
);
{
}
return
std
::
unique_ptr
<
T
>
(
new
T
(
std
::
forward
<
Args
>
(
args
)...
)
);
}
}
#endif
}
#endif
src/factory.cpp
View file @
d60e971d
...
@@ -19,5 +19,6 @@ c11log::details::factory::logger_ptr c11log::details::factory::get_logger(const
...
@@ -19,5 +19,6 @@ c11log::details::factory::logger_ptr c11log::details::factory::get_logger(const
c11log
::
details
::
factory
&
c11log
::
details
::
factory
::
instance
()
c11log
::
details
::
factory
&
c11log
::
details
::
factory
::
instance
()
{
{
static
c11log
::
details
::
factory
instance
;
static
c11log
::
details
::
factory
instance
;
return
instance
;
return
instance
;
}
}
src/line_logger.cpp
deleted
100644 → 0
View file @
514526ed
#include "stdafx.h"
#include "c11log/logger.h"
c11log
::
details
::
line_logger
::
line_logger
(
logger
*
callback_logger
,
level
::
level_enum
msg_level
)
:
_callback_logger
(
callback_logger
)
{
if
(
callback_logger
)
{
callback_logger
->
formatter_
->
format_header
(
callback_logger
->
logger_name_
,
msg_level
,
c11log
::
formatters
::
clock
::
now
(),
_oss
);
}
}
c11log
::
details
::
line_logger
::~
line_logger
()
{
if
(
_callback_logger
)
{
_oss
<<
'\n'
;
_callback_logger
->
log_it_
(
_oss
.
str_ref
());
}
}
src/test.cpp
View file @
d60e971d
...
@@ -20,38 +20,37 @@ using std::string;
...
@@ -20,38 +20,37 @@ using std::string;
using
std
::
chrono
::
seconds
;
using
std
::
chrono
::
seconds
;
using
Q
=
c11log
::
details
::
blocking_queue
<
string
>
;
using
Q
=
c11log
::
details
::
blocking_queue
<
string
>
;
void
pusher
(
Q
*
q
)
void
pusher
(
Q
*
)
{
{
auto
&
logger
=
c11log
::
get_logger
(
"async"
);
auto
&
logger
=
c11log
::
get_logger
(
"async"
);
while
(
active
)
while
(
active
)
{
{
logger
.
info
()
<<
"Hello logger!"
;
logger
.
info
()
<<
"Hello logger!"
;
++
push_count
;
++
push_count
;
}
}
}
}
void
testq
(
int
size
,
int
pushers
,
int
poppers
)
void
testq
(
int
size
,
int
pushers
,
int
poppers
)
{
{
active
=
true
;
active
=
true
;
Q
q
{
static_cast
<
Q
::
size_type
>
(
size
)};
Q
q
{
static_cast
<
Q
::
size_type
>
(
size
)};
/*
/*
for(int i = 0; i < poppers; i++)
for(int i = 0; i < poppers; i++)
testq(qsize, pushers, poppers);
testq(qsize, pushers, poppers);
*/
*/
for
(
int
i
=
0
;
i
<
pushers
;
i
++
)
for
(
int
i
=
0
;
i
<
pushers
;
i
++
)
new
std
::
thread
(
std
::
bind
(
pusher
,
&
q
));
new
std
::
thread
(
std
::
bind
(
pusher
,
&
q
));
while
(
active
)
while
(
active
)
{
{
using
std
::
endl
;
using
std
::
endl
;
using
std
::
cout
;
using
std
::
cout
;
using
utils
::
format
;
using
utils
::
format
;
push_count
=
0
;
push_count
=
0
;
pop_count
=
0
;
pop_count
=
0
;
std
::
this_thread
::
sleep_for
(
seconds
(
1
));
std
::
this_thread
::
sleep_for
(
seconds
(
1
));
...
@@ -59,8 +58,8 @@ void testq(int size, int pushers, int poppers)
...
@@ -59,8 +58,8 @@ void testq(int size, int pushers, int poppers)
//cout << "Pops/sec =\t" << format(pop_count.load()) << endl << endl;
//cout << "Pops/sec =\t" << format(pop_count.load()) << endl << endl;
//cout << "Total/sec =\t" << format(push_count+pop_count) << endl;
//cout << "Total/sec =\t" << format(push_count+pop_count) << endl;
cout
<<
"Queue size =
\t
"
<<
format
(
q
.
size
())
<<
endl
;
cout
<<
"Queue size =
\t
"
<<
format
(
q
.
size
())
<<
endl
;
cout
<<
"---------------------------------------------------------------------"
<<
endl
;
cout
<<
"---------------------------------------------------------------------"
<<
endl
;
}
}
}
}
...
@@ -75,26 +74,24 @@ int main(int argc, char* argv[])
...
@@ -75,26 +74,24 @@ int main(int argc, char* argv[])
int
qsize
=
atoi
(
argv
[
1
]);
int
qsize
=
atoi
(
argv
[
1
]);
int
pushers
=
atoi
(
argv
[
2
]);
int
pushers
=
atoi
(
argv
[
2
]);
int
poppers
=
atoi
(
argv
[
3
]);
int
poppers
=
atoi
(
argv
[
3
]);
//testq(qsize, pushers, poppers);
//testq(qsize, pushers, poppers);
using
namespace
std
::
chrono
;
using
namespace
std
::
chrono
;
auto
null_sink
=
std
::
make_shared
<
c11log
::
sinks
::
null_sink
>
();
auto
null_sink
=
std
::
make_shared
<
c11log
::
sinks
::
null_sink
>
();
auto
stdout_sink
=
std
::
make_shared
<
c11log
::
sinks
::
stdout_sink
>
();
auto
stdout_sink
=
std
::
make_shared
<
c11log
::
sinks
::
stdout_sink
>
();
auto
async
=
std
::
make_shared
<
c11log
::
sinks
::
async_sink
>
(
1000
);
auto
async
=
std
::
make_shared
<
c11log
::
sinks
::
async_sink
>
(
1000
);
auto
fsink
=
std
::
make_shared
<
c11log
::
sinks
::
rotating_file_sink
>
(
"newlog"
,
"txt"
,
1024
*
1024
*
10
,
2
);
auto
fsink
=
std
::
make_shared
<
c11log
::
sinks
::
rotating_file_sink
>
(
"newlog"
,
"txt"
,
1024
*
1024
*
10
,
2
);
//auto fsink = std::make_shared<c11log::sinks::daily_file_sink>("daily", "txt");
//auto fsink = std::make_shared<c11log::sinks::daily_file_sink>("daily", "txt");
async
->
add_sink
(
fsink
);
async
->
add_sink
(
null_sink
);
auto
&
logger
=
c11log
::
get_logger
(
"async"
);
auto
&
logger
=
c11log
::
get_logger
(
"async"
);
logger
.
add_sink
(
async
);
logger
.
add_sink
(
async
);
testq
(
qsize
,
pushers
,
poppers
);
testq
(
qsize
,
pushers
,
poppers
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment