Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions base/base/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@
# define TSA_ACQUIRE_SHARED(...) __attribute__((acquire_shared_capability(__VA_ARGS__))) /// function acquires a shared capability, but does not release it
# define TSA_TRY_ACQUIRE_SHARED(...) __attribute__((try_acquire_shared_capability(__VA_ARGS__))) /// function tries to acquire a shared capability and returns a boolean value indicating success or failure
# define TSA_RELEASE_SHARED(...) __attribute__((release_shared_capability(__VA_ARGS__))) /// function releases the given shared capability
# define TSA_SCOPED_LOCKABLE __attribute__((scoped_lockable)) /// object of a class has scoped lockable capability

/// Macros for suppressing TSA warnings for specific reads/writes (instead of suppressing it for the whole function)
/// They use a lambda function to apply function attribute to a single statement. This enable us to suppress warnings locally instead of
Expand Down Expand Up @@ -182,6 +183,7 @@
# define TSA_ACQUIRE_SHARED(...)
# define TSA_TRY_ACQUIRE_SHARED(...)
# define TSA_RELEASE_SHARED(...)
# define TSA_SCOPED_LOCKABLE(...)

# define TSA_SUPPRESS_WARNING_FOR_READ(x) (x)
# define TSA_SUPPRESS_WARNING_FOR_WRITE(x) (x)
Expand Down
26 changes: 13 additions & 13 deletions base/poco/Foundation/include/Poco/Logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ namespace Poco


class Exception;

class Logger;
using LoggerPtr = std::shared_ptr<Logger>;

class Foundation_API Logger : public Channel
/// Logger is a special Channel that acts as the main
Expand Down Expand Up @@ -870,6 +871,11 @@ class Foundation_API Logger : public Channel
/// If the Logger does not yet exist, it is created, based
/// on its parent logger.

static LoggerPtr getShared(const std::string & name);
/// Returns a shared pointer to the Logger with the given name.
/// If the Logger does not yet exist, it is created, based
/// on its parent logger.

static Logger & unsafeGet(const std::string & name);
/// Returns a reference to the Logger with the given name.
/// If the Logger does not yet exist, it is created, based
Expand All @@ -885,6 +891,11 @@ class Foundation_API Logger : public Channel
/// given name. The Logger's Channel and log level as set as
/// specified.

static LoggerPtr createShared(const std::string & name, Channel * pChannel, int level = Message::PRIO_INFORMATION);
/// Creates and returns a shared pointer to a Logger with the
/// given name. The Logger's Channel and log level as set as
/// specified.

static Logger & root();
/// Returns a reference to the root logger, which is the ultimate
/// ancestor of all Loggers.
Expand All @@ -893,13 +904,6 @@ class Foundation_API Logger : public Channel
/// Returns a pointer to the Logger with the given name if it
/// exists, or a null pointer otherwise.

static void destroy(const std::string & name);
/// Destroys the logger with the specified name. Does nothing
/// if the logger is not found.
///
/// After a logger has been destroyed, all references to it
/// become invalid.

static void shutdown();
/// Shuts down the logging framework and releases all
/// Loggers.
Expand Down Expand Up @@ -929,15 +933,14 @@ class Foundation_API Logger : public Channel
static const std::string ROOT; /// The name of the root logger ("").

protected:
typedef std::map<std::string, Logger *> LoggerMap;

Logger(const std::string & name, Channel * pChannel, int level);
~Logger();

void log(const std::string & text, Message::Priority prio);
void log(const std::string & text, Message::Priority prio, const char * file, int line);

static std::string format(const std::string & fmt, int argc, std::string argv[]);
static Logger & unsafeCreate(const std::string & name, Channel * pChannel, int level = Message::PRIO_INFORMATION);
static Logger & parent(const std::string & name);
static void add(Logger * pLogger);
static Logger * find(const std::string & name);
Expand All @@ -950,9 +953,6 @@ class Foundation_API Logger : public Channel
std::string _name;
Channel * _pChannel;
std::atomic_int _level;

static LoggerMap * _pLoggerMap;
static Mutex _mapMtx;
};


Expand Down
28 changes: 16 additions & 12 deletions base/poco/Foundation/include/Poco/RefCountedObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ class Foundation_API RefCountedObject
/// Creates the RefCountedObject.
/// The initial reference count is one.

void duplicate() const;
/// Increments the object's reference count.
size_t duplicate() const;
/// Increments the object's reference count, returns reference count before call.

void release() const throw();
size_t release() const throw();
/// Decrements the object's reference count
/// and deletes the object if the count
/// reaches zero.
/// reaches zero, returns reference count before call.

int referenceCount() const;
size_t referenceCount() const;
/// Returns the reference count.

protected:
Expand All @@ -57,36 +57,40 @@ class Foundation_API RefCountedObject
RefCountedObject(const RefCountedObject &);
RefCountedObject & operator=(const RefCountedObject &);

mutable AtomicCounter _counter;
mutable std::atomic<size_t> _counter;
};


//
// inlines
//
inline int RefCountedObject::referenceCount() const
inline size_t RefCountedObject::referenceCount() const
{
return _counter.value();
return _counter.load(std::memory_order_acquire);
}


inline void RefCountedObject::duplicate() const
inline size_t RefCountedObject::duplicate() const
{
++_counter;
return _counter.fetch_add(1, std::memory_order_acq_rel);
}


inline void RefCountedObject::release() const throw()
inline size_t RefCountedObject::release() const throw()
{
size_t reference_count_before = _counter.fetch_sub(1, std::memory_order_acq_rel);

try
{
if (--_counter == 0)
if (reference_count_before == 1)
delete this;
}
catch (...)
{
poco_unexpected();
}

return reference_count_before;
}


Expand Down
Loading