fix intrinsic problem with refcount

adjust slit menus to deconstruct properly
This commit is contained in:
simonb 2007-01-07 14:07:45 +00:00
parent 1cc7b60aa2
commit 440c69afa4
4 changed files with 45 additions and 22 deletions

View file

@ -1,6 +1,8 @@
(Format: Year/Month/Day)
Changes for 1.0rc3:
*07/01/07:
* Fix RefCount crash and Slit deconstruction ordering (Simon)
RefCount.hh Slit.hh/cc
* Support per-window transparency settings.
- new "Transparency" menu in the window menu
- new apps file attribute:

View file

@ -25,6 +25,7 @@
namespace FbTk {
/// holds a pointer with reference counting, similar to std:auto_ptr
template <typename Pointer>
class RefCount {
public:
@ -43,37 +44,47 @@ public:
unsigned int usedBy() const { return (m_refcount != 0 ? *m_refcount : 0); }
#endif
private:
/// increase referense count
/// increase reference count
void incRefCount();
/// decrease referense count
/// decrease reference count
void decRefCount();
/// decrease refcount count
void decRefCountCount();
Pointer *m_data; ///< data holder
mutable unsigned int *m_refcount; ///< holds reference counting
// This one counts the number of active references pointing to the m_refcount data!
// when it reaches zero, *then* we can delete it, otherwise someone else might check it.
mutable unsigned int *m_refcount_count; ///< holds reference counting
};
// implementation
template <typename Pointer>
RefCount<Pointer>::RefCount():m_data(0), m_refcount(new unsigned int(0)) {
RefCount<Pointer>::RefCount():m_data(0), m_refcount(new unsigned int(0)), m_refcount_count(new unsigned int(1)) {
}
template <typename Pointer>
RefCount<Pointer>::RefCount(RefCount<Pointer> &copy):
m_data(copy.m_data),
m_refcount(copy.m_refcount) {
m_refcount(copy.m_refcount),
m_refcount_count(copy.m_refcount_count) {
(*m_refcount_count)++;
incRefCount();
}
template <typename Pointer>
RefCount<Pointer>::RefCount(Pointer *p):m_data(p), m_refcount(new unsigned int(0)) {
RefCount<Pointer>::RefCount(Pointer *p):m_data(p), m_refcount(new unsigned int(0)), m_refcount_count(new unsigned int(1)) {
incRefCount();
}
template <typename Pointer>
RefCount<Pointer>::RefCount(const RefCount<Pointer> &copy):
m_data(copy.m_data),
m_refcount(copy.m_refcount) {
m_refcount(copy.m_refcount),
m_refcount_count(copy.m_refcount_count) {
(*m_refcount_count)++;
incRefCount();
}
@ -86,6 +97,8 @@ template <typename Pointer>
RefCount<Pointer> &RefCount<Pointer>::operator = (const RefCount<Pointer> &copy) {
decRefCount(); // dec current ref count
m_refcount = copy.m_refcount; // set new ref count
m_refcount_count = copy.m_refcount_count;
(*m_refcount_count)++;
m_data = copy.m_data; // set new data pointer
incRefCount(); // inc new ref count
return *this;
@ -96,27 +109,35 @@ RefCount<Pointer> &RefCount<Pointer>::operator = (Pointer *p) {
decRefCount();
m_data = p; // set data pointer
m_refcount = new unsigned int(0); // create new counter
m_refcount_count = new unsigned int(1);
incRefCount();
return *this;
}
template <typename Pointer>
void RefCount<Pointer>::decRefCount() {
if (m_refcount == 0)
return;
if (*m_refcount == 0) { // already zero, then delete refcount
delete m_refcount;
m_refcount = 0;
return;
if (m_refcount != 0) {
(*m_refcount)--;
if (*m_refcount == 0) { // destroy m_data and m_refcount if nobody else is using this
if (m_data != 0)
delete m_data;
m_data = 0;
}
}
(*m_refcount)--;
if (*m_refcount == 0) { // destroy m_data and m_refcount if nobody else is using this
if (m_data != 0)
delete m_data;
m_data = 0;
decRefCountCount();
}
template <typename Pointer>
void RefCount<Pointer>::decRefCountCount() {
if (*m_refcount_count == 0)
return; // shouldnt happen
(*m_refcount_count)--;
if (*m_refcount_count == 0) {
delete m_refcount;
m_refcount = 0;
delete m_refcount_count;
}
m_refcount = 0;
m_refcount_count = 0;
}
template <typename Pointer>

View file

@ -261,12 +261,12 @@ unsigned int Slit::s_eventmask = SubstructureRedirectMask | ButtonPressMask |
Slit::Slit(BScreen &scr, FbTk::XLayer &layer, const char *filename)
: m_hidden(false),
m_screen(scr),
m_slitmenu(scr.menuTheme(),
scr.imageControl(),
*scr.layerManager().getLayer(Layer::MENU)),
m_clientlist_menu(scr.menuTheme(),
scr.imageControl(),
*scr.layerManager().getLayer(Layer::MENU)),
m_slitmenu(scr.menuTheme(),
scr.imageControl(),
*scr.layerManager().getLayer(Layer::MENU)),
frame(scr.rootWindow()),
//For KDE dock applets
m_kwm1_dockwindow(XInternAtom(FbTk::App::instance()->display(),

View file

@ -145,8 +145,8 @@ private:
FbTk::Timer m_timer;
SlitClients m_client_list;
FbMenu m_slitmenu, m_clientlist_menu;
std::auto_ptr<LayerMenu> m_layermenu;
FbMenu m_clientlist_menu, m_slitmenu;
std::string m_filename;
struct frame {