Use atomic int for reference count in wxWebRequest classes
This is required because these classes are copied in both the main and the worker threads and using plain int is MT-unsafe.
This commit is contained in:
42
include/wx/private/refcountermt.h
Normal file
42
include/wx/private/refcountermt.h
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Name: wx/private/refcountermt.h
|
||||||
|
// Purpose: wxRefCounterMT class: MT-safe version of wxRefCounter
|
||||||
|
// Author: Vadim Zeitlin
|
||||||
|
// Created: 2021-01-11
|
||||||
|
// Copyright: (c) 2021 Vadim Zeitlin <vadim@wxwidgets.org>
|
||||||
|
// Licence: wxWindows licence
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#ifndef _WX_PRIVATE_REFCOUNTERMT_H_
|
||||||
|
#define _WX_PRIVATE_REFCOUNTERMT_H_
|
||||||
|
|
||||||
|
#include "wx/atomic.h"
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// Version of wxRefCounter with MT-safe count
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
class wxRefCounterMT
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
wxRefCounterMT() { m_count = 1; }
|
||||||
|
|
||||||
|
void IncRef() { wxAtomicInc(m_count); }
|
||||||
|
void DecRef()
|
||||||
|
{
|
||||||
|
if ( wxAtomicDec(m_count) == 0 )
|
||||||
|
delete this;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual ~wxRefCounterMT() { }
|
||||||
|
|
||||||
|
private:
|
||||||
|
// Ref count is atomic to allow IncRef() and DecRef() to be concurrently
|
||||||
|
// called from different threads.
|
||||||
|
wxAtomicInt m_count;
|
||||||
|
|
||||||
|
wxDECLARE_NO_COPY_CLASS(wxRefCounterMT);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // _WX_PRIVATE_REFCOUNTERMT_H_
|
@@ -14,13 +14,15 @@
|
|||||||
#include "wx/hashmap.h"
|
#include "wx/hashmap.h"
|
||||||
#include "wx/scopedptr.h"
|
#include "wx/scopedptr.h"
|
||||||
|
|
||||||
|
#include "wx/private/refcountermt.h"
|
||||||
|
|
||||||
WX_DECLARE_STRING_HASH_MAP(wxString, wxWebRequestHeaderMap);
|
WX_DECLARE_STRING_HASH_MAP(wxString, wxWebRequestHeaderMap);
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// wxWebAuthChallengeImpl
|
// wxWebAuthChallengeImpl
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
class wxWebAuthChallengeImpl : public wxRefCounter
|
class wxWebAuthChallengeImpl : public wxRefCounterMT
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~wxWebAuthChallengeImpl() { }
|
virtual ~wxWebAuthChallengeImpl() { }
|
||||||
@@ -43,7 +45,7 @@ private:
|
|||||||
// wxWebRequestImpl
|
// wxWebRequestImpl
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
class wxWebRequestImpl : public wxRefCounter
|
class wxWebRequestImpl : public wxRefCounterMT
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~wxWebRequestImpl() { }
|
virtual ~wxWebRequestImpl() { }
|
||||||
@@ -123,7 +125,7 @@ private:
|
|||||||
// wxWebResponseImpl
|
// wxWebResponseImpl
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
class wxWebResponseImpl : public wxRefCounter
|
class wxWebResponseImpl : public wxRefCounterMT
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~wxWebResponseImpl();
|
virtual ~wxWebResponseImpl();
|
||||||
@@ -190,7 +192,7 @@ public:
|
|||||||
// wxWebSessionImpl
|
// wxWebSessionImpl
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
class wxWebSessionImpl : public wxRefCounter
|
class wxWebSessionImpl : public wxRefCounterMT
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~wxWebSessionImpl() { }
|
virtual ~wxWebSessionImpl() { }
|
||||||
|
Reference in New Issue
Block a user