From: Pierre-Marc Fournier Date: Mon, 28 Sep 2009 23:55:27 +0000 (-0400) Subject: move patient_write to share.h because it now has multiple users X-Git-Tag: v0.1~112 X-Git-Url: http://git.lttng.org/?a=commitdiff_plain;h=8bf5ab2d80aa095929b6d49cf2a219d9173fe4af;hp=60e57148f47eb3a3116de47e23516fc5df8c968e;p=ust.git move patient_write to share.h because it now has multiple users --- diff --git a/share/share.h b/share/share.h new file mode 100644 index 0000000..f674f31 --- /dev/null +++ b/share/share.h @@ -0,0 +1,34 @@ +#ifndef UST_SHARE_H +#define UST_SHARE_H + +#include +#include + +/* This write is patient because it restarts if it was incomplete. + */ + +static inline ssize_t patient_write(int fd, const void *buf, size_t count) +{ + const char *bufc = (const char *) buf; + int result; + + for(;;) { + result = write(fd, bufc, count); + if(result == -1 && errno == EINTR) { + continue; + } + if(result <= 0) { + return result; + } + count -= result; + bufc += result; + + if(count == 0) { + break; + } + } + + return bufc-(const char *)buf; +} + +#endif /* UST_SHARE_H */ diff --git a/ustd/ustd.c b/ustd/ustd.c index 7d1eb49..4a9a14e 100644 --- a/ustd/ustd.c +++ b/ustd/ustd.c @@ -35,6 +35,7 @@ #include "ustd.h" #include "localerr.h" #include "ustcomm.h" +#include "share.h" /* return value: 0 = subbuffer is finished, it won't produce data anymore * 1 = got subbuffer successfully @@ -198,30 +199,6 @@ end: return retval; } -/* This write is patient because it restarts if it was incomplete. - */ - -ssize_t patient_write(int fd, const void *buf, size_t count) -{ - const char *bufc = (const char *) buf; - int result; - - for(;;) { - result = write(fd, bufc, count); - if(result <= 0) { - return result; - } - count -= result; - bufc += result; - - if(count == 0) { - break; - } - } - - return bufc-(const char *)buf; -} - void decrement_active_buffers(void *arg) { pthread_mutex_lock(&active_buffers_mutex); diff --git a/ustd/ustd.h b/ustd/ustd.h index 65328d6..6025213 100644 --- a/ustd/ustd.h +++ b/ustd/ustd.h @@ -32,8 +32,6 @@ struct buffer_info { s64 pidunique; }; -ssize_t patient_write(int fd, const void *buf, size_t count); - void finish_consuming_dead_subbuffer(struct buffer_info *buf); #endif /* USTD_H */