Commit 32a96ddb authored by elelel's avatar elelel Committed by Davis E. King

Replace shared_ptr_thread_safe with std::shared_ptr (#590)

* Replace shared_ptr/weak_ptr with stdlib counterparts

* Fix ptr usage through tests compilation

* Bring back dlib smart ptrs as legacy

* Include scoped_ptr directly

* Add explanation about smart_ptr deprecation

* Replace shared_ptr_thread_safe

* Fix missed old include

* Removed missed old include
parent 74f9f2fb
...@@ -17,16 +17,17 @@ ...@@ -17,16 +17,17 @@
#pragma comment (lib, "imm32.lib") #pragma comment (lib, "imm32.lib")
#endif #endif
#include <cmath>
#include <memory>
#include <sstream> #include <sstream>
#include <vector>
#include "../threads.h" #include "../threads.h"
#include "../assert.h" #include "../assert.h"
#include "../queue.h" #include "../queue.h"
#include "../sync_extension.h" #include "../sync_extension.h"
#include "../queue.h" #include "../queue.h"
#include "../logger.h" #include "../logger.h"
#include <cmath>
#include <vector>
namespace dlib namespace dlib
{ {
...@@ -63,9 +64,9 @@ namespace dlib ...@@ -63,9 +64,9 @@ namespace dlib
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
const shared_ptr_thread_safe<dlib::mutex>& global_mutex() const std::shared_ptr<dlib::mutex>& global_mutex()
{ {
static shared_ptr_thread_safe<dlib::mutex> m(new dlib::mutex); static std::shared_ptr<dlib::mutex> m(new dlib::mutex);
return m; return m;
} }
...@@ -118,7 +119,7 @@ namespace dlib ...@@ -118,7 +119,7 @@ namespace dlib
// processing. // processing.
thread_id_type event_thread_id; thread_id_type event_thread_id;
shared_ptr_thread_safe<dlib::mutex> reference_to_global_mutex; std::shared_ptr<dlib::mutex> reference_to_global_mutex;
event_handler_thread( event_handler_thread(
) : ) :
...@@ -288,10 +289,10 @@ namespace dlib ...@@ -288,10 +289,10 @@ namespace dlib
struct call_global_mutex { call_global_mutex() { global_mutex(); } }; struct call_global_mutex { call_global_mutex() { global_mutex(); } };
static call_global_mutex call_global_mutex_instance; static call_global_mutex call_global_mutex_instance;
const shared_ptr_thread_safe<event_handler_thread>& global_data() const std::shared_ptr<event_handler_thread>& global_data()
{ {
auto_mutex M(*global_mutex()); auto_mutex M(*global_mutex());
static shared_ptr_thread_safe<event_handler_thread> p; static std::shared_ptr<event_handler_thread> p;
if (p.get() == 0) if (p.get() == 0)
{ {
p.reset(new event_handler_thread()); p.reset(new event_handler_thread());
...@@ -671,7 +672,7 @@ namespace dlib ...@@ -671,7 +672,7 @@ namespace dlib
SetThreadPriority(hand,THREAD_PRIORITY_ABOVE_NORMAL); SetThreadPriority(hand,THREAD_PRIORITY_ABOVE_NORMAL);
CloseHandle(hand); CloseHandle(hand);
shared_ptr_thread_safe<event_handler_thread> globals(global_data()); std::shared_ptr<event_handler_thread> globals(global_data());
window_table_type& window_table = globals->window_table; window_table_type& window_table = globals->window_table;
HWND& helper_window = globals->helper_window; HWND& helper_window = globals->helper_window;
...@@ -1465,7 +1466,7 @@ namespace dlib ...@@ -1465,7 +1466,7 @@ namespace dlib
!*/ !*/
{ {
using namespace gui_core_kernel_1_globals; using namespace gui_core_kernel_1_globals;
shared_ptr_thread_safe<event_handler_thread> globals(global_data()); std::shared_ptr<event_handler_thread> globals(global_data());
// if we are running in the event handling thread then just call // if we are running in the event handling thread then just call
// CreateWindow directly // CreateWindow directly
if (get_thread_id() == globals->event_thread_id) if (get_thread_id() == globals->event_thread_id)
...@@ -2071,7 +2072,7 @@ namespace dlib ...@@ -2071,7 +2072,7 @@ namespace dlib
using namespace gui_core_kernel_1_globals; using namespace gui_core_kernel_1_globals;
using namespace std; using namespace std;
shared_ptr_thread_safe<event_handler_thread> globals(global_data()); std::shared_ptr<event_handler_thread> globals(global_data());
if (OpenClipboard(globals->helper_window)) if (OpenClipboard(globals->helper_window))
{ {
...@@ -2138,7 +2139,7 @@ namespace dlib ...@@ -2138,7 +2139,7 @@ namespace dlib
{ {
using namespace gui_core_kernel_1_globals; using namespace gui_core_kernel_1_globals;
using namespace std; using namespace std;
shared_ptr_thread_safe<event_handler_thread> globals(global_data()); std::shared_ptr<event_handler_thread> globals(global_data());
auto_mutex M(globals->window_table.get_mutex()); auto_mutex M(globals->window_table.get_mutex());
if (OpenClipboard(globals->helper_window)) if (OpenClipboard(globals->helper_window))
......
...@@ -11,7 +11,9 @@ ...@@ -11,7 +11,9 @@
#error "DLIB_NO_GUI_SUPPORT is defined so you can't use the GUI code. Turn DLIB_NO_GUI_SUPPORT off if you want to use it." #error "DLIB_NO_GUI_SUPPORT is defined so you can't use the GUI code. Turn DLIB_NO_GUI_SUPPORT off if you want to use it."
#endif #endif
#include <memory>
#include <string> #include <string>
#include "../windows_magic.h" #include "../windows_magic.h"
...@@ -39,8 +41,6 @@ ...@@ -39,8 +41,6 @@
#include "../queue.h" #include "../queue.h"
#include "../pixel.h" #include "../pixel.h"
#include "../unicode.h" #include "../unicode.h"
#include "../smart_pointers_thread_safe.h"
namespace dlib namespace dlib
{ {
...@@ -169,7 +169,7 @@ namespace dlib ...@@ -169,7 +169,7 @@ namespace dlib
class base_window class base_window
{ {
friend LRESULT CALLBACK gui_core_kernel_1_globals::WndProc (HWND, UINT, WPARAM, LPARAM); friend LRESULT CALLBACK gui_core_kernel_1_globals::WndProc (HWND, UINT, WPARAM, LPARAM);
shared_ptr_thread_safe<gui_core_kernel_1_globals::event_handler_thread> globals; std::shared_ptr<gui_core_kernel_1_globals::event_handler_thread> globals;
HWND hwnd; HWND hwnd;
DWORD style; DWORD style;
......
...@@ -8,24 +8,25 @@ ...@@ -8,24 +8,25 @@
#include "gui_core_kernel_2.h" #include "gui_core_kernel_2.h"
#include <cmath>
#include <cstring>
#include <iostream>
#include <vector>
#include <set>
#include <X11/Xatom.h>
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <X11/Xutil.h> #include <X11/Xutil.h>
#include <X11/keysym.h> #include <X11/keysym.h>
#include <X11/Xlocale.h> #include <X11/Xlocale.h>
#include <X11/XKBlib.h> #include <X11/XKBlib.h>
#include <poll.h> #include <poll.h>
#include <iostream>
#include "../assert.h" #include "../assert.h"
#include "../queue.h" #include "../queue.h"
#include <cstring>
#include <cmath>
#include <X11/Xatom.h>
#include "../sync_extension.h" #include "../sync_extension.h"
#include "../logger.h" #include "../logger.h"
#include <vector>
#include <set>
#include "../smart_pointers_thread_safe.h"
namespace dlib namespace dlib
{ {
...@@ -49,9 +50,9 @@ namespace dlib ...@@ -49,9 +50,9 @@ namespace dlib
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
const shared_ptr_thread_safe<dlib::mutex>& global_mutex() const std::shared_ptr<dlib::mutex>& global_mutex()
{ {
static shared_ptr_thread_safe<dlib::mutex> m(new dlib::mutex); static std::shared_ptr<dlib::mutex> m(new dlib::mutex);
return m; return m;
} }
...@@ -95,7 +96,7 @@ namespace dlib ...@@ -95,7 +96,7 @@ namespace dlib
queue_of_user_events user_events; queue_of_user_events user_events;
queue_of_user_events user_events_temp; queue_of_user_events user_events_temp;
shared_ptr_thread_safe<dlib::mutex> reference_to_global_mutex; std::shared_ptr<dlib::mutex> reference_to_global_mutex;
event_handler_thread( event_handler_thread(
) : ) :
...@@ -315,7 +316,7 @@ namespace dlib ...@@ -315,7 +316,7 @@ namespace dlib
Time last_click_time; Time last_click_time;
XIC xic; XIC xic;
XFontSet fs; XFontSet fs;
shared_ptr_thread_safe<event_handler_thread> globals; std::shared_ptr<event_handler_thread> globals;
}; };
// Do all this just to make sure global_mutex() is initialized at program start // Do all this just to make sure global_mutex() is initialized at program start
...@@ -324,10 +325,10 @@ namespace dlib ...@@ -324,10 +325,10 @@ namespace dlib
struct call_global_mutex { call_global_mutex() { global_mutex(); } }; struct call_global_mutex { call_global_mutex() { global_mutex(); } };
static call_global_mutex call_global_mutex_instance; static call_global_mutex call_global_mutex_instance;
const shared_ptr_thread_safe<event_handler_thread>& global_data() const std::shared_ptr<event_handler_thread>& global_data()
{ {
auto_mutex M(*global_mutex()); auto_mutex M(*global_mutex());
static shared_ptr_thread_safe<event_handler_thread> p; static std::shared_ptr<event_handler_thread> p;
if (p.get() == 0) if (p.get() == 0)
p.reset(new event_handler_thread()); p.reset(new event_handler_thread());
return p; return p;
...@@ -1356,7 +1357,7 @@ namespace dlib ...@@ -1356,7 +1357,7 @@ namespace dlib
{ {
using namespace gui_core_kernel_2_globals; using namespace gui_core_kernel_2_globals;
shared_ptr_thread_safe<event_handler_thread> globals(global_data()); std::shared_ptr<event_handler_thread> globals(global_data());
auto_mutex M(globals->window_table.get_mutex()); auto_mutex M(globals->window_table.get_mutex());
globals->clipboard = str.c_str(); globals->clipboard = str.c_str();
...@@ -1405,7 +1406,7 @@ namespace dlib ...@@ -1405,7 +1406,7 @@ namespace dlib
) )
{ {
using namespace gui_core_kernel_2_globals; using namespace gui_core_kernel_2_globals;
shared_ptr_thread_safe<event_handler_thread> globals(global_data()); std::shared_ptr<event_handler_thread> globals(global_data());
auto_mutex M(globals->window_table.get_mutex()); auto_mutex M(globals->window_table.get_mutex());
str.clear(); str.clear();
...@@ -1495,7 +1496,7 @@ namespace dlib ...@@ -1495,7 +1496,7 @@ namespace dlib
void* void*
) )
{ {
shared_ptr_thread_safe<event_handler_thread> globals(global_data()); std::shared_ptr<event_handler_thread> globals(global_data());
auto_mutex M(globals->window_table.get_mutex()); auto_mutex M(globals->window_table.get_mutex());
globals->user_events.lock(); globals->user_events.lock();
...@@ -1536,7 +1537,7 @@ namespace dlib ...@@ -1536,7 +1537,7 @@ namespace dlib
e.p = p; e.p = p;
e.i = i; e.i = i;
{ {
shared_ptr_thread_safe<event_handler_thread> globals(global_data()); std::shared_ptr<event_handler_thread> globals(global_data());
auto_mutex M(globals->user_events.get_mutex()); auto_mutex M(globals->user_events.get_mutex());
globals->user_events.enqueue(e); globals->user_events.enqueue(e);
......
...@@ -3,10 +3,11 @@ ...@@ -3,10 +3,11 @@
#ifndef DLIB_BASE_WIDGETs_CPP_ #ifndef DLIB_BASE_WIDGETs_CPP_
#define DLIB_BASE_WIDGETs_CPP_ #define DLIB_BASE_WIDGETs_CPP_
#include "base_widgets.h"
#include "../assert.h"
#include <iostream> #include <iostream>
#include <memory>
#include "base_widgets.h"
#include "../assert.h"
namespace dlib namespace dlib
{ {
...@@ -133,7 +134,7 @@ namespace dlib ...@@ -133,7 +134,7 @@ namespace dlib
void button:: void button::
set_main_font ( set_main_font (
const shared_ptr_thread_safe<font>& f const std::shared_ptr<font>& f
) )
{ {
auto_mutex M(m); auto_mutex M(m);
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#ifndef DLIB_BASE_WIDGETs_ #ifndef DLIB_BASE_WIDGETs_
#define DLIB_BASE_WIDGETs_ #define DLIB_BASE_WIDGETs_
#include <memory>
#include "base_widgets_abstract.h" #include "base_widgets_abstract.h"
#include "drawable.h" #include "drawable.h"
#include "../gui_core.h" #include "../gui_core.h"
...@@ -586,7 +588,7 @@ namespace dlib ...@@ -586,7 +588,7 @@ namespace dlib
class tooltip_window : public base_window class tooltip_window : public base_window
{ {
public: public:
tooltip_window (const shared_ptr_thread_safe<font>& f) : base_window(false,true), pad(3), mfont(f) tooltip_window (const std::shared_ptr<font>& f) : base_window(false,true), pad(3), mfont(f)
{ {
} }
...@@ -594,7 +596,7 @@ namespace dlib ...@@ -594,7 +596,7 @@ namespace dlib
rectangle rect_all; rectangle rect_all;
rectangle rect_text; rectangle rect_text;
const unsigned long pad; const unsigned long pad;
const shared_ptr_thread_safe<font> mfont; const std::shared_ptr<font> mfont;
void set_text ( void set_text (
const std::string& str const std::string& str
...@@ -777,7 +779,7 @@ namespace dlib ...@@ -777,7 +779,7 @@ namespace dlib
) const; ) const;
void set_main_font ( void set_main_font (
const shared_ptr_thread_safe<font>& f const std::shared_ptr<font>& f
); );
void show ( void show (
...@@ -1623,7 +1625,7 @@ namespace dlib ...@@ -1623,7 +1625,7 @@ namespace dlib
private: private:
dlib::ustring text; dlib::ustring text;
const shared_ptr_thread_safe<font> f; const std::shared_ptr<font> f;
any_function<void()> action; any_function<void()> action;
unichar hotkey; unichar hotkey;
point underline_p1; point underline_p1;
...@@ -1801,7 +1803,7 @@ namespace dlib ...@@ -1801,7 +1803,7 @@ namespace dlib
private: private:
dlib::ustring text; dlib::ustring text;
const shared_ptr_thread_safe<font> f; const std::shared_ptr<font> f;
any_function<void()> action; any_function<void()> action;
unichar hotkey; unichar hotkey;
point underline_p1; point underline_p1;
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#ifndef DLIB_DRAWABLe_ #ifndef DLIB_DRAWABLe_
#define DLIB_DRAWABLe_ #define DLIB_DRAWABLe_
#include <memory>
#include "drawable_abstract.h" #include "drawable_abstract.h"
#include "../gui_core.h" #include "../gui_core.h"
#include "../set.h" #include "../set.h"
...@@ -344,7 +346,7 @@ namespace dlib ...@@ -344,7 +346,7 @@ namespace dlib
} }
virtual void set_main_font ( virtual void set_main_font (
const shared_ptr_thread_safe<font>& f const std::shared_ptr<font>& f
) )
{ {
auto_mutex M(m); auto_mutex M(m);
...@@ -352,7 +354,7 @@ namespace dlib ...@@ -352,7 +354,7 @@ namespace dlib
parent.invalidate_rectangle(rect); parent.invalidate_rectangle(rect);
} }
const shared_ptr_thread_safe<font> main_font ( const std::shared_ptr<font> main_font (
) const ) const
{ {
auto_mutex M(m); auto_mutex M(m);
...@@ -420,7 +422,7 @@ namespace dlib ...@@ -420,7 +422,7 @@ namespace dlib
bool enabled; bool enabled;
const long& lastx; const long& lastx;
const long& lasty; const long& lasty;
shared_ptr_thread_safe<font> mfont; std::shared_ptr<font> mfont;
void enable_events ( void enable_events (
......
...@@ -5,11 +5,13 @@ ...@@ -5,11 +5,13 @@
#include "fonts.h" #include "fonts.h"
#include "../serialize.h" #include <fstream>
#include <memory>
#include <sstream> #include <sstream>
#include "../serialize.h"
#include "../base64.h" #include "../base64.h"
#include "../compress_stream.h" #include "../compress_stream.h"
#include <fstream>
#include "../tokenizer.h" #include "../tokenizer.h"
#include "nativefont.h" #include "nativefont.h"
...@@ -657,7 +659,7 @@ namespace dlib ...@@ -657,7 +659,7 @@ namespace dlib
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
const shared_ptr_thread_safe<font> get_native_font ( const std::shared_ptr<font> get_native_font (
) )
{ {
return nativefont::native_font::get_font(); return nativefont::native_font::get_font();
......
...@@ -4,16 +4,17 @@ ...@@ -4,16 +4,17 @@
#ifndef DLIB_FONTs_ #ifndef DLIB_FONTs_
#define DLIB_FONTs_ #define DLIB_FONTs_
#include <memory>
#include <string>
#include "fonts_abstract.h" #include "fonts_abstract.h"
#include "../gui_core.h" #include "../gui_core.h"
#include <string>
#include "../algs.h" #include "../algs.h"
#include "../serialize.h" #include "../serialize.h"
#include "../unicode.h" #include "../unicode.h"
#include "../array.h" #include "../array.h"
#include "../array2d.h" #include "../array2d.h"
#include "../threads.h" #include "../threads.h"
#include "../smart_pointers_thread_safe.h"
namespace dlib namespace dlib
{ {
...@@ -483,7 +484,7 @@ namespace dlib ...@@ -483,7 +484,7 @@ namespace dlib
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
const shared_ptr_thread_safe<font> get_native_font (); const std::shared_ptr<font> get_native_font ();
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
...@@ -500,11 +501,11 @@ namespace dlib ...@@ -500,11 +501,11 @@ namespace dlib
public: public:
static const shared_ptr_thread_safe<font>& get_font ( static const std::shared_ptr<font>& get_font (
) )
{ {
static mutex m; static mutex m;
static shared_ptr_thread_safe<font> f; static std::shared_ptr<font> f;
auto_mutex M(m); auto_mutex M(m);
if (f.get() == 0) if (f.get() == 0)
f.reset(new default_font); f.reset(new default_font);
......
...@@ -7,10 +7,10 @@ ...@@ -7,10 +7,10 @@
#include "../gui_widgets.h" #include "../gui_widgets.h"
#include "../unicode.h" #include "../unicode.h"
#include "../smart_pointers_thread_safe.h"
#include "../uintn.h" #include "../uintn.h"
#include <map> #include <map>
#include <memory>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
...@@ -546,10 +546,10 @@ namespace nativefont ...@@ -546,10 +546,10 @@ namespace nativefont
return (*this)[ch].width() > 0; return (*this)[ch].width() > 0;
} }
static const dlib::shared_ptr_thread_safe<font>& get_font ( static const std::shared_ptr<font>& get_font (
) )
{ {
static dlib::shared_ptr_thread_safe<font> f(new native_font); static std::shared_ptr<font> f(new native_font);
return f; return f;
} }
......
...@@ -3,8 +3,10 @@ ...@@ -3,8 +3,10 @@
#ifndef DLIB_WIDGETs_CPP_ #ifndef DLIB_WIDGETs_CPP_
#define DLIB_WIDGETs_CPP_ #define DLIB_WIDGETs_CPP_
#include "widgets.h"
#include <algorithm> #include <algorithm>
#include <memory>
#include "widgets.h"
#include "../string.h" #include "../string.h"
namespace dlib namespace dlib
...@@ -160,7 +162,7 @@ namespace dlib ...@@ -160,7 +162,7 @@ namespace dlib
void toggle_button:: void toggle_button::
set_main_font ( set_main_font (
const shared_ptr_thread_safe<font>& f const std::shared_ptr<font>& f
) )
{ {
auto_mutex M(m); auto_mutex M(m);
...@@ -309,7 +311,7 @@ namespace dlib ...@@ -309,7 +311,7 @@ namespace dlib
void label:: void label::
set_main_font ( set_main_font (
const shared_ptr_thread_safe<font>& f const std::shared_ptr<font>& f
) )
{ {
auto_mutex M(m); auto_mutex M(m);
...@@ -638,7 +640,7 @@ namespace dlib ...@@ -638,7 +640,7 @@ namespace dlib
void text_field:: void text_field::
set_main_font ( set_main_font (
const shared_ptr_thread_safe<font>& f const std::shared_ptr<font>& f
) )
{ {
auto_mutex M(m); auto_mutex M(m);
...@@ -1745,7 +1747,7 @@ namespace dlib ...@@ -1745,7 +1747,7 @@ namespace dlib
void tabbed_display:: void tabbed_display::
set_main_font ( set_main_font (
const shared_ptr_thread_safe<font>& f const std::shared_ptr<font>& f
) )
{ {
auto_mutex M(m); auto_mutex M(m);
...@@ -1887,7 +1889,7 @@ namespace dlib ...@@ -1887,7 +1889,7 @@ namespace dlib
void named_rectangle:: void named_rectangle::
set_main_font ( set_main_font (
const shared_ptr_thread_safe<font>& f const std::shared_ptr<font>& f
) )
{ {
auto_mutex M(m); auto_mutex M(m);
...@@ -2065,7 +2067,7 @@ namespace dlib ...@@ -2065,7 +2067,7 @@ namespace dlib
void mouse_tracker:: void mouse_tracker::
set_main_font ( set_main_font (
const shared_ptr_thread_safe<font>& f const std::shared_ptr<font>& f
) )
{ {
auto_mutex M(m); auto_mutex M(m);
...@@ -2270,7 +2272,7 @@ namespace dlib ...@@ -2270,7 +2272,7 @@ namespace dlib
template <typename S> template <typename S>
void list_box<S>:: void list_box<S>::
set_main_font ( set_main_font (
const shared_ptr_thread_safe<font>& f const std::shared_ptr<font>& f
) )
{ {
auto_mutex M(m); auto_mutex M(m);
...@@ -3300,7 +3302,7 @@ namespace dlib ...@@ -3300,7 +3302,7 @@ namespace dlib
void menu_bar:: void menu_bar::
set_main_font ( set_main_font (
const shared_ptr_thread_safe<font>& f const std::shared_ptr<font>& f
) )
{ {
auto_mutex M(m); auto_mutex M(m);
...@@ -4916,7 +4918,7 @@ namespace dlib ...@@ -4916,7 +4918,7 @@ namespace dlib
void text_box:: void text_box::
set_main_font ( set_main_font (
const shared_ptr_thread_safe<font>& f const std::shared_ptr<font>& f
) )
{ {
auto_mutex M(m); auto_mutex M(m);
......
...@@ -4,13 +4,18 @@ ...@@ -4,13 +4,18 @@
#ifndef DLIB_WIDGETs_ #ifndef DLIB_WIDGETs_
#define DLIB_WIDGETs_ #define DLIB_WIDGETs_
#include <cctype>
#include <memory>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include "../algs.h" #include "../algs.h"
#include "widgets_abstract.h" #include "widgets_abstract.h"
#include "drawable.h" #include "drawable.h"
#include "../gui_core.h" #include "../gui_core.h"
#include "fonts.h" #include "fonts.h"
#include <string>
#include <sstream>
#include "../timer.h" #include "../timer.h"
#include "base_widgets.h" #include "base_widgets.h"
#include "../member_function_pointer.h" #include "../member_function_pointer.h"
...@@ -23,10 +28,7 @@ ...@@ -23,10 +28,7 @@
#include "style.h" #include "style.h"
#include "../string.h" #include "../string.h"
#include "../misc_api.h" #include "../misc_api.h"
#include <cctype>
#include <vector>
#include "../any.h" #include "../any.h"
#include <set>
#include "../image_processing/full_object_detection.h" #include "../image_processing/full_object_detection.h"
#ifdef _MSC_VER #ifdef _MSC_VER
...@@ -93,7 +95,7 @@ namespace dlib ...@@ -93,7 +95,7 @@ namespace dlib
) const; ) const;
void set_main_font ( void set_main_font (
const shared_ptr_thread_safe<font>& f const std::shared_ptr<font>& f
); );
private: private:
...@@ -213,7 +215,7 @@ namespace dlib ...@@ -213,7 +215,7 @@ namespace dlib
); );
void set_main_font ( void set_main_font (
const shared_ptr_thread_safe<font>& f const std::shared_ptr<font>& f
); );
void set_pos ( void set_pos (
...@@ -478,7 +480,7 @@ namespace dlib ...@@ -478,7 +480,7 @@ namespace dlib
); );
void set_main_font ( void set_main_font (
const shared_ptr_thread_safe<font>& f const std::shared_ptr<font>& f
); );
int next_free_user_event_number ( int next_free_user_event_number (
...@@ -866,7 +868,7 @@ namespace dlib ...@@ -866,7 +868,7 @@ namespace dlib
); );
void set_main_font ( void set_main_font (
const shared_ptr_thread_safe<font>& f const std::shared_ptr<font>& f
); );
int next_free_user_event_number ( int next_free_user_event_number (
...@@ -1262,7 +1264,7 @@ namespace dlib ...@@ -1262,7 +1264,7 @@ namespace dlib
); );
void set_main_font ( void set_main_font (
const shared_ptr_thread_safe<font>& f const std::shared_ptr<font>& f
); );
void fit_to_contents ( void fit_to_contents (
...@@ -1381,7 +1383,7 @@ namespace dlib ...@@ -1381,7 +1383,7 @@ namespace dlib
); );
void set_main_font ( void set_main_font (
const shared_ptr_thread_safe<font>& f const std::shared_ptr<font>& f
); );
protected: protected:
...@@ -1440,7 +1442,7 @@ namespace dlib ...@@ -1440,7 +1442,7 @@ namespace dlib
); );
void set_main_font ( void set_main_font (
const shared_ptr_thread_safe<font>& f const std::shared_ptr<font>& f
); );
protected: protected:
...@@ -1795,7 +1797,7 @@ namespace dlib ...@@ -1795,7 +1797,7 @@ namespace dlib
) const; ) const;
void set_main_font ( void set_main_font (
const shared_ptr_thread_safe<font>& f const std::shared_ptr<font>& f
); );
private: private:
...@@ -2041,7 +2043,7 @@ namespace dlib ...@@ -2041,7 +2043,7 @@ namespace dlib
void set_pos(long,long){} void set_pos(long,long){}
void set_main_font ( void set_main_font (
const shared_ptr_thread_safe<font>& f const std::shared_ptr<font>& f
); );
void set_number_of_menus ( void set_number_of_menus (
......
...@@ -6,8 +6,9 @@ ...@@ -6,8 +6,9 @@
#include "iosockstream_abstract.h" #include "iosockstream_abstract.h"
#include <iostream> #include <iostream>
#include <memory>
#include "../sockstreambuf.h" #include "../sockstreambuf.h"
#include "../smart_pointers_thread_safe.h"
#include "../timeout.h" #include "../timeout.h"
#ifdef _MSC_VER #ifdef _MSC_VER
...@@ -147,7 +148,7 @@ namespace dlib ...@@ -147,7 +148,7 @@ namespace dlib
private: private:
void terminate_connection( void terminate_connection(
shared_ptr_thread_safe<connection> thecon std::shared_ptr<connection> thecon
) )
{ {
thecon->shutdown(); thecon->shutdown();
...@@ -155,7 +156,7 @@ namespace dlib ...@@ -155,7 +156,7 @@ namespace dlib
scoped_ptr<timeout> con_timeout; scoped_ptr<timeout> con_timeout;
rmutex class_mutex; rmutex class_mutex;
shared_ptr_thread_safe<connection> con; std::shared_ptr<connection> con;
scoped_ptr<sockstreambuf> buf; scoped_ptr<sockstreambuf> buf;
}; };
......
...@@ -3,6 +3,16 @@ ...@@ -3,6 +3,16 @@
#ifndef DLIB_SMART_POINTERs_THREAD_SAFE_H_ #ifndef DLIB_SMART_POINTERs_THREAD_SAFE_H_
#define DLIB_SMART_POINTERs_THREAD_SAFE_H_ #define DLIB_SMART_POINTERs_THREAD_SAFE_H_
// This is legacy smart pointer code that will likely to stop working under default
// compiler flags when C++17 becomes the default standard in the compilers.
// Please consider migrating your code to contemporary smart pointers from C++
// standard library. The warning below will help to detect if the deprecated code
// was included from library's clients.
#if (defined(__GNUC__) && ((__GNUC__ >= 4 && __GNUC_MINOR__ >= 8) || (__GNUC__ > 4))) || \
(defined(__clang__) && ((__clang_major__ >= 3 && __clang_minor__ >= 4)))
#pragma GCC warning "smart_pointers_thread_safe.h is included which will fail to compile under C++17"
#endif
#include "smart_pointers/shared_ptr_thread_safe.h" #include "smart_pointers/shared_ptr_thread_safe.h"
#endif // DLIB_SMART_POINTERs_THREAD_SAFE_H_ #endif // DLIB_SMART_POINTERs_THREAD_SAFE_H_
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include "../algs.h" #include "../algs.h"
#include <string> #include <string>
#include "../threads.h" #include "../threads.h"
#include "../smart_pointers.h"
#include "../uintn.h" #include "../uintn.h"
......
#include <fstream>
#include <iostream>
#include <memory>
#include <sstream>
#include <string>
#include "dlib/image_io.h" #include "dlib/image_io.h"
#include "dlib/array2d.h" #include "dlib/array2d.h"
#include "dlib/gui_core.h" #include "dlib/gui_core.h"
#include "dlib/assert.h" #include "dlib/assert.h"
#include "dlib/misc_api.h" #include "dlib/misc_api.h"
#include <string>
#include "dlib/image_transforms.h" #include "dlib/image_transforms.h"
#include "dlib/timer.h" #include "dlib/timer.h"
#include "dlib/gui_widgets.h" #include "dlib/gui_widgets.h"
#include "dlib/queue.h" #include "dlib/queue.h"
#include <sstream>
#include <iostream>
#include <fstream>
using namespace dlib; using namespace dlib;
using namespace std; using namespace std;
...@@ -444,7 +447,7 @@ public: ...@@ -444,7 +447,7 @@ public:
{ {
bool use_bdf_fonts = false; bool use_bdf_fonts = false;
shared_ptr_thread_safe<bdf_font> f(new bdf_font); std::shared_ptr<bdf_font> f(new bdf_font);
if (use_bdf_fonts) if (use_bdf_fonts)
{ {
......
...@@ -3,6 +3,10 @@ ...@@ -3,6 +3,10 @@
#ifndef DLIB_THREAD_POOl_Hh_ #ifndef DLIB_THREAD_POOl_Hh_
#define DLIB_THREAD_POOl_Hh_ #define DLIB_THREAD_POOl_Hh_
#include <exception>
#include <memory>
#include <thread>
#include "thread_pool_extension_abstract.h" #include "thread_pool_extension_abstract.h"
#include "multithreaded_object_extension.h" #include "multithreaded_object_extension.h"
#include "../member_function_pointer.h" #include "../member_function_pointer.h"
...@@ -11,10 +15,6 @@ ...@@ -11,10 +15,6 @@
#include "auto_mutex_extension.h" #include "auto_mutex_extension.h"
#include "../uintn.h" #include "../uintn.h"
#include "../array.h" #include "../array.h"
#include "../smart_pointers_thread_safe.h"
#include <exception>
#include <thread>
#include <memory>
namespace dlib namespace dlib
{ {
...@@ -88,7 +88,7 @@ namespace dlib ...@@ -88,7 +88,7 @@ namespace dlib
inline void wait () const; inline void wait () const;
mutable uint64 task_id; mutable uint64 task_id;
mutable shared_ptr_thread_safe<thread_pool_implementation> tp; mutable std::shared_ptr<thread_pool_implementation> tp;
T var; T var;
}; };
...@@ -489,7 +489,7 @@ namespace dlib ...@@ -489,7 +489,7 @@ namespace dlib
class thread_pool class thread_pool
{ {
/*! /*!
This object is just a shell that holds a shared_ptr_thread_safe This object is just a shell that holds a std::shared_ptr
to the real thread_pool_implementation object. The reason for doing to the real thread_pool_implementation object. The reason for doing
it this way is so that we can allow any mixture of destruction orders it this way is so that we can allow any mixture of destruction orders
between thread_pool objects and futures. Whoever gets destroyed between thread_pool objects and futures. Whoever gets destroyed
...@@ -1355,7 +1355,7 @@ namespace dlib ...@@ -1355,7 +1355,7 @@ namespace dlib
private: private:
shared_ptr_thread_safe<thread_pool_implementation> impl; std::shared_ptr<thread_pool_implementation> impl;
// restricted functions // restricted functions
thread_pool(thread_pool&); // copy constructor thread_pool(thread_pool&); // copy constructor
......
...@@ -208,9 +208,9 @@ namespace dlib ...@@ -208,9 +208,9 @@ namespace dlib
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
shared_ptr_thread_safe<timer_global_clock> get_global_clock() std::shared_ptr<timer_global_clock> get_global_clock()
{ {
static shared_ptr_thread_safe<timer_global_clock> d(new timer_global_clock); static std::shared_ptr<timer_global_clock> d(new timer_global_clock);
return d; return d;
} }
......
...@@ -3,13 +3,14 @@ ...@@ -3,13 +3,14 @@
#ifndef DLIB_TIMEr_Hh_ #ifndef DLIB_TIMEr_Hh_
#define DLIB_TIMEr_Hh_ #define DLIB_TIMEr_Hh_
#include <memory>
#include "../threads.h" #include "../threads.h"
#include "../algs.h" #include "../algs.h"
#include "../misc_api.h" #include "../misc_api.h"
#include "timer_abstract.h" #include "timer_abstract.h"
#include "../uintn.h" #include "../uintn.h"
#include "../binary_search_tree.h" #include "../binary_search_tree.h"
#include "../smart_pointers_thread_safe.h"
#include "timer_heavy.h" #include "timer_heavy.h"
namespace dlib namespace dlib
...@@ -96,7 +97,7 @@ namespace dlib ...@@ -96,7 +97,7 @@ namespace dlib
mutex m; mutex m;
friend shared_ptr_thread_safe<timer_global_clock> get_global_clock(); friend std::shared_ptr<timer_global_clock> get_global_clock();
private: private:
timer_global_clock(); timer_global_clock();
...@@ -113,7 +114,7 @@ namespace dlib ...@@ -113,7 +114,7 @@ namespace dlib
- spawns timer tasks as is appropriate - spawns timer tasks as is appropriate
!*/ !*/
}; };
shared_ptr_thread_safe<timer_global_clock> get_global_clock(); std::shared_ptr<timer_global_clock> get_global_clock();
/*! /*!
ensures ensures
- returns the global instance of the timer_global_clock object - returns the global instance of the timer_global_clock object
...@@ -209,7 +210,7 @@ namespace dlib ...@@ -209,7 +210,7 @@ namespace dlib
// data members // data members
T& ao; T& ao;
const af_type af; const af_type af;
shared_ptr_thread_safe<timer_global_clock> gc; std::shared_ptr<timer_global_clock> gc;
// restricted functions // restricted functions
timer(const timer&); // copy constructor timer(const timer&); // copy constructor
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment