~ubuntu-branches/ubuntu/saucy/memcached/saucy-201305271046

« back to all changes in this revision

Viewing changes to thread.c

  • Committer: Package Import Robot
  • Author(s): Scott Kitterman
  • Date: 2012-01-22 14:12:32 UTC
  • mfrom: (1.1.11)
  • Revision ID: package-import@ubuntu.com-20120122141232-y3whgwvutns1d8hk
Tags: 1.4.11-0ubuntu1
* New upstream release
  - Fix race condition issue introduced in 1.4.10
  - Multiple other bug fixes
  - Initial (beta - API may change) implementation of slab reassingment

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
#include <string.h>
12
12
#include <pthread.h>
13
13
 
 
14
#ifdef __sun
 
15
#include <atomic.h>
 
16
#endif
 
17
 
14
18
#define ITEMS_PER_ALLOC 64
15
19
 
16
20
/* An item in the connection queue. */
39
43
/* Connection lock around accepting new connections */
40
44
pthread_mutex_t conn_lock = PTHREAD_MUTEX_INITIALIZER;
41
45
 
 
46
#if !defined(__GNUC__) && !defined(__sun)
 
47
pthread_mutex_t atomics_mutex = PTHREAD_MUTEX_INITIALIZER;
 
48
#endif
 
49
 
42
50
/* Lock for global stats */
43
51
static pthread_mutex_t stats_lock;
44
52
 
70
78
 
71
79
static void thread_libevent_process(int fd, short which, void *arg);
72
80
 
 
81
inline unsigned short refcount_incr(unsigned short *refcount) {
 
82
#ifdef __GNUC__
 
83
    return __sync_add_and_fetch(refcount, 1);
 
84
#elif defined(__sun)
 
85
    return atomic_inc_ushort_nv(refcount);
 
86
#else
 
87
    unsigned short res;
 
88
    mutex_lock(&atomics_mutex);
 
89
    *refcount++;
 
90
    res = *refcount;
 
91
    pthread_mutex_unlock(&atomics_mutex);
 
92
    return res;
 
93
#endif
 
94
}
 
95
 
 
96
inline unsigned short refcount_decr(unsigned short *refcount) {
 
97
#ifdef __GNUC__
 
98
    return __sync_sub_and_fetch(refcount, 1);
 
99
#elif defined(__sun)
 
100
    return atomic_dec_ushort_nv(refcount);
 
101
#else
 
102
    unsigned short res;
 
103
    mutex_lock(&atomics_mutex);
 
104
    *refcount--;
 
105
    res = *refcount;
 
106
    pthread_mutex_unlock(&atomics_mutex);
 
107
    return res;
 
108
#endif
 
109
}
 
110
 
73
111
void item_lock(uint32_t hv) {
74
112
    mutex_lock(&item_locks[hv & item_lock_mask]);
75
113
}