I am looking for a way to optimize the following code, for an open source project that I am developing, or to make it more efficient by moving the hard work to another thread.
void ProfilerCommunication::AddVisitPoint(ULONG uniqueId) { CScopedLock<CMutex> lock(m_mutexResults); m_pVisitPoints->points[m_pVisitPoints->count].UniqueId = uniqueId; if (++m_pVisitPoints->count == VP_BUFFER_SIZE) { SendVisitPoints(); m_pVisitPoints->count=0; } }
The above code is used by the OpenCover profiler (an open source coverage tool for .NET written in C ++) when every visit point is called. A mutex is used to protect some shared memory (a 64K block shared between several 32/64 bit processes and C ++ / C #) when it completely signals the host process. Obviously, this is pretty hard for every breakpoint, and I would like to make the kick easier.
I am thinking about using a queue that is pushed by the above method, and a thread that issues data and fills the shared memory.
Q. Is there a thread-safe queue in C ++ (Windows STL) that I can use, or a queue lock, because I do not want to replace one problem with another? Do people think my approach is reasonable?
EDIT 1: I just found concurrent_queue.h in the include folder - could this be my answer ...?
source share