aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/suricata/src/threads-arch-tile.h
blob: d022d90e339f331404e670f0d190061aad8bc7c1 (plain)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/* Copyright (C) 2011-2013 Open Information Security Foundation
 *
 * You can copy, redistribute or modify this Program under the terms of
 * the GNU General Public License version 2 as published by the Free
 * Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * version 2 along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301, USA.
 */

/**
 * \file
 *
 * \author Ken Steele, Tilera Corporation <suricata@tilera.com>
 */

#ifndef __THREADS_ARCH_TILE_H__
#define __THREADS_ARCH_TILE_H__

#include <tmc/spin.h>
#include <arch/cycle.h>

/* NOTE: On Tilera datapath threads use the TMC (Tilera Multicore
 * Components) library spin mutexes while the control threads use
 * pthread mutexes.  So the pthread mutex types are split out so that
 * their use can be differentiated.
 */

/* ctrl mutex */
#define SCCtrlMutex pthread_mutex_t
#define SCCtrlMutexAttr pthread_mutexattr_t
#define SCCtrlMutexInit(mut, mutattr ) pthread_mutex_init(mut, mutattr)
#define SCCtrlMutexLock(mut) pthread_mutex_lock(mut)
#define SCCtrlMutexTrylock(mut) pthread_mutex_trylock(mut)
#define SCCtrlMutexUnlock(mut) pthread_mutex_unlock(mut)
#define SCCtrlMutexDestroy pthread_mutex_destroy

/* ctrl cond */
#define SCCtrlCondT pthread_cond_t
#define SCCtrlCondInit pthread_cond_init
#define SCCtrlCondSignal pthread_cond_signal
#define SCCtrlCondTimedwait pthread_cond_timedwait
#define SCCtrlCondWait pthread_cond_wait
#define SCCtrlCondDestroy pthread_cond_destroy

/* mutex */

#define SCMutex tmc_spin_queued_mutex_t
#define SCMutexAttr
#define SCMutexDestroy(x) ({ (void)(x); 0; })
#define SCMUTEX_INITIALIZER TMC_SPIN_QUEUED_MUTEX_INIT
#define SCMutexInit(mut, mutattr) ({ \
    int ret = 0; \
    tmc_spin_queued_mutex_init(mut); \
    ret; \
})
#define SCMutexLock(mut) ({ \
    int ret = 0; \
    tmc_spin_queued_mutex_lock(mut); \
    ret; \
})
#define SCMutexTrylock(mut) ({ \
    int ret = (tmc_spin_queued_mutex_trylock(mut) == 0) ? 0 : EBUSY; \
    ret; \
})
#define SCMutexUnlock(mut) ({ \
    int ret = 0; \
    tmc_spin_queued_mutex_unlock(mut); \
    ret; \
})

/* conditions */

/* Ignore signals when using spin locks */
#define SCCondT uint8_t
#define SCCondInit(x,y) ({ 0; })
#define SCCondSignal(x) ({ 0; })
#define SCCondDestroy(x) ({ 0; })

static inline void cycle_sleep(int cycles)
{
  uint64_t end = get_cycle_count() + cycles;
  while (get_cycle_count() < end)
    ;
}
#define SCCondWait(x,y) cycle_sleep(300)

/* spinlocks */

#define SCSpinlock                              tmc_spin_queued_mutex_t
#define SCSpinLock(spin)                        ({ tmc_spin_queued_mutex_lock(spin); 0; })
#define SCSpinTrylock(spin)                     (tmc_spin_queued_mutex_trylock(spin) ? EBUSY : 0)
#define SCSpinUnlock(spin)                      ({ tmc_spin_queued_mutex_unlock(spin); 0; })
#define SCSpinInit(spin, spin_attr)             ({ tmc_spin_queued_mutex_init(spin); 0; })
#define SCSpinDestroy(spin)                     ({ (void)(spin); 0; })

/* rwlocks */

#define SCRWLock tmc_spin_rwlock_t
#define SCRWLockDestroy(x) ({ (void)(x); 0; })
#define SCRWLockInit(rwl, rwlattr ) ({ tmc_spin_rwlock_init(rwl); 0; })
#define SCRWLockWRLock(rwl) ({ tmc_spin_rwlock_wrlock(rwl); 0; })
#define SCRWLockRDLock(rwl) ({ tmc_spin_rwlock_rdlock(rwl); 0; })
#define SCRWLockTryWRLock(rwl) (tmc_spin_rwlock_trywrlock(rwl) ? EBUSY : 0)
#define SCRWLockTryRDLock(rwl) (tmc_spin_rwlock_tryrdlock(rwl) ? EBUSY : 0)
#define SCRWLockUnlock(rwl) ({ tmc_spin_rwlock_unlock(rwl); 0; })
#endif