KSquare Utilities
GlobalGoalKeeper.cpp
Go to the documentation of this file.
1 /* GlobalGoalKeeper.cpp -- Implements a single GoalKeeper that can be used anywhere in the application.
2  * Copyright (C) 1994-2014 Kurt Kramer
3  * For conditions of distribution and use, see copyright notice in KKB.h
4  */
5 #include "FirstIncludes.h"
6 
7 #include <errno.h>
8 #include <vector>
9 #include "MemoryDebug.h"
10 
11 using namespace std;
12 
13 #include "GoalKeeper.h"
14 #include "GlobalGoalKeeper.h"
15 using namespace KKB;
16 
17 
18 
19 GoalKeeperPtr GlobalGoalKeeper::globalGoalie = NULL;
20 
21 
22 void GlobalGoalKeeper::CreateGlobalGoalie ()
23 {
24  bool didNotExist = false;
25  GoalKeeper::CreateAndStartBlock ("GlobalGoalie", globalGoalie, didNotExist);
26 
27  if (didNotExist)
28  atexit (GlobalGoalKeeper::CleanUp);
29 
30  globalGoalie->EndBlock ();
31 }
32 
33 
34 void GlobalGoalKeeper::CleanUp ()
35 {
36  GoalKeeper::Destroy (globalGoalie);
37  globalGoalie = NULL;
38 }
39 
40 
41 
43 {
44  if (!globalGoalie)
45  CreateGlobalGoalie ();
46  globalGoalie->StartBlock ();
47 }
48 
49 
50 
52 {
53  if (!globalGoalie)
54  CreateGlobalGoalie ();
55  globalGoalie->EndBlock ();
56 }
static void CreateAndStartBlock(const KKStr &_name, volatile GoalKeeperPtr &_newGoalKeeper, bool &_didNotExistYet)
Create a GoalKeeper object and avoid a race condition doing it.
Definition: GoalKeeper.cpp:413
static void Destroy(volatile GoalKeeperPtr &_goalKeeperInstance)
Destroys an existing instance of GoalKeeper.
Definition: GoalKeeper.cpp:491
KKTHread * KKTHreadPtr
void StartBlock()
Initiates a Block as long as another thread has not already locked this object.
Definition: GoalKeeper.cpp:214
void EndBlock()
Ends the block and allows other threads to pass through StatBlock.
Definition: GoalKeeper.cpp:295
Maintains one instance of a GoalKeeper object that can be used anywhere in the application.