fbxsdk/core/sync/fbxsync.h Source File

fbxsync.h
Go to the documentation of this file.
1 /****************************************************************************************
2 
3  Copyright (C) 2015 Autodesk, Inc.
4  All rights reserved.
5 
6  Use of this software is subject to the terms of the Autodesk license agreement
7  provided at the time of installation or download, or which otherwise accompanies
8  this software in either electronic or hard copy form.
9 
10 ****************************************************************************************/
11 
13 #ifndef _FBXSDK_CORE_SYNC_H_
14 #define _FBXSDK_CORE_SYNC_H_
15 
16 #include <fbxsdk/fbxsdk_def.h>
17 
18 #if !defined(FBXSDK_ENV_WINSTORE) && !defined(FBXSDK_ENV_EMSCRIPTEN)
19 
22 
23 #include <fbxsdk/fbxsdk_nsbegin.h>
24 
25 class FbxMutexImpl;
26 class FbxSemaphoreImpl;
27 class FbxGateImpl;
28 
39 {
40 public:
41  FbxSpinLock();
42 
44  void Acquire();
45 
47  void Release();
48 
49 private:
50  FbxAtomic mSpinLock;
51 };
52 
60 {
61 public:
66  FbxMutex(bool pInitialOwnership=false);
67  virtual ~FbxMutex();
68 
72  void Acquire();
73 
79  bool TryAcquire(unsigned int pRetryCount);
80 
85  void Release();
86 
87 private:
88  FbxMutexImpl* mImpl;
89 };
90 
97 {
98 public:
99  FbxSemaphore();
100  virtual ~FbxSemaphore();
101 
107  bool Wait(unsigned int pCount=1);
108 
113  bool Signal(unsigned int pCount=1);
114 
115 private:
116  FbxSemaphoreImpl* mImpl;
117 };
118 
124 {
125 public:
126  FbxGate();
127  virtual ~FbxGate();
128 
132  void Open();
133 
135  void Close();
136 
140  bool IsOpen();
141 
146  bool Wait();
147 
148 private:
149  FbxGateImpl* mImpl;
150 };
151 
155 {
156 public:
158  struct Item
159  {
161  inline Item(){ mNext = NULL; }
162  inline Item* Set(Item* pNext){ return mNext = pNext; }
163  inline Item* Next(){ return mNext; }
164  };
165 
167  FbxSyncStack();
168 
172  void Push(Item* pItem);
173 
177  Item* Pop();
178 
179 private:
180  FbxSpinLock mLock;
181  Item* mTop;
182 };
183 
184 #include <fbxsdk/fbxsdk_nsend.h>
185 
186 #endif /* !FBXSDK_ENV_WINSTORE && !FBXSDK_ENV_EMSCRIPTEN */
187 
188 #endif /* _FBXSDK_CORE_SYNC_H_ */
A spinlock is the fastest and most simple thread lock mechanism available.
Definition: fbxsync.h:38
FBX SDK environment definition.
A simple stack of linked items that is multi-thread safe, protected by a spinlock.
Definition: fbxsync.h:154
#define NULL
Definition: fbxarch.h:210
Item * Next()
Definition: fbxsync.h:163
A gate thread locking mechanism is very similar to a semaphore, except that when it is opened...
Definition: fbxsync.h:123
Mutually excluding thread lock mechanism.
Definition: fbxsync.h:59
Item * Set(Item *pNext)
Definition: fbxsync.h:162
#define FBXSDK_DLL
Definition: fbxarch.h:173
Mutually excluding thread waiting mechanism with a counter.
Definition: fbxsync.h:96
A single link item to be used to construct the stack.
Definition: fbxsync.h:158