Merge vk-gl-cts/opengl-es-cts-3.2.3 into vk-gl-cts/opengl-es-cts-3.2.4
[platform/upstream/VK-GL-CTS.git] / framework / delibs / dethread / deSingleton.h
1 #ifndef _DESINGLETON_H
2 #define _DESINGLETON_H
3 /*-------------------------------------------------------------------------
4  * drawElements Thread Library
5  * ---------------------------
6  *
7  * Copyright 2014 The Android Open Source Project
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  *//*!
22  * \file
23  * \brief Thread-safe singleton.
24  *//*--------------------------------------------------------------------*/
25
26 #include "deDefs.h"
27
28 typedef enum deSingletonState_e
29 {
30         DE_SINGLETON_STATE_NOT_INITIALIZED = 0,
31         DE_SINGLETON_STATE_INITIALIZING,
32         DE_SINGLETON_STATE_INITIALIZED,
33
34         DE_SINGLETON_STATE_LAST
35 } deSingletonState;
36
37 DE_BEGIN_EXTERN_C
38
39 typedef void    (*deSingletonConstructorFunc)           (void* arg);
40
41 /*--------------------------------------------------------------------*//*!
42  * \brief Initialize singleton.
43  *
44  * This function ensures that singletonState = DE_SINGLETON_STATE_INITIALIZED
45  * upon return.
46  *
47  * If current singleton state is DE_SINGLETON_NOT_INITIALIZED, constructor
48  * function is called with the supplied argument (arg).
49  *
50  * It is guaranteed that constructor is called only once, even when multiple
51  * concurrent calls are made to deInitSingleton().
52  *
53  * Note that singletonState memory location must be initialized to
54  * DE_SINGLETON_STATE_NOT_INITIALIZED prior to any calls to deInitSingleton().
55  *
56  * \param singletonState        Pointer to singleton state.
57  * \param constructor           Constructor function.
58  * \param arg                           Generic arg pointer for constructor.
59  *//*--------------------------------------------------------------------*/
60 void                    deInitSingleton                                         (volatile deSingletonState* singletonState, deSingletonConstructorFunc constructor, void* arg);
61
62 void                    deSingleton_selfTest                            (void);
63
64 DE_END_EXTERN_C
65
66 #endif /* _DESINGLETON_H */