]> git.cworth.org Git - vogl/blob - src/voglcore/lzma_Threads.h
Initial vogl checkin
[vogl] / src / voglcore / lzma_Threads.h
1 /**************************************************************************
2  *
3  * Copyright 2013-2014 RAD Game Tools and Valve Software
4  * Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC
5  * All Rights Reserved.
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a copy
8  * of this software and associated documentation files (the "Software"), to deal
9  * in the Software without restriction, including without limitation the rights
10  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11  * copies of the Software, and to permit persons to whom the Software is
12  * furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included in
15  * all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23  * THE SOFTWARE.
24  *
25  **************************************************************************/
26
27 /* Threads.h -- multithreading library
28 2008-11-22 : Igor Pavlov : Public domain */
29
30 #ifndef __7Z_THRESDS_H
31 #define __7Z_THRESDS_H
32
33 #include "lzma_Types.h"
34
35 namespace vogl
36 {
37
38     typedef struct _CThread
39     {
40         HANDLE handle;
41     } CThread;
42
43 #define Thread_Construct(thread) (thread)->handle = NULL
44 #define Thread_WasCreated(thread) ((thread)->handle != NULL)
45
46     typedef unsigned THREAD_FUNC_RET_TYPE;
47 #define THREAD_FUNC_CALL_TYPE MY_STD_CALL
48 #define THREAD_FUNC_DECL THREAD_FUNC_RET_TYPE THREAD_FUNC_CALL_TYPE
49
50     WRes Thread_Create(CThread *thread, THREAD_FUNC_RET_TYPE(THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter);
51     WRes Thread_Wait(CThread *thread);
52     WRes Thread_Close(CThread *thread);
53
54     typedef struct _CEvent
55     {
56         HANDLE handle;
57     } CEvent;
58
59     typedef CEvent CAutoResetEvent;
60     typedef CEvent CManualResetEvent;
61
62 #define Event_Construct(event) (event)->handle = NULL
63 #define Event_IsCreated(event) ((event)->handle != NULL)
64
65     WRes ManualResetEvent_Create(CManualResetEvent *event, int initialSignaled);
66     WRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *event);
67     WRes AutoResetEvent_Create(CAutoResetEvent *event, int initialSignaled);
68     WRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *event);
69     WRes Event_Set(CEvent *event);
70     WRes Event_Reset(CEvent *event);
71     WRes Event_Wait(CEvent *event);
72     WRes Event_Close(CEvent *event);
73
74     typedef struct _CSemaphore
75     {
76         HANDLE handle;
77     } CSemaphore;
78
79 #define Semaphore_Construct(p) (p)->handle = NULL
80
81     WRes Semaphore_Create(CSemaphore *p, UInt32 initiallyCount, UInt32 maxCount);
82     WRes Semaphore_ReleaseN(CSemaphore *p, UInt32 num);
83     WRes Semaphore_Release1(CSemaphore *p);
84     WRes Semaphore_Wait(CSemaphore *p);
85     WRes Semaphore_Close(CSemaphore *p);
86
87     typedef CRITICAL_SECTION CCriticalSection;
88
89     WRes CriticalSection_Init(CCriticalSection *p);
90 #define CriticalSection_Delete(p) DeleteCriticalSection(p)
91 #define CriticalSection_Enter(p) EnterCriticalSection(p)
92 #define CriticalSection_Leave(p) LeaveCriticalSection(p)
93 }
94
95 #endif