Changeset 4:d061ad3be7fd in xplcommon


Ignore:
Timestamp:
12/27/12 18:52:39 (12 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

Added support for a waitable event for POSIX and a test program

Files:
8 added
7 edited

Legend:

Unmodified
Added
Removed
  • Makefile.am

    r0 r4  
    1 SUBDIRS=src
     1SUBDIRS=src test
    22
    33pkgconfigdir=$(libdir)/pkgconfig
  • configure.ac

    r3 r4  
    2828        src/xplcommon/posix/Makefile
    2929        src/xplcommon/win32/Makefile
     30        test/Makefile
    3031])
    3132
  • src/xplcommon/Makefile.am

    r3 r4  
    2222include_xplcommon_HEADERS=\
    2323        config.h        \
    24         Thread.h
     24        Thread.h        \
     25        Waiter.h        \
     26        WaitableEvent.h
  • src/xplcommon/posix/Makefile.am

    r3 r4  
    44        Thread.cc               \
    55        Waitable.cc     \
    6         Waiter.cc
     6        Waiter.cc       \
     7        WaitableEvent.cc
    78
    89include_xplcommon_posixdir=$(includedir)/xplcommon/posix
     
    1011        Thread.h                \
    1112        Waitable.h              \
    12         Waiter.h
     13        Waiter.h                \
     14        WaitableEvent.h
  • src/xplcommon/posix/Thread.h

    r3 r4  
    3333
    3434#include <pthread.h>
     35#include <unistd.h>
    3536
    3637//------------------------------------------------------------------------------
     
    4546class Thread
    4647{
     48public:
     49    /**
     50     * Sleep for the given number of milliseconds.
     51     */
     52    static void sleep(unsigned millis);
     53
    4754private:
    4855    /**
     
    8491//------------------------------------------------------------------------------
    8592
     93inline void Thread::sleep(unsigned millis)
     94{
     95    usleep(static_cast<useconds_t>(millis)*1000);
     96}
     97
     98//------------------------------------------------------------------------------
     99
    86100inline Thread::~Thread()
    87101{
  • src/xplcommon/posix/Waitable.cc

    r3 r4  
    3434#include "Waiter.h"
    3535
     36#include <fcntl.h>
     37
    3638//------------------------------------------------------------------------------
    3739
    3840using xplcommon::posix::Waitable;
     41
     42//------------------------------------------------------------------------------
     43
     44void Waitable::setNonBlocking(int fd)
     45{
     46    fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK);
     47}
    3948
    4049//------------------------------------------------------------------------------
  • src/xplcommon/posix/Waitable.h

    r3 r4  
    4747class Waitable
    4848{
     49public:
     50    /**
     51     * Set the given file descriptor to non-blocking.
     52     */
     53    static void setNonBlocking(int fd);
     54
    4955protected:
    5056    /**
Note: See TracChangeset for help on using the changeset viewer.