X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=glib%2Fgwakeup.c;h=c0f1ba0541ad361bfe378797da4dc5d96cc5c234;hb=2a53b4d0e2c98a14aedf31e38f0ad1fb2e8fe26f;hp=76f9ece25b847b12618fa29dec2cb410cada2cdc;hpb=452b6277d4badf7d471c73555277a5afd3393602;p=platform%2Fupstream%2Fglib.git diff --git a/glib/gwakeup.c b/glib/gwakeup.c index 76f9ece..c0f1ba0 100644 --- a/glib/gwakeup.c +++ b/glib/gwakeup.c @@ -12,18 +12,29 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * License along with this library; if not, see . * * Author: Ryan Lortie */ #include "config.h" + +/* gwakeup.c is special -- GIO and some test cases include it. As such, + * it cannot include other glib headers without triggering the single + * includes warnings. We have to manually include its dependencies here + * (and at all other use sites). + */ +#ifdef GLIB_COMPILATION +#include "gtypes.h" +#include "gpoll.h" +#else +#include +#endif + #include "gwakeup.h" -/** +/*< private > * SECTION:gwakeup * @title: GWakeup * @short_description: portable cross-thread event signal mechanism @@ -49,9 +60,12 @@ #ifdef _WIN32 #include + +#ifdef GLIB_COMPILATION #include "gmessages.h" #include "giochannel.h" #include "gwin32.h" +#endif GWakeup * g_wakeup_new (void) @@ -128,7 +142,11 @@ g_wakeup_new (void) /* try eventfd first, if we think we can */ #if defined (HAVE_EVENTFD) +#ifndef TEST_EVENTFD_FALLBACK wakeup->fds[0] = eventfd (0, EFD_CLOEXEC | EFD_NONBLOCK); +#else + wakeup->fds[0] = -1; +#endif if (wakeup->fds[0] != -1) { @@ -202,17 +220,35 @@ g_wakeup_acknowledge (GWakeup *wakeup) * g_wakeup_get_pollfd() will immediately succeed until such a time as * g_wakeup_acknowledge() is called. * + * This function is safe to call from a UNIX signal handler. + * * Since: 2.30 **/ void g_wakeup_signal (GWakeup *wakeup) { - guint64 one = 1; + int res; if (wakeup->fds[1] == -1) - write (wakeup->fds[0], &one, sizeof one); + { + guint64 one = 1; + + /* eventfd() case. It requires a 64-bit counter increment value to be + * written. */ + do + res = write (wakeup->fds[0], &one, sizeof one); + while (G_UNLIKELY (res == -1 && errno == EINTR)); + } else - write (wakeup->fds[1], &one, 1); + { + guint8 one = 1; + + /* Non-eventfd() case. Only a single byte needs to be written, and it can + * have an arbitrary value. */ + do + res = write (wakeup->fds[1], &one, sizeof one); + while (G_UNLIKELY (res == -1 && errno == EINTR)); + } } /**