Conversation
cd9a25f to
91060c2
Compare
|
|
||
| #include <list> | ||
|
|
||
| class CCriticalSection |
There was a problem hiding this comment.
A very intuitive class, with its implementation quite similar to ATL's CComAutoCriticalSection. (Actually, there is nothing "Com" in it.)
| CRITICAL_SECTION m_cs; | ||
| }; | ||
|
|
||
| class CCriticalSectionLock |
There was a problem hiding this comment.
The implementation is quite similar to ATL's CComCritSecLock.
|
Why implement a new locking mechanism when there is already one available in |
|
Agree, Yuni::Mutex could be used instead. In such case I'll add a new class Yuni::MutexLockerEx that will include the m_bLocked member and additional methods Lock and Unlock - similar to CComCritSecLock. |
|
There's already a Yuni::MutexLocker class. Why not use that one? |
|
@MAPJe71, please look at the implementation of Yuni::MutexLocker and then re-read my previous comment :) This is because of the following line in CThreadSafeQueue::push : |
|
Dispite using an autolocker/lock-guard on a mutex you can still manually (un-)lock it e.g. template <typename C>
class CThreadSafeQueue : protected std::list<C>
{
public:
void push(C& c)
{
Yuni::MutexLocker lock(m_Mutex); //<-- auto lock (RAII)
push_back( c );
m_Mutex.unlock(); //<-- manual unlock
if (!::ReleaseSemaphore(m_hSemaphore, 1, NULL))
{
// If the semaphore is full, then take back the entry.
m_Mutex.lock(); //<-- manual lock
pop_back();
if (GetLastError() == ERROR_TOO_MANY_POSTS)
{
m_bOverflow = true;
}
}
} //<-- auto unlock
bool pop(C& c)
{
Yuni::MutexLocker lock(m_Mutex);
//
}
protected:
Yuni::Mutex m_Mutex;
}; |
|
@MAPJe71, |
|
I'd rather propose to have 2 classes: MutexLocker and MutexLockerEx, without inheritance.
|
|
OK, guys - no additional classes now. Just a little more thinking and a little bit more braces :) |
5a6175c to
bcf3e7e
Compare
|
Now I believe it's good enough. |
|
@d0vgan additional benefit: building with mingw would be possible again, because ATL is not available there, see #4145 and there #2478 with patches to avoid ATL, see chcg@463bdc5#diff-5b536d07367d39b369aea9582ff0fe9d with |
|
Wow, so I'm not the first one to propose this! |
23325ef to
3261a6b
Compare
|
rebased + now everything in 1 commit |
|
Come on, why these ATL things are still here? |
|
I used to think that it's me who is conservative and not fast - now I see I'm not alone :) |
3261a6b to
56b2f07
Compare
|
@MAPJe71 From my point of view and from my experience, unlocking a mutex in the middle of the code where it is supposed to be managed by the scope is far from a good idea. Like deleting some resource managed by Regarding libyuni/mutex, this is historical reason as That's said, it is right here to use yuni/mutex here, for code consistency. That replacement has nothing to do with this MR and should be another one. |
|
@d0vgan I would encourage you next time to use multiple commits as it changes different things. |
|
@MAPJe71 Where did you find the snippet you posted regarding |
|
@donho For information, libyuni is going full C++17, so |
|
@milipili the snippet is from |
|
Ah yes right. Inheriting from |
|
@donho This class |
|
ATL dependency is really annoying. Nice job :) |
|
After some thinking, I think I vote for chcg's patch: |
|
@d0vgan: just to provide some aux. info, since I had the same fundamental problem as well. ATL/MFC is available with the Visual C++ Build Tools 2015. You can build Notepad++ easily that way. |
|
@MIvanchev The main point to get ride of ATL I think is to be able to build this under mingw. |
Yes, I also think the mingw build should be restored. I wanted to raise awareness that the Build Tools include ATL/MFC, because I wasted 2 days trying to figure out things... =) |
|
@d0vgan Sorry for the late review. Could you solve the conflict please? |
|
@d0vgan Never mind, I will take in charge of it. Thank you for the PR. |
Use std::lock_guard instead of CComCritSecLock<CComAutoCriticalSection> Close notepad-plus-plus#4320
The ATL dependency is quite annoying when working in Visual Studio Express (where there's no ATL included). Moreover, currently it's easy to get rid of the ATL dependency at all - actually it does not add anything to the code that really worth this dependency.