Send wakeup to threads waiting on empty queue before releasing the

lock to decrease spurious wakeups.

Submitted by:	davidxu
MFC after:	2 weeks
This commit is contained in:
trociny 2013-12-10 20:06:41 +00:00
parent f157138bd2
commit 7a816c7150
2 changed files with 7 additions and 16 deletions

View File

@ -180,27 +180,21 @@ static pthread_mutex_t metadata_lock;
((res)->hr_remotein != NULL && (res)->hr_remoteout != NULL)
#define QUEUE_INSERT1(hio, name, ncomp) do { \
bool _wakeup; \
\
mtx_lock(&hio_##name##_list_lock[(ncomp)]); \
_wakeup = TAILQ_EMPTY(&hio_##name##_list[(ncomp)]); \
if (TAILQ_EMPTY(&hio_##name##_list[(ncomp)])) \
cv_broadcast(&hio_##name##_list_cond[(ncomp)]); \
TAILQ_INSERT_TAIL(&hio_##name##_list[(ncomp)], (hio), \
hio_next[(ncomp)]); \
hio_##name##_list_size[(ncomp)]++; \
mtx_unlock(&hio_##name##_list_lock[ncomp]); \
if (_wakeup) \
cv_broadcast(&hio_##name##_list_cond[(ncomp)]); \
mtx_unlock(&hio_##name##_list_lock[(ncomp)]); \
} while (0)
#define QUEUE_INSERT2(hio, name) do { \
bool _wakeup; \
\
mtx_lock(&hio_##name##_list_lock); \
_wakeup = TAILQ_EMPTY(&hio_##name##_list); \
if (TAILQ_EMPTY(&hio_##name##_list)) \
cv_broadcast(&hio_##name##_list_cond); \
TAILQ_INSERT_TAIL(&hio_##name##_list, (hio), hio_##name##_next);\
hio_##name##_list_size++; \
mtx_unlock(&hio_##name##_list_lock); \
if (_wakeup) \
cv_broadcast(&hio_##name##_list_cond); \
} while (0)
#define QUEUE_TAKE1(hio, name, ncomp, timeout) do { \
bool _last; \

View File

@ -110,15 +110,12 @@ static void *disk_thread(void *arg);
static void *send_thread(void *arg);
#define QUEUE_INSERT(name, hio) do { \
bool _wakeup; \
\
mtx_lock(&hio_##name##_list_lock); \
_wakeup = TAILQ_EMPTY(&hio_##name##_list); \
if (TAILQ_EMPTY(&hio_##name##_list)) \
cv_broadcast(&hio_##name##_list_cond); \
TAILQ_INSERT_TAIL(&hio_##name##_list, (hio), hio_next); \
hio_##name##_list_size++; \
mtx_unlock(&hio_##name##_list_lock); \
if (_wakeup) \
cv_broadcast(&hio_##name##_list_cond); \
} while (0)
#define QUEUE_TAKE(name, hio) do { \
mtx_lock(&hio_##name##_list_lock); \