Click here to Skip to main content
15,902,635 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Generalincrease the max length of SETWINDOWTEXT Pin
Member 147966910-Jan-05 21:43
Member 147966910-Jan-05 21:43 
GeneralRe: increase the max length of SETWINDOWTEXT Pin
Roger Allen10-Jan-05 23:19
Roger Allen10-Jan-05 23:19 
GeneralCRectTracker and scrolling problems Pin
Maverick10-Jan-05 21:38
Maverick10-Jan-05 21:38 
GeneralFIFO thread synchronizing Pin
Menny Even Danan10-Jan-05 20:53
Menny Even Danan10-Jan-05 20:53 
GeneralRe: FIFO thread synchronizing Pin
Blake Miller11-Jan-05 4:03
Blake Miller11-Jan-05 4:03 
GeneralRe: FIFO thread synchronizing Pin
Menny Even Danan11-Jan-05 21:39
Menny Even Danan11-Jan-05 21:39 
GeneralRe: FIFO thread synchronizing Pin
Blake Miller12-Jan-05 5:00
Blake Miller12-Jan-05 5:00 
GeneralRe: FIFO thread synchronizing Pin
Menny Even Danan12-Jan-05 0:52
Menny Even Danan12-Jan-05 0:52 
Notice,
MS does not guarantee FIFO order when using CRITICAL_SECTION:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/initializecriticalsection.asp

I've tried to implement a FIFO critical section. But i think it consumes alot of CPU time. If anyone can look into it, it would be helpfull

thanks

H FILE:
****************************
#include <windows.h>
#include <stdlib.h>
#include <list>class uFIFOCriticalSection
{
protected:
CRITICAL_SECTION _EntryCritSection;
std::list<handle> mLst_events;

public:
uFIFOCriticalSection();

void Enter();
void Leave();

virtual ~uFIFOCriticalSection();
private:
// No copies do not implement
uFIFOCriticalSection(const uFIFOCriticalSection &rhs);
uFIFOCriticalSection &operator=(const uFIFOCriticalSection &rhs);
};
****************************
CPP FILE:
**********************
#include "uFIFOCriticalSection.h"

uFIFOCriticalSection::uFIFOCriticalSection()
{
InitializeCriticalSection (&_EntryCritSection);
}

void uFIFOCriticalSection::Enter() {
EnterCriticalSection(&_EntryCritSection);
//creating an event handle for this thread (when it goes out of the critical section
HANDLE my_event = CreateEvent(NULL, false, false, NULL);
HANDLE last_event = NULL;
//checking if there is a thread inside the critical section
if (!mLst_events.empty()) last_event = mLst_events.back();

//pushing this thread's event handle into the queue
mLst_events.push_back(my_event);
LeaveCriticalSection(&_EntryCritSection);
//if there is a thread inside the, (last_event != NULL -> 'mLst_events' IS empty)
//we'll wait for the single event to be signalled.
//NOTE: if the 'last_event' is already signalled, the function will not wait
//and if the last_event is closed (by CloseHandle) the handle is invalid
//and the function will return with 'WAIT_FAILED'. Both cases are good for us.
if (last_event != NULL) WaitForSingleObject(last_event, INFINITE);
}

void uFIFOCriticalSection::Leave() {
EnterCriticalSection(&_EntryCritSection);
//the thread had left the critical section.
//getting the related event handle
HANDLE my_event = mLst_events.front();
mLst_events.pop_front();//removing myself
LeaveCriticalSection(&_EntryCritSection);
//signalling this thread's event.
//if there is a thread wait on this event,
//it's will automatically started
SetEvent(my_event);
//no need for it anymore, we can close the handle to retain resources
CloseHandle(my_event);
}

uFIFOCriticalSection::~uFIFOCriticalSection()
{
//we must release all the threads
//DO WE? let's try not...
/* std::list<handle>::iterator itr = mLst_events.begin();
while(itr != mLst_events.end()) {
SetEvent((*itr));
itr++;
}*/
DeleteCriticalSection (&_EntryCritSection);
}
*****************
GeneralFile Directory Table Pin
LiYS10-Jan-05 20:20
LiYS10-Jan-05 20:20 
GeneralRe: File Directory Table Pin
David Crow11-Jan-05 6:42
David Crow11-Jan-05 6:42 
GeneralRe: File Directory Table Pin
LiYS11-Jan-05 13:37
LiYS11-Jan-05 13:37 
GeneralRe: File Directory Table Pin
David Crow12-Jan-05 1:55
David Crow12-Jan-05 1:55 
GeneralCreating Property Sheet Run Time. Pin
Anonymous10-Jan-05 20:05
Anonymous10-Jan-05 20:05 
Generalsoftware package Pin
vc-programmer-10-Jan-05 19:31
vc-programmer-10-Jan-05 19:31 
GeneralRe: software package Pin
ThatsAlok11-Jan-05 0:34
ThatsAlok11-Jan-05 0:34 
GeneralConverting UNICODE to Str Pin
dSolariuM10-Jan-05 18:44
dSolariuM10-Jan-05 18:44 
QuestionI need to do some clean-up on exit, how do I break in? Pin
fklldsvs10-Jan-05 18:22
fklldsvs10-Jan-05 18:22 
AnswerRe: I need to do some clean-up on exit, how do I break in? Pin
Cedric Moonen10-Jan-05 19:50
Cedric Moonen10-Jan-05 19:50 
QuestionHow to change the Color in Scroll Bar in a TextBox? Pin
pubududilena10-Jan-05 18:04
pubududilena10-Jan-05 18:04 
QuestionHow to call javascript in mfc project without CHtmlView? Pin
Anonymous10-Jan-05 17:47
Anonymous10-Jan-05 17:47 
AnswerRe: How to call javascript in mfc project without CHtmlView? Pin
basementman11-Jan-05 5:50
basementman11-Jan-05 5:50 
GeneralSliding window in serial communications Pin
ledallam10-Jan-05 17:16
ledallam10-Jan-05 17:16 
GeneralRe: Sliding window in serial communications Pin
Antony M Kancidrowski11-Jan-05 2:02
Antony M Kancidrowski11-Jan-05 2:02 
GeneralCPicture control Pin
Suvendra10-Jan-05 16:14
Suvendra10-Jan-05 16:14 
GeneralRe: CPicture control Pin
Abhi Lahare10-Jan-05 17:05
Abhi Lahare10-Jan-05 17:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.