From 161b8b92a2df18073f5f7c22e35269287b0523d0 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Wed, 28 Feb 2007 18:55:46 +0000 Subject: "Sampo's Delight" - add "do not show this window again" to memory warning; check physical RAM on linux and only warn if limit is less than 75% of total RAM; do nothing on OSX since there is no mlockall there git-svn-id: svn://localhost/ardour2/trunk@1534 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/ardour_ui.cc | 62 +++++++++++++++++++++++++++++++++++++++++------- gtk2_ardour/ardour_ui.h | 3 +++ 2 files changed, 56 insertions(+), 9 deletions(-) (limited to 'gtk2_ardour') diff --git a/gtk2_ardour/ardour_ui.cc b/gtk2_ardour/ardour_ui.cc index c6db2716c5..c11175fe27 100644 --- a/gtk2_ardour/ardour_ui.cc +++ b/gtk2_ardour/ardour_ui.cc @@ -437,27 +437,71 @@ ARDOUR_UI::save_ardour_state () void ARDOUR_UI::startup () { - if (engine->is_realtime()) { + check_memory_locking(); +} + +void +ARDOUR_UI::no_memory_warning () +{ + XMLNode node (X_("no-memory-warning")); + Config->add_instant_xml (node, get_user_ardour_path()); +} + +void +ARDOUR_UI::check_memory_locking () +{ +#ifdef __APPLE__ + /* OS X doesn't support mlockall(2), and so testing for memory locking capability there is pointless */ + return; +#endif + + XMLNode* memory_warning_node = Config->instant_xml (X_("no-memory-warning"), get_user_ardour_path()); + + if (engine->is_realtime() && memory_warning_node == 0) { struct rlimit limits; - + int64_t ram; + long pages, page_size; + + if ((page_size = sysconf (_SC_PAGESIZE)) < 0 ||(pages = sysconf (_SC_PHYS_PAGES)) < 0) { + ram = 0; + } else { + ram = (int64_t) pages * (int64_t) page_size; + } + if (getrlimit (RLIMIT_MEMLOCK, &limits)) { return; } if (limits.rlim_cur != RLIM_INFINITY) { - MessageDialog msg (_("WARNING: Your system has a limit for maximum amount of locked memory. " - "This might cause Ardour to run out of memory before your system " - "runs out of memory. \n\n" - "You can view the memory limit with 'ulimit -l', " - "and it is normally controlled by /etc/security/limits.conf")); + + if (ram == 0 || ((double) limits.rlim_cur / ram) < 0.75) { - editor->ensure_float (msg); - msg.run (); + + MessageDialog msg (_("WARNING: Your system has a limit for maximum amount of locked memory. " + "This might cause Ardour to run out of memory before your system " + "runs out of memory. \n\n" + "You can view the memory limit with 'ulimit -l', " + "and it is normally controlled by /etc/security/limits.conf")); + + VBox* vbox = msg.get_vbox(); + HBox hbox; + CheckButton cb (_("Do not show this window again")); + + cb.signal_toggled().connect (mem_fun (*this, &ARDOUR_UI::no_memory_warning)); + + hbox.pack_start (cb, true, false); + vbox->pack_start (hbox); + hbox.show_all (); + + editor->ensure_float (msg); + msg.run (); + } } } } + void ARDOUR_UI::finish() { diff --git a/gtk2_ardour/ardour_ui.h b/gtk2_ardour/ardour_ui.h index 00d8deacbf..a8bd1517f1 100644 --- a/gtk2_ardour/ardour_ui.h +++ b/gtk2_ardour/ardour_ui.h @@ -697,6 +697,9 @@ class ARDOUR_UI : public Gtkmm2ext::UI bool can_save_keybindings; bool first_idle (); + + void no_memory_warning (); + void check_memory_locking (); }; #endif /* __ardour_gui_h__ */ -- cgit v1.2.3