8
8
#define arp_cache_end (&arp_cache[ARP_CACHE_SZ])
9
9
static struct arpentry arp_cache [ARP_CACHE_SZ ];
10
10
11
- #ifdef LOCK_SEM
12
-
13
- #include <semaphore.h>
14
- static sem_t arp_cache_sem ; /* arp cache lock */
15
- static _inline void arp_cache_lock_init (void )
16
- {
17
- if (sem_init (& arp_cache_sem , 0 , 1 ) == -1 )
18
- perrx ("sem_init" );
19
- }
20
-
21
- #ifdef DEBUG_ARPCACHE_LOCK
22
- #define arp_cache_lock () do { dbg("lock"); sem_wait(&arp_cache_sem); } while(0)
23
- #define arp_cache_unlock () do { dbg("unlock"); sem_post(&arp_cache_sem); } while(0)
24
- #else /* !DEBUG_ARPCACHE_LOCK */
25
- static _inline void arp_cache_lock (void )
26
- {
27
- sem_wait (& arp_cache_sem );
28
- }
29
-
30
- static _inline void arp_cache_unlock (void )
31
- {
32
- sem_post (& arp_cache_sem );
33
- }
34
- #endif /* end DEBUG_ARPCACHE_LOCK */
35
-
36
- #else /* !DEBUG_SEM */
37
-
38
- /* It is evil to init pthread mutex dynamically X< */
11
+ /* Lock Definition */
39
12
#ifdef STATIC_MUTEX
40
13
pthread_mutex_t arp_cache_mutex = PTHREAD_MUTEX_INITIALIZER ;
41
14
#else
42
15
pthread_mutex_t arp_cache_mutex ;
16
+ /* Why are they not defined in pthread.h? */
43
17
#ifndef PTHREAD_MUTEX_NORMAL
44
18
#define PTHREAD_MUTEX_NORMAL PTHREAD_MUTEX_TIMED_NP
45
19
#endif
20
+ #endif /* STATIC_MUTEX */
46
21
47
- #endif
22
+ /* Lock Init */
48
23
static _inline void arp_cache_lock_init (void )
49
24
{
50
25
#ifndef STATIC_MUTEX
26
+ /* It is evil to init pthread mutex dynamically X< */
51
27
pthread_mutexattr_t attr ;
52
28
if (pthread_mutexattr_init (& attr ) != 0 )
53
29
perrx ("pthread_mutexattr_init" );
@@ -58,6 +34,7 @@ static _inline void arp_cache_lock_init(void)
58
34
#endif
59
35
}
60
36
37
+ /* Lock Function */
61
38
#ifdef DEBUG_ARPCACHE_LOCK
62
39
#define arp_cache_lock () do { dbg("lock"); pthread_mutex_lock(&arp_cache_mutex); } while(0)
63
40
#define arp_cache_unlock () do { dbg("unlock"); pthread_mutex_unlock(&arp_cache_mutex); } while(0)
@@ -72,7 +49,6 @@ static _inline void arp_cache_unlock(void)
72
49
pthread_mutex_unlock (& arp_cache_mutex );
73
50
}
74
51
#endif /* end DEBUG_ARPCACHE_LOCK */
75
- #endif /* end LOCK_SEM */
76
52
77
53
void arp_queue_send (struct arpentry * ae )
78
54
{
@@ -210,14 +186,14 @@ void arp_cache_init(void)
210
186
dbg ("ARP CACHE SEMAPHORE INIT" );
211
187
}
212
188
213
- static char * __arpstate [] = {
189
+ static const char * __arpstate [] = {
214
190
NULL ,
215
191
"Free" ,
216
192
"Waiting" ,
217
193
"Resolved"
218
194
};
219
195
220
- static inline char * arpstate (struct arpentry * ae )
196
+ static _inline const char * arpstate (struct arpentry * ae )
221
197
{
222
198
return __arpstate [ae -> ae_state ];
223
199
}
0 commit comments