File: mt-types.h

package info (click to toggle)
mpsolve 3.2.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,100 kB
  • sloc: ansic: 25,748; sh: 4,925; cpp: 3,155; makefile: 914; python: 407; yacc: 158; lex: 85; xml: 41
file content (56 lines) | stat: -rw-r--r-- 1,203 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
 * This file is part of MPSolve 3.2.2
 *
 * Copyright (C) 2001-2020, Dipartimento di Matematica "L. Tonelli", Pisa.
 * License: http://www.gnu.org/licenses/gpl.html GPL version 3 or higher
 *
 * Authors:
 *   Leonardo Robol <leonardo.robol@unipi.it>
 */

#include <pthread.h>
#include <mps/mps.h>

/**
 * @file
 * @brief Implementation of some thread-safe types that can be easily used
 * with the macro MPS_LOCK() and MPS_UNLOCK().
 */

#ifndef MPS_MT_TYPES_
#define MPS_MT_TYPES_

#define MPS_LOCK(x) (pthread_mutex_lock (&(x).mutex))

#define MPS_UNLOCK(x) (pthread_mutex_unlock (&(x).mutex))

#define MPS_INIT_LOCK(x) (pthread_mutex_init (&(x).mutex, NULL))

/**
 * @brief A thread safe version of mps_boolean.
 *
 * Must be accessed using the macro MPS_LOCK (x) and
 * MPS_UNLOCK (x).
 */
struct mps_boolean_mt {
  mps_boolean value;
  pthread_mutex_t mutex;
};

/**
 * @brief A thread safe version of mps_boolean.
 *
 * Must be accessed using the macro MPS_LOCK (x) and
 * MPS_UNLOCK (x).
 */
struct mps_long_int_mt {
  long int value;
  pthread_mutex_t mutex;
};

#ifndef __cplusplus
typedef struct mps_boolean_mt mps_boolean_mt;
typedef struct mps_long_int_mt mps_long_int_mt;

#endif
#endif