Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

error codes for work msg queue functions

Change-Id: I9e9b2e964248fd55c7d40e7f266499aa58b5816b
Reviewed-on: http://review.membase.org/3761
Tested-by: Chiyoung Seo <chiyoung.seo@gmail.com>
Reviewed-by: Chiyoung Seo <chiyoung.seo@gmail.com>
  • Loading branch information...
commit ca33975877954912799a6acd4eded66c8a777154 1 parent f114b8d
@steveyen steveyen authored chiyoung committed
Showing with 35 additions and 16 deletions.
  1. +31 −12 work.c
  2. +4 −4 work.h
View
43 work.c
@@ -230,7 +230,7 @@ void work_recv(int fd, short which, void *arg) {
* been counted, work_collect_wait() returns control back to the
* main caller.
*/
-void work_collect_init(work_collect *c, int count, void *data) {
+int work_collect_init(work_collect *c, int count, void *data) {
assert(c);
memset(c, 0, sizeof(work_collect));
@@ -238,31 +238,50 @@ void work_collect_init(work_collect *c, int count, void *data) {
c->count = count;
c->data = data;
- pthread_mutex_init(&c->collect_lock, NULL);
- pthread_cond_init(&c->collect_cond, NULL);
+ int rv;
+
+ rv = pthread_mutex_init(&c->collect_lock, NULL);
+ if (rv != 0) {
+ return rv;
+ }
+
+ rv = pthread_cond_init(&c->collect_cond, NULL);
+ if (rv != 0) {
+ return rv;
+ }
+
+ return 0;
}
-void work_collect_wait(work_collect *c) {
+int work_collect_wait(work_collect *c) {
+ int rv = 0;
pthread_mutex_lock(&c->collect_lock);
- while (c->count != 0) { // Can't test for > 0, due to -1 on init race.
- pthread_cond_wait(&c->collect_cond, &c->collect_lock);
+ while (c->count != 0 && rv == 0) { // Can't test for > 0, due to -1 on init race.
+ rv = pthread_cond_wait(&c->collect_cond, &c->collect_lock);
}
pthread_mutex_unlock(&c->collect_lock);
+ return rv;
}
-void work_collect_count(work_collect *c, int count) {
+int work_collect_count(work_collect *c, int count) {
+ int rv = 0;
pthread_mutex_lock(&c->collect_lock);
c->count = count;
- if (c->count <= 0)
- pthread_cond_signal(&c->collect_cond);
+ if (c->count <= 0) {
+ rv = pthread_cond_signal(&c->collect_cond);
+ }
pthread_mutex_unlock(&c->collect_lock);
+ return rv;
}
-void work_collect_one(work_collect *c) {
+int work_collect_one(work_collect *c) {
+ int rv = 0;
pthread_mutex_lock(&c->collect_lock);
assert(c->count >= 1);
c->count--;
- if (c->count <= 0)
- pthread_cond_signal(&c->collect_cond);
+ if (c->count <= 0) {
+ rv = pthread_cond_signal(&c->collect_cond);
+ }
pthread_mutex_unlock(&c->collect_lock);
+ return rv;
}
View
8 work.h
@@ -54,9 +54,9 @@ bool work_send(work_queue *m,
void work_recv(int fd, short which, void *arg);
-void work_collect_init(work_collect *c, int count, void *data);
-void work_collect_wait(work_collect *c);
-void work_collect_count(work_collect *c, int count);
-void work_collect_one(work_collect *c);
+int work_collect_init(work_collect *c, int count, void *data);
+int work_collect_wait(work_collect *c);
+int work_collect_count(work_collect *c, int count);
+int work_collect_one(work_collect *c);
#endif // WORK_H
Please sign in to comment.
Something went wrong with that request. Please try again.