PIOMan

Documentation

piom_lock_nothread.h
Go to the documentation of this file.
1/*
2 * Pioman: a Generic I/O Manager
3 * Copyright (C) 2008-2023 (see AUTHORS file)
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or (at
8 * your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 */
15
16#ifndef PIOM_NOTHREAD_H
17#define PIOM_NOTHREAD_H
18
19#ifndef PIOM_CONFIG_H
20# error "Cannot include this file directly. Please include <pioman.h>."
21#endif /* PIOM_CONFIG_H */
22
23#ifdef PIOMAN_MULTITHREAD
24# error "inconsistency detected: PIOMAN_MULTITHREAD defined in piom_nothread.h"
25#endif /* PIOMAN_MULTITHREAD */
26
27#include <stdio.h>
28#include <stdlib.h>
29#include <stdint.h>
30#include <unistd.h>
31
32/* ** base dummy types ************************************* */
33
34#define piom_thread_t int
35#define PIOM_THREAD_NULL 0
36#define PIOM_THREAD_SELF 1
37
38/* ** spinlocks for no-thread ****************************** */
39
40typedef int piom_spinlock_t;
41
42static inline void piom_spin_init(piom_spinlock_t*lock)
43{
44 *lock = 0;
45}
46static inline void piom_spin_destroy(piom_spinlock_t*lock)
47{
48 assert(*lock == 0);
49}
50static inline void piom_spin_lock(piom_spinlock_t*lock)
51{
52 assert(*lock == 0);
53 *lock = 1;
54}
55static inline void piom_spin_unlock(piom_spinlock_t*lock)
56{
57 assert(*lock == 1);
58 *lock = 0;
59}
60static inline int piom_spin_trylock(piom_spinlock_t*lock)
61{
62 if(*lock == 0)
63 {
64 *lock = 1;
65 return 1;
66 }
67 else
68 {
69 return 0;
70 }
71}
72
74{
75 assert(*lock != 0);
76}
77
79{
80 assert(*lock == 0);
81}
82
83
84/* ** semaphores ******************************************* */
85
87typedef int piom_sem_t;
88
89static inline void piom_sem_P(piom_sem_t*sem)
90{
91 (*sem)--;
92 while((*sem) < 0)
93 {
95 }
96}
97
98static inline void piom_sem_V(piom_sem_t*sem)
99{
100 (*sem)++;
101}
102
103static inline void piom_sem_init(piom_sem_t*sem, int initial)
104{
105 (*sem) = initial;
106}
107
108#endif /* PIOM_NOTHREAD_H */
void piom_ltask_schedule(int point)
Schedule tasks from local or all queues (depending on 'point')
#define PIOM_POLL_POINT_BUSY
poll in a busy wait
Definition: pioman.h:86
ABT_mutex piom_spinlock_t
Definition: piom_lock_abt.h:45
static void piom_spin_assert_locked(piom_spinlock_t *lock)
static void piom_spin_lock(piom_spinlock_t *lock)
static void piom_spin_init(piom_spinlock_t *lock)
static void piom_spin_assert_notlocked(piom_spinlock_t *lock)
static void piom_sem_P(piom_sem_t *sem)
static void piom_spin_unlock(piom_spinlock_t *lock)
int piom_sem_t
dummy non-threaded semaphore
static int piom_spin_trylock(piom_spinlock_t *lock)
static void piom_sem_V(piom_sem_t *sem)
int piom_spinlock_t
static void piom_sem_init(piom_sem_t *sem, int initial)
static void piom_spin_destroy(piom_spinlock_t *lock)