|
Packit Service |
310c69 |
/*
|
|
Packit Service |
310c69 |
* Copyright (c) 2020 Red Hat, Inc.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* This program is free software; you can redistribute it and/or
|
|
Packit Service |
310c69 |
* modify it under the terms of the GNU General Public License
|
|
Packit Service |
310c69 |
* as published by the Free Software Foundation; either version 2
|
|
Packit Service |
310c69 |
* of the License, or (at your option) any later version.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* This program is distributed in the hope that it will be useful,
|
|
Packit Service |
310c69 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
310c69 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit Service |
310c69 |
* GNU General Public License for more details.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* You should have received a copy of the GNU General Public License
|
|
Packit Service |
310c69 |
* along with this program; if not, write to the Free Software
|
|
Packit Service |
310c69 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
Packit Service |
310c69 |
* 02110-1301, USA.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* $Id: //eng/uds-releases/jasper/src/uds/threadOnce.h#1 $
|
|
Packit Service |
310c69 |
*/
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#ifndef THREAD_ONCE_H
|
|
Packit Service |
310c69 |
#define THREAD_ONCE_H
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#include "atomicDefs.h"
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#define ONCE_STATE_INITIALIZER ATOMIC_INIT(0)
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
typedef atomic_t OnceState;
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Thread safe once only initialization.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param onceState pointer to object to record that initialization
|
|
Packit Service |
310c69 |
* has been performed
|
|
Packit Service |
310c69 |
* @param initFunction called if onceState does not indicate
|
|
Packit Service |
310c69 |
* initialization has been performed
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return UDS_SUCCESS or error code
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @note Generally the following declaration of onceState is performed in
|
|
Packit Service |
310c69 |
* at file scope:
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* static OnceState onceState = ONCE_STATE_INITIALIZER;
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int performOnce(OnceState *onceState, void (*initFunction) (void));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#endif /* THREAD_ONCE_H */
|