亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? select.cxx

?? eCos/RedBoot for勤研ARM AnywhereII(4510) 含全部源代碼
?? CXX
字號:
//==========================================================================
//
//      select.cxx
//
//      Fileio select() support
//
//==========================================================================
//####ECOSGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// This file is part of eCos, the Embedded Configurable Operating System.
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
// Copyright (C) 2002 Nick Garnett
//
// eCos is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 or (at your option) any later version.
//
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
// for more details.
//
// You should have received a copy of the GNU General Public License along
// with eCos; if not, write to the Free Software Foundation, Inc.,
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or inline functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. However the source code for this file must still be made available
// in accordance with section (3) of the GNU General Public License.
//
// This exception does not invalidate any other reasons why a work based on
// this file might be covered by the GNU General Public License.
//
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
// at http://sources.redhat.com/ecos/ecos-license/
// -------------------------------------------
//####ECOSGPLCOPYRIGHTEND####
//==========================================================================
//#####DESCRIPTIONBEGIN####
//
// Author(s):           nickg
// Contributors:        nickg
// Date:                2000-05-25
// Purpose:             Fileio select() support
// Description:         Support for select().
//                      
//              
//              
//
//####DESCRIPTIONEND####
//
//==========================================================================

#include <pkgconf/hal.h>
#include <pkgconf/kernel.h>
#include <pkgconf/io_fileio.h>

#include <cyg/kernel/ktypes.h>         // base kernel types
#include <cyg/infra/cyg_trac.h>        // tracing macros
#include <cyg/infra/cyg_ass.h>         // assertion macros

#include <stdarg.h>                    // for fcntl()

#include "fio.h"                       // Private header

#include <sys/select.h>                // select header

#include <cyg/kernel/sched.hxx>        // scheduler definitions
#include <cyg/kernel/thread.hxx>       // thread definitions
#include <cyg/kernel/mutex.hxx>        // mutex definitions
#include <cyg/kernel/clock.hxx>        // clock definitions

#include <cyg/kernel/sched.inl>
#include <cyg/kernel/thread.inl>
#include <cyg/kernel/clock.inl>

//==========================================================================
// File object locking

#define LOCK_FILE( fp ) cyg_file_lock( fp )

#define UNLOCK_FILE( fp ) cyg_file_unlock( fp )

//==========================================================================
// Local variables

// Mutex for serializing select processing. This essntially controls
// access to the contents of the selinfo structures embedded in the
// client system data structures.
static Cyg_Mutex select_mutex CYGBLD_ATTRIB_INIT_PRI(CYG_INIT_IO_FS);

// Condition variable where any thread that is waiting for a select to
// fire is suspended. Note that select is not intended to be a real time
// operation. Whenever any selectable event occurs, all selecting threads
// will be resumed. They must then rescan their selectees and resuspend if
// necessary.
static Cyg_Condition_Variable selwait( select_mutex ) CYGBLD_ATTRIB_INIT_PRI(CYG_INIT_IO_FS);

static volatile cyg_uint32 selwake_count = 0;

//==========================================================================
// Timeval to ticks conversion support

// Converters from sec and us to ticks
static struct Cyg_Clock::converter us_converter, sec_converter;

static cyg_bool converters_initialized = false;

externC cyg_tick_count cyg_timeval_to_ticks( const struct timeval *tv )
{
    if( !converters_initialized )
    {
        // Create the converters we need.
        Cyg_Clock::real_time_clock->get_other_to_clock_converter( 1000, &us_converter );
        Cyg_Clock::real_time_clock->get_other_to_clock_converter( 1000000000, &sec_converter );

        converters_initialized = true;
    }
    
    // Short circuit zero timeval
    if( tv->tv_sec == 0 && tv->tv_usec == 0 )
    {
        return 0;
    }
        
    // Convert the seconds field to ticks.
    cyg_tick_count ticks = Cyg_Clock::convert( tv->tv_sec, &sec_converter );

    // Convert the nanoseconds. This will round down to nearest whole tick.
    ticks += Cyg_Clock::convert( (cyg_tick_count)tv->tv_usec, &us_converter );

    return ticks;
}

//==========================================================================
// Select API function

static int
cyg_pselect(int nfd, fd_set *in, fd_set *out, fd_set *ex,
           struct timeval *tv, const sigset_t *mask)
{
    FILEIO_ENTRY();

