8000 Merge pull request #386 from wilx/master · log4cplus/log4cplus@cff5bc2 · GitHub
[go: up one dir, main page]

Skip to content

Commit cff5bc2

Browse files
authored
Merge pull request #386 from wilx/master
Merge.
2 parents 3e22587 + 3fbadc5 commit cff5bc2

File tree

4 files changed

+78
-8
lines changed

4 files changed

+78
-8
lines changed

include/log4cplus/thread/threads.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,21 @@ LOG4CPLUS_EXPORT void setCurrentThreadName2(const log4cplus::tstring & name);
4747
LOG4CPLUS_EXPORT void yield();
4848
LOG4CPLUS_EXPORT void blockAllSignals();
4949

50+
/**
51+
* This class blocks all POSIX signals when created and unblocks them when
52+
* destroyed.
53+
*/
54+
class LOG4CPLUS_EXPORT SignalsBlocker
55+
{
56+
public:
57+
SignalsBlocker();
58+
~SignalsBlocker();
59+
60+
private:
61+
struct SignalsBlockerImpl;
62+
std::unique_ptr<SignalsBlockerImpl> impl;
63+
};
64+
5065

5166
#ifndef LOG4CPLUS_SINGLE_THREADED
5267

src/global-init.cxx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,17 @@ Initializer::~Initializer ()
131131
namespace
132132
{
133133

134+
#if ! defined (LOG4CPLUS_SINGLE_THREADED)
135+
static
136+
std::unique_ptr<progschj::ThreadPool>
137+
instantiate_thread_pool ()
138+
{
139+
log4cplus::thread::SignalsBlocker sb;
140+
return std::unique_ptr<progschj::ThreadPool>(new progschj::ThreadPool);
141+
}
142+
#endif
143+
144+
134145
//! Default context.
135146
struct DefaultContext
136147
{
@@ -146,7 +157,7 @@ struct DefaultContext
146157
spi::FilterFactoryRegistry filter_factory_registry;
147158
spi::LocaleFactoryRegistry locale_factory_registry;
148159
#if ! defined (LOG4CPLUS_SINGLE_THREADED)
149-
std::unique_ptr<progschj::ThreadPool> thread_pool {new progschj::ThreadPool};
160+
std::unique_ptr<progschj::ThreadPool> thread_pool {instantiate_thread_pool ()};
150161
#endif
151162
Hierarchy hierarchy;
152163
};
@@ -562,7 +573,7 @@ threadCleanup ()
562573

563574

564575
void
565-
setThreadPoolSize (std::size_t pool_size)
576+
setThreadPoolSize (std::size_t LOG4CPLUS_THREADED (pool_size))
566577
{
567578
#if ! defined (LOG4CPLUS_SINGLE_THREADED)
568579
get_dc ()->thread_pool->set_pool_size (pool_size);

src/threads.cxx

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,10 @@
5353
#include <log4cplus/internal/cygwin-win32.h>
5454
#include <log4cplus/streams.h>
5555

56+
#include <log4cplus/thread/threads.h>
57+
5658
#ifndef LOG4CPLUS_SINGLE_THREADED
5759

58-
#include <log4cplus/thread/threads.h>
5960
#include <log4cplus/thread/impl/threads-impl.h>
6061
#include <log4cplus/thread/impl/tls.h>
6162
#include <log4cplus/ndc.h>
@@ -202,6 +203,37 @@ LOG4CPLUS_EXPORT void setCurrentThreadName2(const log4cplus::tstring & name)
202203
}
203204

204205

206+
//
207+
//
208+
//
209+
210+
struct SignalsBlocker::SignalsBlockerImpl
211+
{
212+
#if defined (LOG4CPLUS_USE_PTHREADS)
213+
sigset_t signal_set;
214+
#endif
215+
};
216+
217+
218+
SignalsBlocker::SignalsBlocker ()
219+
: impl (new SignalsBlocker::SignalsBlockerImpl)
220+
{
221+
#if defined (LOG4CPLUS_USE_PTHREADS)
222+
sigset_t block_all_set;
223+
sigfillset (&block_all_set);
224+
(void) pthread_sigmask (SIG_BLOCK, &block_all_set, &impl->signal_set);
225+
#endif
226+
}
227+
228+
229+
SignalsBlocker::~SignalsBlocker()
230+
{
231+
#if defined (LOG4CPLUS_USE_PTHREADS)
232+
(void) pthread_sigmask (SIG_BLOCK, &impl->signal_set, nullptr);
233+
#endif
234+
}
235+
236+
205237
#ifndef LOG4CPLUS_SINGLE_THREADED
206238

207239
//

src/version.cxx

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
// Copyright (C) 2010-2017, Vaclav Haisman. All rights reserved.
2-
//
2+
//
33
// Redistribution and use in source and binary forms, with or without modifica-
44
// tion, are permitted provided that the following conditions are met:
5-
//
5+
//
66
// 1. Redistributions of source code must retain the above copyright notice,
77
// this list of conditions and the following disclaimer.
8-
//
8+
//
99
// 2. Redistributions in binary form must reproduce the above copyright notice,
1010
// this list of conditions and the following disclaimer in the documentation
1111
// and/or other materials provided with the distribution.
12-
//
12+
//
1313
// THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
1414
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
1515
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
@@ -34,4 +34,16 @@ namespace log4cplus
3434
unsigned const version = LOG4CPLUS_VERSION;
3535
char const versionStr[] = LOG4CPLUS_VERSION_STR LOG4CPLUS_VERSION_STR_SUFFIX;
3636

37-
}
37+
namespace
38+
{
39+
40+
#if defined (__ELF__) && (defined (__GNUC__) || defined (__clang__))
41+
char const versionStrComment[]
42+
__attribute__ ((__used__, __section__ ((".comment"))))
43+
= "log4cplus " LOG4CPLUS_VERSION_STR LOG4CPLUS_VERSION_STR_SUFFIX;
44+
#endif
45+
46+
47+
} // namespace
48+
49+
} // namespace log4cplus

0 commit comments

Comments
 (0)
0