Skip to content

Commit 7d1c5bf

Browse files
committed
remove semaphore from arp cache lock
1 parent c9a04d4 commit 7d1c5bf

File tree

1 file changed

+8
-32
lines changed

1 file changed

+8
-32
lines changed

arp/arp_cache.c

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,46 +8,22 @@
88
#define arp_cache_end (&arp_cache[ARP_CACHE_SZ])
99
static struct arpentry arp_cache[ARP_CACHE_SZ];
1010

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 */
3912
#ifdef STATIC_MUTEX
4013
pthread_mutex_t arp_cache_mutex = PTHREAD_MUTEX_INITIALIZER;
4114
#else
4215
pthread_mutex_t arp_cache_mutex;
16+
/* Why are they not defined in pthread.h? */
4317
#ifndef PTHREAD_MUTEX_NORMAL
4418
#define PTHREAD_MUTEX_NORMAL PTHREAD_MUTEX_TIMED_NP
4519
#endif
20+
#endif /* STATIC_MUTEX */
4621

47-
#endif
22+
/* Lock Init */
4823
static _inline void arp_cache_lock_init(void)
4924
{
5025
#ifndef STATIC_MUTEX
26+
/* It is evil to init pthread mutex dynamically X< */
5127
pthread_mutexattr_t attr;
5228
if (pthread_mutexattr_init(&attr) != 0)
5329
perrx("pthread_mutexattr_init");
@@ -58,6 +34,7 @@ static _inline void arp_cache_lock_init(void)
5834
#endif
5935
}
6036

37+
/* Lock Function */
6138
#ifdef DEBUG_ARPCACHE_LOCK
6239
#define arp_cache_lock() do { dbg("lock"); pthread_mutex_lock(&arp_cache_mutex); } while(0)
6340
#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)
7249
pthread_mutex_unlock(&arp_cache_mutex);
7350
}
7451
#endif /* end DEBUG_ARPCACHE_LOCK */
75-
#endif /* end LOCK_SEM */
7652

7753
void arp_queue_send(struct arpentry *ae)
7854
{
@@ -210,14 +186,14 @@ void arp_cache_init(void)
210186
dbg("ARP CACHE SEMAPHORE INIT");
211187
}
212188

213-
static char *__arpstate[] = {
189+
static const char *__arpstate[] = {
214190
NULL,
215191
"Free",
216192
"Waiting",
217193
"Resolved"
218194
};
219195

220-
static inline char *arpstate(struct arpentry *ae)
196+
static _inline const char *arpstate(struct arpentry *ae)
221197
{
222198
return __arpstate[ae->ae_state];
223199
}

0 commit comments

Comments
 (0)