    int error = ENOERR;
    int fd, mode, num;
    cyg_file *fp;
    fd_set in_res, out_res, ex_res;  // Result sets
    fd_set *selection[3], *result[3];
    cyg_tick_count ticks;
    int mode_type[] = {CYG_FREAD, CYG_FWRITE, 0};
    cyg_uint32 wake_count;
    sigset_t oldmask;

    FD_ZERO(&in_res);
    FD_ZERO(&out_res);
    FD_ZERO(&ex_res);

    // Set up sets
    selection[0] = in;   result[0] = &in_res;
    selection[1] = out;  result[1] = &out_res;
    selection[2] = ex;   result[2] = &ex_res;

    // Compute end time
    if (tv)
        ticks = cyg_timeval_to_ticks( tv );
    else ticks = 0;

    // Lock the mutex
    select_mutex.lock();

    // Scan sets for possible I/O until something found, timeout or error.
    while (!error)
    {
        wake_count = selwake_count;
        
        num = 0;  // Total file descriptors "ready"
        for (mode = 0;  !error && mode < 3;  mode++)
        {
            if (selection[mode]) {
                for (fd = 0;  !error && fd < nfd;  fd++)
                {
                    if (FD_ISSET(fd, selection[mode]))
                    {
                        fp = cyg_fp_get( fd );
                        if( fp == NULL )
                        {
                            error = EBADF;
                            break;
                        }

                        if ((*fp->f_ops->fo_select)(fp, mode_type[mode], 0))
                        {
                            FD_SET(fd, result[mode]);
                            num++;
                        }

                        cyg_fp_free( fp );
                    }
                }
            }
        }
        
        if (num)
        {
            // Found something, update user's sets
            if (in)  FD_COPY( &in_res, in );
            if (out) FD_COPY( &out_res, out );
            if (ex)  FD_COPY( &ex_res, ex );
            select_mutex.unlock();
            CYG_FILEIO_DELIVER_SIGNALS( mask );
            FILEIO_RETURN_VALUE(num);
        }

        Cyg_Scheduler::lock();

        // Switch to the supplied signal mask. This will permit delivery
        // of any signals that might terminate this select operation.
        
        CYG_FILEIO_SIGMASK_SET( mask, &oldmask );
    
        do
        {

            // We need to see if any signals have been posted while we
            // were testing all those files. The handlers will not
            // have run because we have ASRs inhibited but the signal
            // will have been set pending.

            if( CYG_FILEIO_SIGPENDING() )
            {
                // There are pending signals so we need to terminate
                // the select operation and return EINTR. Handlers for
                // the pending signals will be called just before we
                // return.

                error = EINTR;
                break;
            }
            
            if( wake_count == selwake_count )
            {
                // Nothing found, see if we want to wait
                if (tv)
                {
                    // Special case of "poll"
                    if (ticks == 0)
                    {
                        error = EAGAIN;
                        break;
                    }

                    ticks += Cyg_Clock::real_time_clock->current_value();
                
                    if( !selwait.wait( ticks ) )
                    {
                        // A non-standard wakeup, if the current time is equal to
                        // or past the timeout, return zero. Otherwise return
                        // EINTR, since we have been released.

                        if( Cyg_Clock::real_time_clock->current_value() >= ticks )
                        {
                            error = EAGAIN;
                            break;
                        }
                        else error = EINTR;
                    }

                    ticks -= Cyg_Clock::real_time_clock->current_value();
                }
                else
                {
                    // Wait forever (until something happens)
            
                    if( !selwait.wait() )
                        error = EINTR;
                }
            }

        } while(0);

        CYG_FILEIO_SIGMASK_SET( &oldmask, NULL );
        
        Cyg_Scheduler::unlock();
        
    } // while(!error)

    select_mutex.unlock();
 
    // If the error code is EAGAIN, this means that a timeout has
    // happened. We return zero in that case, rather than a proper
    // error code.
    // If the error code is EINTR, then a signal may be pending
    // delivery. Call back into the POSIX package to handle it.
    
    if( error == EAGAIN )
        FILEIO_RETURN_VALUE(0);
    else if( error == EINTR )
        CYG_FILEIO_DELIVER_SIGNALS( mask );

    FILEIO_RETURN(error);
}

// -------------------------------------------------------------------------
// Select API function

__externC int
select(int nfd, fd_set *in, fd_set *out, fd_set *ex, struct timeval *tv)
{
	return cyg_pselect(nfd, in, out, ex, tv, NULL);
}

// -------------------------------------------------------------------------
// Pselect API function
//
// This is derived from the POSIX-200X specification.

