blob: 87071523daa898561927b1ac1f45499782f06f11 [file] [log] [blame]
Paul Bakker2466d932013-09-28 14:40:38 +02001/**
2 * \file threading.h
3 *
4 * \brief Threading abstraction layer
5 *
6 * Copyright (C) 2006-2013, Brainspark B.V.
7 *
8 * This file is part of PolarSSL (http://www.polarssl.org)
9 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
10 *
11 * All rights reserved.
12 *
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.
17 *
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.
22 *
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.
26 */
27#ifndef POLARSSL_THREADING_H
28#define POLARSSL_THREADING_H
29
30#include "config.h"
31
32#include <stdlib.h>
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
38#define POLARSSL_ERR_THREADING_FEATURE_UNAVAILABLE -0x001A /**< The selected feature is not available. */
39#define POLARSSL_ERR_THREADING_BAD_INPUT_DATA -0x001C /**< Bad input parameters to function. */
40#define POLARSSL_ERR_THREADING_MUTEX_ERROR -0x001E /**< Locking / unlocking / free failed with error code. */
41
Paul Bakker2466d932013-09-28 14:40:38 +020042#if defined(POLARSSL_THREADING_PTHREAD)
43#include <pthread.h>
44typedef pthread_mutex_t threading_mutex_t;
45#endif
46
47#if defined(POLARSSL_THREADING_ALT)
48/* You should define the threading_mutex_t type in your header */
49#include "threading_alt.h"
50
51/**
52 * \brief Set your alternate threading implementation function
53 * pointers
54 *
Paul Bakker6838bd12013-09-30 13:56:38 +020055 * \param mutex_init the init function implementation
Paul Bakker2466d932013-09-28 14:40:38 +020056 * \param mutex_free the free function implementation
57 * \param mutex_lock the lock function implementation
58 * \param mutex_unlock the unlock function implementation
59 *
60 * \return 0 if successful
61 */
62int threading_set_alt( int (*mutex_init)( threading_mutex_t * ),
63 int (*mutex_free)( threading_mutex_t * ),
64 int (*mutex_lock)( threading_mutex_t * ),
65 int (*mutex_unlock)( threading_mutex_t * ) );
66#endif /* POLARSSL_THREADING_ALT_C */
67
68/*
69 * The function pointers for mutex_init, mutex_free, mutex_ and mutex_unlock
Paul Bakker6838bd12013-09-30 13:56:38 +020070 *
71 * All these functions are expected to work or the result will be undefined.
Paul Bakker2466d932013-09-28 14:40:38 +020072 */
73extern int (*polarssl_mutex_init)( threading_mutex_t *mutex );
74extern int (*polarssl_mutex_free)( threading_mutex_t *mutex );
75extern int (*polarssl_mutex_lock)( threading_mutex_t *mutex );
76extern int (*polarssl_mutex_unlock)( threading_mutex_t *mutex );
77
78#ifdef __cplusplus
79}
80#endif
81
82#endif /* threading.h */