3 /*-------------------------------------------------------------------------
4 * drawElements Thread Library
5 * ---------------------------
7 * Copyright 2014 The Android Open Source Project
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
23 * \brief Thread-safe singleton.
24 *//*--------------------------------------------------------------------*/
28 typedef enum deSingletonState_e
30 DE_SINGLETON_STATE_NOT_INITIALIZED = 0,
31 DE_SINGLETON_STATE_INITIALIZING,
32 DE_SINGLETON_STATE_INITIALIZED,
34 DE_SINGLETON_STATE_LAST
39 typedef void (*deSingletonConstructorFunc) (void* arg);
41 /*--------------------------------------------------------------------*//*!
42 * \brief Initialize singleton.
44 * This function ensures that singletonState = DE_SINGLETON_STATE_INITIALIZED
47 * If current singleton state is DE_SINGLETON_NOT_INITIALIZED, constructor
48 * function is called with the supplied argument (arg).
50 * It is guaranteed that constructor is called only once, even when multiple
51 * concurrent calls are made to deInitSingleton().
53 * Note that singletonState memory location must be initialized to
54 * DE_SINGLETON_STATE_NOT_INITIALIZED prior to any calls to deInitSingleton().
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);
62 void deSingleton_selfTest (void);
66 #endif /* _DESINGLETON_H */