__externC int
pselect(int nfd, fd_set *in, fd_set *out, fd_set *ex,
	const struct timespec *ts, const sigset_t *sigmask)
{
	struct timeval tv;

#ifndef CYGPKG_POSIX_SIGNALS
        CYG_ASSERT( sigmask == NULL,
                    "pselect called with non-null sigmask without POSIX signal support"
                    );
#endif

	if (ts != NULL)
        {
            tv.tv_sec = ts->tv_sec;
            tv.tv_usec = ts->tv_nsec/1000;
        }

	return cyg_pselect(nfd, in, out, ex, ts ? &tv : NULL, sigmask);
}

//==========================================================================
// Select support functions.

// -------------------------------------------------------------------------
// cyg_selinit() is used to initialize a selinfo structure

void cyg_selinit( struct CYG_SELINFO_TAG *sip )
{
    sip->si_info = 0;
    sip->si_thread = 0;
}

// -------------------------------------------------------------------------
// cyg_selrecord() is called when a client device needs to register
// the current thread for selection.

void cyg_selrecord( CYG_ADDRWORD info, struct CYG_SELINFO_TAG *sip )
{
    sip->si_info = info;
    sip->si_thread = (CYG_ADDRESS)Cyg_Thread::self();
}

// -------------------------------------------------------------------------
// cyg_selwakeup() is called when the client device matches the select
// criterion, and needs to wake up a selector.

void cyg_selwakeup( struct CYG_SELINFO_TAG *sip )
{
    // We don't actually use the si_info field of selinfo at present.
    // A potential use would be to select one of several selwait condition
    // variables to signal. However, that would only be necessary if we
    // end up having lots of threads in select.

    Cyg_Scheduler::lock();
 
    if( sip->si_thread != 0 )
    {
        // If the thread pointer is still present, this selection has
        // not been fired before. We just wake up all threads waiting,
        // regardless of whether they are waiting for this event or
        // not.  This avoids any race conditions, and is consistent
        // with the behaviour of the BSD kernel.
        
        sip->si_thread = 0;
        selwait.broadcast();
        selwake_count++;

    }

    Cyg_Scheduler::unlock();    
}

