suricata
threads-arch-tile.h
Go to the documentation of this file.
1 /* Copyright (C) 2011-2013 Open Information Security Foundation
2  *
3  * You can copy, redistribute or modify this Program under the terms of
4  * the GNU General Public License version 2 as published by the Free
5  * Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * version 2 along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15  * 02110-1301, USA.
16  */
17 
18 /**
19  * \file
20  *
21  * \author Ken Steele, Tilera Corporation <suricata@tilera.com>
22  */
23 
24 #ifndef __THREADS_ARCH_TILE_H__
25 #define __THREADS_ARCH_TILE_H__
26 
27 #include <tmc/spin.h>
28 #include <arch/cycle.h>
29 
30 /* NOTE: On Tilera datapath threads use the TMC (Tilera Multicore
31  * Components) library spin mutexes while the control threads use
32  * pthread mutexes. So the pthread mutex types are split out so that
33  * their use can be differentiated.
34  */
35 
36 /* ctrl mutex */
37 #define SCCtrlMutex pthread_mutex_t
38 #define SCCtrlMutexAttr pthread_mutexattr_t
39 #define SCCtrlMutexInit(mut, mutattr ) pthread_mutex_init(mut, mutattr)
40 #define SCCtrlMutexLock(mut) pthread_mutex_lock(mut)
41 #define SCCtrlMutexTrylock(mut) pthread_mutex_trylock(mut)
42 #define SCCtrlMutexUnlock(mut) pthread_mutex_unlock(mut)
43 #define SCCtrlMutexDestroy pthread_mutex_destroy
44 
45 /* ctrl cond */
46 #define SCCtrlCondT pthread_cond_t
47 #define SCCtrlCondInit pthread_cond_init
48 #define SCCtrlCondSignal pthread_cond_signal
49 #define SCCtrlCondTimedwait pthread_cond_timedwait
50 #define SCCtrlCondWait pthread_cond_wait
51 #define SCCtrlCondDestroy pthread_cond_destroy
52 
53 /* mutex */
54 
55 #define SCMutex tmc_spin_queued_mutex_t
56 #define SCMutexAttr
57 #define SCMutexDestroy(x) ({ (void)(x); 0; })
58 #define SCMUTEX_INITIALIZER TMC_SPIN_QUEUED_MUTEX_INIT
59 #define SCMutexInit(mut, mutattr) ({ \
60  int ret = 0; \
61  tmc_spin_queued_mutex_init(mut); \
62  ret; \
63 })
64 #define SCMutexLock(mut) ({ \
65  int ret = 0; \
66  tmc_spin_queued_mutex_lock(mut); \
67  ret; \
68 })
69 #define SCMutexTrylock(mut) ({ \
70  int ret = (tmc_spin_queued_mutex_trylock(mut) == 0) ? 0 : EBUSY; \
71  ret; \
72 })
73 #define SCMutexUnlock(mut) ({ \
74  int ret = 0; \
75  tmc_spin_queued_mutex_unlock(mut); \
76  ret; \
77 })
78 
79 /* conditions */
80 
81 /* Ignore signals when using spin locks */
82 #define SCCondT uint8_t
83 #define SCCondInit(x,y) ({ 0; })
84 #define SCCondSignal(x) ({ 0; })
85 #define SCCondDestroy(x) ({ 0; })
86 
87 static inline void cycle_sleep(int cycles)
88 {
89  uint64_t end = get_cycle_count() + cycles;
90  while (get_cycle_count() < end)
91  ;
92 }
93 #define SCCondWait(x,y) cycle_sleep(300)
94 
95 /* spinlocks */
96 
97 #define SCSpinlock tmc_spin_queued_mutex_t
98 #define SCSpinLock(spin) ({ tmc_spin_queued_mutex_lock(spin); 0; })
99 #define SCSpinTrylock(spin) (tmc_spin_queued_mutex_trylock(spin) ? EBUSY : 0)
100 #define SCSpinUnlock(spin) ({ tmc_spin_queued_mutex_unlock(spin); 0; })
101 #define SCSpinInit(spin, spin_attr) ({ tmc_spin_queued_mutex_init(spin); 0; })
102 #define SCSpinDestroy(spin) ({ (void)(spin); 0; })
103 
104 /* rwlocks */
105 
106 #define SCRWLock tmc_spin_rwlock_t
107 #define SCRWLockDestroy(x) ({ (void)(x); 0; })
108 #define SCRWLockInit(rwl, rwlattr ) ({ tmc_spin_rwlock_init(rwl); 0; })
109 #define SCRWLockWRLock(rwl) ({ tmc_spin_rwlock_wrlock(rwl); 0; })
110 #define SCRWLockRDLock(rwl) ({ tmc_spin_rwlock_rdlock(rwl); 0; })
111 #define SCRWLockTryWRLock(rwl) (tmc_spin_rwlock_trywrlock(rwl) ? EBUSY : 0)
112 #define SCRWLockTryRDLock(rwl) (tmc_spin_rwlock_tryrdlock(rwl) ? EBUSY : 0)
113 #define SCRWLockUnlock(rwl) ({ tmc_spin_rwlock_unlock(rwl); 0; })
114 #endif