4 * \brief Threading abstraction layer
6 * Copyright (C) 2006-2013, Brainspark B.V.
8 * This file is part of PolarSSL (http://www.polarssl.org)
9 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
11 * All rights reserved.
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 #ifndef POLARSSL_THREADING_H
28 #define POLARSSL_THREADING_H
30 #if !defined(POLARSSL_CONFIG_FILE)
33 #include POLARSSL_CONFIG_FILE
42 #define POLARSSL_ERR_THREADING_FEATURE_UNAVAILABLE -0x001A /**< The selected feature is not available. */
43 #define POLARSSL_ERR_THREADING_BAD_INPUT_DATA -0x001C /**< Bad input parameters to function. */
44 #define POLARSSL_ERR_THREADING_MUTEX_ERROR -0x001E /**< Locking / unlocking / free failed with error code. */
46 #if defined(POLARSSL_THREADING_PTHREAD)
48 typedef pthread_mutex_t threading_mutex_t
;
51 #if defined(POLARSSL_THREADING_ALT)
52 /* You should define the threading_mutex_t type in your header */
53 #include "threading_alt.h"
56 * \brief Set your alternate threading implementation function
59 * \param mutex_init the init function implementation
60 * \param mutex_free the free function implementation
61 * \param mutex_lock the lock function implementation
62 * \param mutex_unlock the unlock function implementation
64 * \return 0 if successful
66 int threading_set_alt( int (*mutex_init
)( threading_mutex_t
* ),
67 int (*mutex_free
)( threading_mutex_t
* ),
68 int (*mutex_lock
)( threading_mutex_t
* ),
69 int (*mutex_unlock
)( threading_mutex_t
* ) );
70 #endif /* POLARSSL_THREADING_ALT_C */
73 * The function pointers for mutex_init, mutex_free, mutex_ and mutex_unlock
75 * All these functions are expected to work or the result will be undefined.
77 extern int (*polarssl_mutex_init
)( threading_mutex_t
*mutex
);
78 extern int (*polarssl_mutex_free
)( threading_mutex_t
*mutex
);
79 extern int (*polarssl_mutex_lock
)( threading_mutex_t
*mutex
);
80 extern int (*polarssl_mutex_unlock
)( threading_mutex_t
*mutex
);
86 #endif /* threading.h */