1 /**************************************************************************
3 * Copyright 2013-2014 RAD Game Tools and Valve Software
4 * Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC
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:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
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
25 **************************************************************************/
27 /* Threads.h -- multithreading library
28 2008-11-22 : Igor Pavlov : Public domain */
30 #ifndef __7Z_THRESDS_H
31 #define __7Z_THRESDS_H
33 #include "lzma_Types.h"
38 typedef struct _CThread
43 #define Thread_Construct(thread) (thread)->handle = NULL
44 #define Thread_WasCreated(thread) ((thread)->handle != NULL)
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
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);
54 typedef struct _CEvent
59 typedef CEvent CAutoResetEvent;
60 typedef CEvent CManualResetEvent;
62 #define Event_Construct(event) (event)->handle = NULL
63 #define Event_IsCreated(event) ((event)->handle != NULL)
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);
74 typedef struct _CSemaphore
79 #define Semaphore_Construct(p) (p)->handle = NULL
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);
87 typedef CRITICAL_SECTION CCriticalSection;
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)