User forums > Nightly builds

The 19 september 2010 build (6608) CODECOMPLETION BRANCH version is out.

<< < (13/19) > >>

Loaden:

--- Quote from: MortenMacFly on September 23, 2010, 05:48:06 pm ---
--- Quote from: Loaden on September 23, 2010, 12:24:04 pm ---Fix system headers complete hangs.

--- End quote ---
I see this in the patch:
+            return !!m_Locker;
Before digging deeper into it: Is that what you want or a mistake?!


--- End quote ---
It just convert to bool.
It's i want.

oBFusCATed:
This is C-ish style of coding, not very appropriate for C++.
If you can use != 0, != NULL or something like that it is better.
What is the type of m_Locker?

Loaden:

--- Quote from: oBFusCATed on September 24, 2010, 08:12:02 am ---This is C-ish style of coding, not very appropriate for C++.
If you can use != 0, != NULL or something like that it is better.
What is the type of m_Locker?

--- End quote ---
I just like this convertion. It's very simply. :?
Here is the completly code.

--- Code: ---class SystemHeadersThread : public wxThread
{
public:
    SystemHeadersThread(CodeCompletion* parent, SystemHeadersMap& headersMap, const wxArrayString& incDirs) :
        m_Parent(parent),
        m_SystemHeadersMap(headersMap),
        m_IncludeDirs(incDirs)
    {
        Create();
        SetPriority(WXTHREAD_MIN_PRIORITY);
    }

    virtual void* Entry()
    {
        wxArrayString dirs;
        {
            wxCriticalSectionLocker locker(s_HeadersCriticalSection);
            for (size_t i = 0; i < m_IncludeDirs.GetCount(); ++i)
            {
                if (m_SystemHeadersMap.find(m_IncludeDirs[i]) == m_SystemHeadersMap.end())
                {
                    dirs.Add(m_IncludeDirs[i]);
                    m_SystemHeadersMap[m_IncludeDirs[i]] = std::list<wxString>();
                }
            }
        }

        for (size_t i = 0; i < dirs.GetCount() && !TestDestroy(); ++i)
        {
            wxDir dir(dirs[i]);
            if (!dir.IsOpened())
                continue;

            HeaderDirTraverser traverser(m_SystemHeadersMap, dirs[i]);
            dir.Traverse(traverser, wxEmptyString, wxDIR_FILES | wxDIR_DIRS);

            wxCommandEvent evt(wxEVT_COMMAND_MENU_SELECTED, THREAD_UPDATE);
            evt.SetClientData(this);
            evt.SetString(wxString::Format(_T("Get Headers: %s , %d"), dirs[i].wx_str(),
                                           m_SystemHeadersMap[dirs[i]].size()));
            wxPostEvent(m_Parent, evt);
        }

        if (!TestDestroy())
        {
            wxCommandEvent evt(wxEVT_COMMAND_MENU_SELECTED, THREAD_COMPLETED);
            evt.SetClientData(this);
            if (!dirs.IsEmpty())
                evt.SetString(wxString::Format(_T("Get the system header file path: %d"), dirs.GetCount()));
            wxPostEvent(m_Parent, evt);
        }

        return NULL;
    }

private:
    CodeCompletion*   m_Parent;
    SystemHeadersMap& m_SystemHeadersMap;
    wxArrayString     m_IncludeDirs;

private:
    class HeaderDirTraverser : public wxDirTraverser
    {
    public:
        HeaderDirTraverser(SystemHeadersMap& headersMap, const wxString& searchDir) :
            m_SystemHeadersMap(headersMap),
            m_SearchDir(searchDir),
            m_Headers(headersMap[searchDir]),
            m_Locker(NULL),
            m_HeaderCount(0)
        {}

        ~HeaderDirTraverser()
        {
            if (m_Locker)
                delete m_Locker;
        }

        virtual wxDirTraverseResult OnFile(const wxString& filename)
        {
            if (!AddLock())
                return wxDIR_STOP;

            wxFileName fn(filename);
            if (!fn.HasExt() || fn.GetExt().GetChar(0) == _T('h'))
            {
                fn.MakeRelativeTo(m_SearchDir);
                wxString final(fn.GetFullPath());
                final.Replace(_T("\\"), _T("/"), true);
                m_Headers.push_back(final);
            }

            return wxDIR_CONTINUE;
        }

        virtual wxDirTraverseResult OnDir(const wxString& dirname)
        {
            if (!AddLock())
                return wxDIR_STOP;

            wxString path(dirname);
            if (path.Last() != wxFILE_SEP_PATH)
                path.Append(wxFILE_SEP_PATH);

            if (m_SystemHeadersMap.find(path) != m_SystemHeadersMap.end())
                return wxDIR_IGNORE;
            return wxDIR_CONTINUE;
        }

        bool AddLock()
        {
            if (++m_HeaderCount % 100 == 1)
            {
                if (m_Locker)
                {
                    delete m_Locker;
                    m_Locker = NULL;
                }

                wxMilliSleep(1);
                m_Locker = new(std::nothrow) wxCriticalSectionLocker(s_HeadersCriticalSection);
            }

            return !!m_Locker;
        }

    private:
        const SystemHeadersMap&  m_SystemHeadersMap;
        const wxString&          m_SearchDir;
        std::list<wxString>&     m_Headers;
        wxCriticalSectionLocker* m_Locker;
        size_t                   m_HeaderCount;
    };
};
--- End code ---

Borr:
ibpp(http://www.ibpp.org/)  and CC problem still not solved
http://forums.codeblocks.org/index.php/topic,11844.msg80492.html#msg80492

oBFusCATed:

--- Quote from: Loaden on September 24, 2010, 08:48:21 am ---It's very simply. :?

--- End quote ---
You mean simple?

In this case != NULL is best (in fact you could use != nullptr in C::B), because you're documenting that this is a check for NULL.
"!!" is very confusing for people not seen this before...

Also why do you create the locker on the heap, probably some commenting will be good, this is way to non trivial code you've written.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version