Example #1
0
// wake up from cURL I/O
void CurlHttpIO::addevents(Waiter* w, int flags)
{
    int t;
    PosixWaiter* pw = (PosixWaiter*)w;

    curl_multi_fdset(curlm, &pw->rfds, &pw->wfds, &pw->efds, &t);

    pw->bumpmaxfd(t);
}
Example #2
0
File: fs.cpp Project: hnkien/sdk
// wake up from filesystem updates
void PosixFileSystemAccess::addevents(Waiter* w, int flags)
{
    if (notifyfd >= 0)
    {
        PosixWaiter* pw = (PosixWaiter*)w;

        FD_SET(notifyfd, &pw->rfds);
        FD_SET(notifyfd, &pw->ignorefds);

        pw->bumpmaxfd(notifyfd);
    }
}
Example #3
0
int main() {
    for (int i = 0; i < READER_COUNT; ++i) {
        createThread([&](){
                g_mainWaiter.release();
                g_threadsWaiter.wait();

                double start = getTime();
                for (int j = 0; j < READER_LOOP; ++j) {
                    {
#if USE_LOCK == LOCK_TYPE_RW
                        ReaderGuard<ReaderWriterLock> guard(g_resRW);
#elif USE_LOCK == LOCK_TYPE_RW2
                        ReaderGuard<ReaderWriterLock2> guard(g_resRW2);
#elif USE_LOCK == LOCK_TYPE_POSIX_RW
                        ReaderGuard<PosixReaderWriterLock> guard(g_posixResRW);
#elif USE_LOCK == LOCK_TYPE_MUTEX
                        MutexGuard<Mutex> guard(g_resMutex);
#elif USE_LOCK == LOCK_TYPE_POSIX_MUTEX
                        MutexGuard<PosixMutex> guard(g_posixResMutex);
#else
#endif
                        doRead();
                    }
                }
                double readerTime = getTime() - start;

                MutexGuard<Mutex> guard(g_gMutex);
                g_readerTime += readerTime;
                g_mainWaiter.release();
                });
    }
    for (int i = 0; i < WRITER_COUNT; ++i) {
        createThread([&](){
                g_mainWaiter.release();
                g_threadsWaiter.wait();

                double start = getTime();
                for (int j = 0; j < WRITER_LOOP; ++j) {
                    sleep_us(10);
                    {
#if USE_LOCK == LOCK_TYPE_RW
                        WriterGuard<ReaderWriterLock> guard(g_resRW);
#elif USE_LOCK == LOCK_TYPE_RW2
                        WriterGuard<ReaderWriterLock2> guard(g_resRW2);
#elif USE_LOCK == LOCK_TYPE_POSIX_RW
                        WriterGuard<PosixReaderWriterLock> guard(g_posixResRW);
#elif USE_LOCK == LOCK_TYPE_MUTEX
                        MutexGuard<Mutex> guard(g_resMutex);
#elif USE_LOCK == LOCK_TYPE_POSIX_MUTEX
                        MutexGuard<PosixMutex> guard(g_posixResMutex);
#else
#endif
                        doWrite();
                    }
                }
                double writerTime = getTime() - start;

                MutexGuard<Mutex> guard(g_gMutex);
                g_writerTime += writerTime;
                g_mainWaiter.release();
                });
    }

    for (int i = 0; i < READER_COUNT + WRITER_COUNT; ++i) g_mainWaiter.acquire();
    g_threadsWaiter.signal();
    for (int i = 0; i < READER_COUNT + WRITER_COUNT; ++i) g_mainWaiter.acquire();

    fprintf(stderr, "res=%d,res2=%d=\n", g_res, g_res2);
    printf("lockType=%s, R/W=%d, reader=%.3fs, writer=%.3fs\n", TYPE_NAME, READER_COUNT / WRITER_COUNT, g_readerTime / READER_COUNT, g_writerTime / WRITER_COUNT);
}