Skip to content

Commit 2014d93

Browse files
authored
Merge pull request #39 from ogournet/dlock
dlock: remove unused refcnt
2 parents bb610c5 + 2f13bb7 commit 2014d93

File tree

3 files changed

+26
-43
lines changed

3 files changed

+26
-43
lines changed

src/gtp_conn.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ extern thread_master_t *master;
3939
/* Local data */
4040
struct hlist_head *gtp_conn_tab;
4141
static int gtp_conn_tab_cnt = 0;
42-
dlock_mutex_t *__gtp_conn_lock_array;
42+
pthread_mutex_t *__gtp_conn_lock_array;
4343

4444

4545
/*
@@ -60,15 +60,15 @@ gtp_conn_unlock_id(uint64_t id)
6060
int
6161
gtp_conn_lock_init(void)
6262
{
63-
__gtp_conn_lock_array = dlock_init();
64-
return 0;
63+
__gtp_conn_lock_array = dlock_init();
64+
return 0;
6565
}
6666

6767
int
6868
gtp_conn_lock_destroy(void)
6969
{
7070
FREE(__gtp_conn_lock_array);
71-
return 0;
71+
return 0;
7272
}
7373

7474

@@ -78,18 +78,18 @@ gtp_conn_lock_destroy(void)
7878
int
7979
gtp_conn_get(gtp_conn_t *c)
8080
{
81-
if (!c)
82-
return 0;
83-
__sync_add_and_fetch(&c->refcnt, 1);
81+
if (!c)
82+
return 0;
83+
__sync_add_and_fetch(&c->refcnt, 1);
8484
return 0;
8585
}
8686

8787
int
8888
gtp_conn_put(gtp_conn_t *c)
8989
{
90-
if (!c)
91-
return 0;
92-
__sync_sub_and_fetch(&c->refcnt, 1);
90+
if (!c)
91+
return 0;
92+
__sync_sub_and_fetch(&c->refcnt, 1);
9393
return 0;
9494
}
9595

src/gtp_htab.c

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -33,45 +33,34 @@
3333

3434

3535
/*
36-
* Distributate lock handling
36+
* Distributed lock handling
3737
*/
38-
static dlock_mutex_t *
39-
dlock_hash(dlock_mutex_t *__array, uint32_t w1, uint32_t w2)
38+
static pthread_mutex_t *
39+
dlock_hash(pthread_mutex_t *__array, uint32_t w1, uint32_t w2)
4040
{
41-
return __array + (jhash_2words(w1, w2, 0) & DLOCK_HASHTAB_MASK);
41+
return &__array[(jhash_2words(w1, w2, 0) & DLOCK_HASHTAB_MASK)];
4242
}
4343

4444
int
45-
dlock_lock_id(dlock_mutex_t *__array, uint32_t w1, uint32_t w2)
45+
dlock_lock_id(pthread_mutex_t *__array, uint32_t w1, uint32_t w2)
4646
{
47-
dlock_mutex_t *m = dlock_hash(__array, w1, w2);
48-
pthread_mutex_lock(&m->mutex);
49-
__sync_add_and_fetch(&m->refcnt, 1);
47+
pthread_mutex_t *m = dlock_hash(__array, w1, w2);
48+
pthread_mutex_lock(m);
5049
return 0;
5150
}
5251

5352
int
54-
dlock_unlock_id(dlock_mutex_t *__array, uint32_t w1, uint32_t w2)
53+
dlock_unlock_id(pthread_mutex_t *__array, uint32_t w1, uint32_t w2)
5554
{
56-
dlock_mutex_t *m = dlock_hash(__array, w1, w2);
57-
if (__sync_sub_and_fetch(&m->refcnt, 1) == 0)
58-
pthread_mutex_unlock(&m->mutex);
55+
pthread_mutex_t *m = dlock_hash(__array, w1, w2);
56+
pthread_mutex_unlock(m);
5957
return 0;
6058
}
6159

62-
dlock_mutex_t *
60+
pthread_mutex_t *
6361
dlock_init(void)
6462
{
65-
dlock_mutex_t *new;
66-
new = (dlock_mutex_t *) MALLOC(DLOCK_HASHTAB_SIZE * sizeof(dlock_mutex_t));
67-
return new;
68-
}
69-
70-
int
71-
dlock_destroy(dlock_mutex_t *__array)
72-
{
73-
FREE(__array);
74-
return 0;
63+
return MALLOC(DLOCK_HASHTAB_SIZE * sizeof(pthread_mutex_t));
7564
}
7665

7766
/*

src/include/gtp_htab.h

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,16 @@
2727
#define DLOCK_HASHTAB_SIZE (1 << DLOCK_HASHTAB_BITS)
2828
#define DLOCK_HASHTAB_MASK (DLOCK_HASHTAB_SIZE - 1)
2929

30-
typedef struct _dlock_mutex {
31-
pthread_mutex_t mutex;
32-
uint32_t refcnt;
33-
} dlock_mutex_t;
34-
3530
/* htab */
3631
typedef struct _gtp_htab {
3732
struct hlist_head *htab;
38-
dlock_mutex_t *dlock;
33+
pthread_mutex_t *dlock;
3934
} gtp_htab_t;
4035

4136
/* Prototypes */
42-
extern int dlock_lock_id(dlock_mutex_t *, uint32_t, uint32_t);
43-
extern int dlock_unlock_id(dlock_mutex_t *, uint32_t, uint32_t);
44-
extern dlock_mutex_t *dlock_init(void);
45-
extern int dlock_destroy(dlock_mutex_t *);
37+
extern int dlock_lock_id(pthread_mutex_t *, uint32_t, uint32_t);
38+
extern int dlock_unlock_id(pthread_mutex_t *, uint32_t, uint32_t);
39+
extern pthread_mutex_t *dlock_init(void);
4640
extern void gtp_htab_init(gtp_htab_t *, size_t);
4741
extern void gtp_htab_destroy(gtp_htab_t *);
4842

0 commit comments

Comments
 (0)