// -------------------------------------------------------------------------
// EOF select.cxx

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美天堂一区二区三区| 日韩一区二区免费高清| 欧美日韩午夜在线视频| 国产午夜精品福利| 日韩中文字幕区一区有砖一区| 高清不卡在线观看| 欧美一区二区三区在线| 亚洲欧美另类图片小说| 国产精品1024| 精品国精品国产尤物美女| 亚洲一区二区3| 99在线视频精品| 国产日韩欧美亚洲| 奇米色一区二区| 欧美精品在线一区二区三区| 亚洲视频你懂的| 欧美写真视频网站| 亚洲综合无码一区二区| 成人国产视频在线观看| 欧美大片日本大片免费观看| 午夜电影网一区| 在线观看不卡一区| 亚洲精品免费电影| 91麻豆精品在线观看| 亚洲欧洲一区二区在线播放| 国产成人免费在线视频| 久久久精品天堂| 国产乱人伦偷精品视频不卡| 精品少妇一区二区三区视频免付费 | 678五月天丁香亚洲综合网| 国产精品乱码妇女bbbb| 国产不卡视频在线观看| 国产网站一区二区三区| 福利91精品一区二区三区| 国产亚洲精品7777| 不卡一区二区三区四区| 26uuu国产电影一区二区| 韩国女主播成人在线观看| 精品国产伦一区二区三区观看体验| 日韩成人免费在线| 亚洲精品一区二区在线观看| 国产一区在线不卡| 国产欧美精品一区二区三区四区 | 亚洲免费观看高清完整版在线观看 | 九九九久久久精品| 精品国精品国产| 国产电影精品久久禁18| 久久久久青草大香线综合精品| 久久se精品一区精品二区| 精品国内片67194| 国产精品18久久久久久久网站| 欧美激情一区二区三区不卡| 91在线播放网址| 一卡二卡三卡日韩欧美| 欧美群妇大交群中文字幕| 免费在线看一区| 久久精品一区二区| 91丨porny丨在线| 人人狠狠综合久久亚洲| 久久综合久久综合久久| 91网站在线观看视频| 五月天久久比比资源色| 亚洲小说欧美激情另类| 欧美一级在线视频| 成人av电影在线网| 日韩影院免费视频| 中文字幕国产精品一区二区| 欧美在线观看视频一区二区三区| 久色婷婷小香蕉久久| 136国产福利精品导航| 136国产福利精品导航| 日韩一区二区三免费高清| 成人av网站大全| 免费成人在线观看| 亚洲三级在线观看| 欧美精品一区二区三区高清aⅴ| 91在线观看一区二区| 91视频xxxx| 久久99国产精品久久99果冻传媒| 亚洲日本一区二区| 国产偷v国产偷v亚洲高清| 欧美日韩一区二区在线视频| 国产不卡视频一区| 蜜臀久久99精品久久久久宅男| 蜜臀久久99精品久久久久宅男| 亚洲视频在线一区| 国产日产欧美一区二区三区| 7777精品伊人久久久大香线蕉 | www.激情成人| 韩国毛片一区二区三区| 三级欧美韩日大片在线看| 亚洲欧洲成人自拍| 日韩二区三区四区| 1区2区3区国产精品| 久久综合狠狠综合久久综合88| 色女孩综合影院| 国产aⅴ综合色| 精品一区二区三区日韩| 丝袜诱惑制服诱惑色一区在线观看| 中文字幕av一区 二区| 欧美成人高清电影在线| 91麻豆精品国产91久久久资源速度| 91网站最新网址| av资源网一区| 成人动漫一区二区在线| 国产一区二区三区最好精华液| 欧美a级理论片| 免费成人在线影院| 蜜桃av噜噜一区| 美女一区二区三区在线观看| 视频一区二区中文字幕| 亚洲国产毛片aaaaa无费看 | 国产精品乱码人人做人人爱| 国产欧美视频一区二区| 亚洲国产精品ⅴa在线观看| 久久免费午夜影院| 久久久国产午夜精品| 26uuu国产日韩综合| 国产日韩亚洲欧美综合| 久久精品欧美日韩| 国产精品免费视频一区| 亚洲视频一区二区在线观看| 亚洲精品久久7777| 午夜视频久久久久久| 日本女优在线视频一区二区| 久久丁香综合五月国产三级网站| 蜜桃视频在线一区| 国产精品综合一区二区| 波多野结衣中文字幕一区| 91亚洲精品久久久蜜桃网站| 色94色欧美sute亚洲线路一久| 欧美综合一区二区| 欧美一区二区三区不卡| 久久精品亚洲国产奇米99| 综合激情成人伊人| 日本午夜一区二区| 国产伦精一区二区三区| 91欧美一区二区| 777欧美精品| 国产日本一区二区| 一区二区激情小说| 久久国产日韩欧美精品| 久久久精品国产免费观看同学| 中日韩免费视频中文字幕| 亚洲国产综合在线| 极品美女销魂一区二区三区免费| 成人高清免费观看| 欧美精品乱人伦久久久久久| 精品乱人伦小说| 亚洲人一二三区| 久久99蜜桃精品| 一本色道久久综合狠狠躁的推荐| 欧美一区日本一区韩国一区| 中文字幕不卡的av| 日韩精品国产精品| av电影在线不卡| 精品国精品国产| 亚洲电影第三页| 北岛玲一区二区三区四区| 欧美伦理影视网| 亚洲天堂久久久久久久| 男人操女人的视频在线观看欧美| 成人激情动漫在线观看| 日本一区二区免费在线 | 欧美色图一区二区三区| 精品福利一区二区三区| 一区二区三区国产精品| 经典三级在线一区| 欧美日韩精品一区二区三区四区 | 成人久久久精品乱码一区二区三区 | 69久久夜色精品国产69蝌蚪网| 亚洲精品一区二区三区四区高清 | ㊣最新国产の精品bt伙计久久| 日本欧美一区二区在线观看| 色综合久久88色综合天天| 国产亚洲欧美一区在线观看| 日韩av一级电影| 欧美日韩视频专区在线播放| 17c精品麻豆一区二区免费| 国产一区二区三区免费观看| 91.麻豆视频| 亚洲国产欧美在线| 在线观看成人小视频| 自拍av一区二区三区| 粉嫩aⅴ一区二区三区四区| 日韩欧美一二三| 青青青伊人色综合久久| 欧美乱妇20p| 亚洲午夜在线观看视频在线| 91麻豆精东视频| 亚洲女人的天堂| 91女人视频在线观看| 亚洲色图欧美偷拍| 99久久夜色精品国产网站| 国产精品入口麻豆原神| 成人精品国产一区二区4080| 久久久久国产一区二区三区四区 | 亚洲欧美乱综合| 91女神在线视频| 一区二区三区四区亚洲|