CAEN Utility  2.0.2
Utilities for CAEN projects
CAENThreadTypes.h
Go to the documentation of this file.
1 /******************************************************************************
2 *
3 * CAEN SpA - Software Division
4 * Via Vetraia, 11 - 55049 - Viareggio ITALY
5 * +39 0594 388 398 - www.caen.it
6 *
7 *******************************************************************************
8 *
9 * Copyright (C) 2019-2022 CAEN SpA
10 *
11 * This file is part of the CAEN Utility.
12 *
13 * The CAEN Utility is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU Lesser General Public
15 * License as published by the Free Software Foundation; either
16 * version 3 of the License, or (at your option) any later version.
17 *
18 * The CAEN Utility 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 GNU
21 * Lesser General Public License for more details.
22 *
23 * You should have received a copy of the GNU Lesser General Public
24 * License along with the CAEN Utility; if not, see
25 * https://www.gnu.org/licenses/.
26 *
27 * SPDX-License-Identifier: LGPL-3.0-or-later
28 *
29 ***************************************************************************/
37 #ifndef CAEN_INCLUDE_TYPES_CAENTHREADTYPES_H_
38 #define CAEN_INCLUDE_TYPES_CAENTHREADTYPES_H_
39 
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 
44 #include <stdbool.h>
45 #include <stdint.h>
46 #include <time.h>
47 
48 #ifdef _WIN32
49 #include <WinSock2.h> // not needed here, but must be included before Windows.h if needed somewhere else
50 #include <Windows.h>
51 #else
52 #include <semaphore.h>
53 #include <pthread.h>
54 #endif
55 
56 #ifdef _WIN32 // Windows
57 // corresponding to thrd_t, inspired to _Thrd_t on xthreads.h
58 struct _c_thread_t {
59  HANDLE handle;
60  unsigned int id;
61  bool valid;
62 };
63 // Mutexes
64 typedef HANDLE c_mutex_t;
65 // Semaphores
66 typedef HANDLE c_semaphore_t;
67 // Condition
68 typedef CONDITION_VARIABLE c_conditionvariable_t;
69 #else
70 struct _c_thread_t {
71  pthread_t handle;
72  bool valid;
73 };
74 // Mutexs
75 typedef pthread_mutex_t c_mutex_t;
76 // Semaphores
77 typedef sem_t c_semaphore_t;
78 // Conditions
79 typedef pthread_cond_t c_conditionvariable_t;
80 #endif
81 typedef int(* c_tstart_t )(void*);
82 // Threads
83 typedef struct _c_thread_t c_thread_t;
84 
89 typedef struct {
90  c_conditionvariable_t _cond;
91 #ifdef _WIN32
92  CRITICAL_SECTION _critical_section;
93 #else
94  pthread_mutex_t _mutex;
95 #endif
97 
99 typedef struct {
101  uint64_t _queue_head;
102  uint64_t _queue_tail;
104 } c_ticket_t;
105 
107 typedef enum {
114 
115 #ifdef __cplusplus
116 }
117 #endif
118 
119 #endif // CAEN_INCLUDE_TYPES_CAENTHREADTYPES_H_
c_conditionvariable_t _cond
A condition variable.
pthread_t handle
Ticket type.
uint64_t _queue_head
pthread_cond_t c_conditionvariable_t
Condition variable type.
c_thread_t _holding_thread_id
c_condition_t _condition
pthread_mutex_t _mutex
On Linux a pthread_cond_t is use with a pthread_mutex_t.
sem_t c_semaphore_t
Semaphore type.
pthread_mutex_t c_mutex_t
Mutex type.
int(* c_tstart_t)(void *)
Thread function type, as defined in C11.
uint64_t _queue_tail
CAENThread_RetCode_t
Return values inspired to C11 thread.h.
Needed because a condition variable on Linux is associated with a mutex, while on Windows it is assoc...