ScummVM API documentation
as_thread.h
1 /*
2  AngelCode Scripting Library
3  Copyright (c) 2003-2017 Andreas Jonsson
4 
5  This software is provided 'as-is', without any express or implied
6  warranty. In no event will the authors be held liable for any
7  damages arising from the use of this software.
8 
9  Permission is granted to anyone to use this software for any
10  purpose, including commercial applications, and to alter it and
11  redistribute it freely, subject to the following restrictions:
12 
13  1. The origin of this software must not be misrepresented; you
14  must not claim that you wrote the original software. If you use
15  this software in a product, an acknowledgment in the product
16  documentation would be appreciated but is not required.
17 
18  2. Altered source versions must be plainly marked as such, and
19  must not be misrepresented as being the original software.
20 
21  3. This notice may not be removed or altered from any source
22  distribution.
23 
24  The original version of this library can be located at:
25  http://www.angelcode.com/angelscript/
26 
27  Andreas Jonsson
28  andreas@angelcode.com
29 */
30 
31 
32 
33 //
34 // as_thread.h
35 //
36 // Classes for multi threading support
37 //
38 
39 #ifndef AS_THREAD_H
40 #define AS_THREAD_H
41 
42 #include "as_config.h"
43 #include "as_string.h"
44 #include "as_memory.h"
45 #include "as_map.h"
46 #include "as_criticalsection.h"
47 
48 BEGIN_AS_NAMESPACE
49 
50 class asCThreadLocalData;
51 
53 public:
54  static asCThreadLocalData *GetLocalData();
55  static int CleanupLocalData();
56 
57  static int Prepare(asIThreadManager *externalThreadMgr);
58  static void Unprepare();
59 
60  // This read/write lock can be used by the application to provide simple synchronization
61  DECLAREREADWRITELOCK(appRWLock)
62 
63 protected:
66 
67  // No need to use the atomic int here, as it will only be
68  // updated within the thread manager's critical section
69  int refCount;
70 
71 #ifndef AS_NO_THREADS
72 #if defined(_MSC_VER) && defined(AS_WINDOWS_THREADS) && (WINAPI_FAMILY & WINAPI_FAMILY_PHONE_APP)
73  // On Windows Store we must use MSVC specific thread variables for thread
74  // local storage, as the TLS API isn't available. On desktop we can't use
75  // this as it may cause problems if the library is used in a dll.
76  // ref: http://msdn.microsoft.com/en-us/library/2s9wt68x.aspx
77  // ref: http://msdn.microsoft.com/en-us/library/9w1sdazb.aspx
78  __declspec(thread) static asCThreadLocalData *tld;
79 #else
80  asDWORD tlsKey;
81 #endif
82  DECLARECRITICALSECTION(criticalSection)
83 #else
84  asCThreadLocalData *tld;
85 #endif
86 };
87 
88 //======================================================================
89 
90 class asIScriptContext;
91 
93 public:
94  asCArray<asIScriptContext *> activeContexts;
95  asCString string;
96 
97 protected:
98  friend class asCThreadManager;
99 
102 };
103 
104 END_AS_NAMESPACE
105 
106 #endif
Definition: as_thread.h:52
Definition: angelscript.h:863
Definition: angelscript.h:788
Definition: as_array.h:47
Definition: as_thread.h:92
Definition: as_string.h:41