Changeset 4:d061ad3be7fd in xplcommon for src


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

Location:
src/xplcommon
Files:
4 added
5 edited

Legend:

Unmodified
Added
Removed
  • 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.