当前位置: 首页>>代码示例>>C++>>正文


C++ Condition_Lock函数代码示例

本文整理汇总了C++中Condition_Lock函数的典型用法代码示例。如果您正苦于以下问题:C++ Condition_Lock函数的具体用法?C++ Condition_Lock怎么用?C++ Condition_Lock使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Condition_Lock函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: PopSingle

/**
* @brief   pop the read point  from cyc buffer
*
* @author hankejia
* @date 2012-11-05
* @param[in] pthis			the pointer point to the CCycBuffer.
* @return T_S32
* @retval return the read point of cycbuffer,if return NULL failed
*/
static T_CHR * PopSingle( T_pVOID pthis, T_S32 iSize )
{
    CCycBuffer *this = ( CCycBuffer * )pthis;
    CycBuffer_handle * handle = (CycBuffer_handle *)this->handle;

    //the cyc buffer is empty, wait for push
    Condition_Lock( handle->mDataCon );
    handle->mPopComplete = AK_FALSE;
    while ( ( handle->mUseSize < iSize ) && ( !(handle->mForceQuit) ) ) {
        //Condition_Unlock( handle->mDataCon );
        Condition_Unlock( handle->mWriteDataCon );

        //logi( "PopSingle buffer empty!\n" );
        Condition_Wait( &(handle->mDataCon) );
        //logi( "wake up from push signed!\n" );

        Condition_Unlock( handle->mDataCon );
        Condition_Lock( handle->mWriteDataCon );
        Condition_Lock( handle->mDataCon );
    }

    if ( handle->mForceQuit ) {
        handle->mPopComplete = AK_TRUE;
        Condition_Unlock( handle->mDataCon );
        return NULL;
    }

    assert( ( ( handle->mRead >= handle->mCycBuffer ) && ( handle->mRead < (handle->mCycBuffer + handle->mBufferSize) ) ) );
    assert( ( ( handle->mWrite >= handle->mCycBuffer ) && ( handle->mWrite < (handle->mCycBuffer + handle->mBufferSize) ) ) );

    Condition_Unlock( handle->mDataCon );

    return handle->mRead;
}
开发者ID:gurkamalsingh88,项目名称:Lamobo-D1,代码行数:43,代码来源:CycBuffer.c

示例2: WriteToFs

/**
* @brief   write cyc buffer is data to file
*
* @author hankejia
* @date 2012-07-05
* @param[in] pthis			the pointer point to the CCycBuffer.
* @param[in] fd			file is descriptor.the cyc buffer is data will write to this file
* @param[in] iSize			how many data in bytes from cyc buffer you want to write to the file
* @param[in] pWriteBuffer	the space alloc by caller,fuction will use this space to load the data,and write to file system,
*						if this param is NULL, function will alloc space by himself
* @return T_S32
* @retval return  >=0 the size of bytes write to file, < 0  failed
*/
static T_S32 WriteToFs( T_pVOID pthis, T_S32 fd, T_S32 iSize )
{
    CCycBuffer *this = ( CCycBuffer * )pthis;
    CycBuffer_handle * handle = (CycBuffer_handle *)this->handle;
    T_CHR * pBuffer = NULL;
    T_S32 iLineSize = 0, iLeavings = 0;

    Condition_Lock( handle->mWriteDataCon );

    //need to flash all data
    if ( -1 == iSize ) {
        iSize = handle->mUseSize;
    }

    pBuffer = PopSingle( pthis, iSize );

    if ( pBuffer == NULL ) {
        ResumeForceQuitState( pthis );
        Condition_Unlock( handle->mWriteDataCon );
        delay_loop( 0, 10000 ); // 10ms
        return 0;
    }

    iLeavings = iSize;

    while( iLeavings > 0 ) {
        iLineSize = ( handle->mCycBuffer + handle->mBufferSize ) - pBuffer;
        if ( iLineSize == 0 ) {
            pBuffer = handle->mCycBuffer;
            continue;
        } else if ( iLineSize > iLeavings ) {
            iLineSize = iLeavings;
        }

        if ( WriteComplete( fd, pBuffer, iLineSize ) < 0 ) {
            Condition_Unlock( handle->mWriteDataCon );
            loge( "WriteToFs::WriteComplete error!\n" );
            return -1;
        }

        pBuffer += iLineSize;
        iLeavings -= iLineSize;
    }

    Condition_Lock( handle->mDataCon );
    handle->mRead = pBuffer;
    handle->mUseSize -= iSize;
    handle->mPopComplete = AK_TRUE;
    Condition_Unlock( handle->mDataCon );
    Condition_Unlock( handle->mWriteDataCon );

    //logi( "pop signal send!\n" );
    Condition_Signal( &(handle->mDataCon) );

    return iSize;
}
开发者ID:gurkamalsingh88,项目名称:Lamobo-D1,代码行数:69,代码来源:CycBuffer.c

示例3: DEFINE_DESTRUCTOR_BEGIN

DEFINE_CONSTRUCTOR_END

/**
* @brief   simulate class CCycbuffer destructor
*
* free all the simulate class member variable,
* @author hankejia
* @date 2012-07-05
* @param[in] pthis   the pointer point to the CCycBuffer.
* @return NONE
*/
DEFINE_DESTRUCTOR_BEGIN( CCycBuffer )
{
    CCycBuffer *this = (CCycBuffer *)pthis;
    CycBuffer_handle * handle = (CycBuffer_handle *)this->handle;

    //虚构时,如果当前还有线程在Push流程中等待
    //那么首先Pop出Buffer中的所有数据,唤醒在Push
    //中等待的线程,等待其完成push操作。
    Condition_Lock( handle->mDataCon );
    if ( !( handle->mPushComplete ) ) {
        Condition_Unlock( handle->mDataCon );
        Clean( this );

        //唤醒在Push中等待的线程
        Condition_Signal( &(handle->mDataCon) );

        Condition_Wait( &(handle->mDataCon) );
        Condition_Unlock( handle->mDataCon );
    } else
        Condition_Unlock( handle->mDataCon );

    //如果当前还有线程在pop流程中等待,那么首先
    //向Buffer中Push数据,唤醒在Pop中等待的线程,等
    //待其完成pop操作。
    Condition_Lock( handle->mDataCon );
    if ( !( handle->mPopComplete ) ) {
        Condition_Unlock( handle->mDataCon );
        FakePushFull( this );

        //唤醒在Pop中等待的线程
        Condition_Signal( &(handle->mDataCon) );

        Condition_Wait( &handle->mDataCon );
        Condition_Unlock( handle->mDataCon );
    } else
        Condition_Unlock( handle->mDataCon );

    DestroyCycBuffer( this );
    Condition_Destroy( &( handle->mDataCon ) );
    Condition_Destroy( &( handle->mWriteDataCon ) );
    //Condition_Destroy( &( handle->mWaitForPopCon ) );
    //Condition_Destroy( &( handle->mWaitForPushCon ) );

    free( handle );
}
开发者ID:gurkamalsingh88,项目名称:Lamobo-D1,代码行数:56,代码来源:CycBuffer.c

示例4: reporter_spawn

/*
 * This function is called only when the reporter thread
 * This function is the loop that the reporter thread processes
 */
void reporter_spawn( thread_Settings *thread ) {
    do {
        // This section allows for safe exiting with Ctrl-C
        Condition_Lock ( ReportCond );
        if ( ReportRoot == NULL ) {
            // Allow main thread to exit if Ctrl-C is received
            thread_setignore();
            Condition_Wait ( &ReportCond );
            // Stop main thread from exiting until done with all reports
            thread_unsetignore();
        }
        Condition_Unlock ( ReportCond );

again:
        if ( ReportRoot != NULL ) {
            ReportHeader *temp = ReportRoot;
            //Condition_Unlock ( ReportCond );
            if(temp->report.mThreadMode == kMode_Client){
            	synchronize();
            }
            if ( reporter_process_report ( temp ) ) {
                // This section allows for more reports to be added while
                // the reporter is processing reports without needing to
                // stop the reporter or immediately notify it
                Condition_Lock ( ReportCond );
                if ( temp == ReportRoot ) {
                    // no new reports
                    ReportRoot = temp->next;
                } else {
                    // new reports added
                    ReportHeader *itr = ReportRoot;
                    while ( itr->next != temp ) {
                        itr = itr->next;
                    }
                    itr->next = temp->next;
                }
                // finished with report so free it
                free( temp );
                Condition_Unlock ( ReportCond );
                Condition_Signal( &ReportDoneCond );
                if (ReportRoot)
                    goto again;
            }
            Condition_Signal( &ReportDoneCond );
            usleep(10000);
        } else {
            //Condition_Unlock ( ReportCond );
        }
    } while ( 1 );
}
开发者ID:AbderrahmaneLaribi,项目名称:iperf2,代码行数:54,代码来源:Reporter.c

示例5: thread_start

/* -------------------------------------------------------------------
 * Start the specified object's thread execution. Increments thread
 * count, spawns new thread, and stores thread ID.
 * ------------------------------------------------------------------- */
void thread_start( struct thread_Settings* thread ) {

    // Make sure this object has not been started already
    if ( thread_equalid( thread->mTID, thread_zeroid() ) ) {

        // Check if we need to start another thread before this one
        if ( thread->runNow != NULL ) {
            thread_start( thread->runNow );
        }

        // increment thread count
        Condition_Lock( thread_sNum_cond );
        thread_sNum++;
        Condition_Unlock( thread_sNum_cond );

#if   defined( HAVE_POSIX_THREAD )

        // pthreads -- spawn new thread
        if ( pthread_create( &thread->mTID, NULL, thread_run_wrapper, thread ) != 0 ) {
            WARN( 1, "pthread_create" );

            // decrement thread count
            Condition_Lock( thread_sNum_cond );
            thread_sNum--;
            Condition_Unlock( thread_sNum_cond );
        }

#elif defined( HAVE_WIN32_THREAD )

        // Win32 threads -- spawn new thread
        // Win32 has a thread handle in addition to the thread ID
        thread->mHandle = CreateThread( NULL, 0, thread_run_wrapper, thread, 0, &thread->mTID );
        if ( thread->mHandle == NULL ) {
            WARN( 1, "CreateThread" );

            // decrement thread count
            Condition_Lock( thread_sNum_cond );
            thread_sNum--;
            Condition_Unlock( thread_sNum_cond );
        }

#else

        // single-threaded -- call Run_Wrapper in this thread
        thread_run_wrapper( thread );
#endif
    }

} // end thread_start
开发者ID:AnupBansod,项目名称:andro-iperf,代码行数:53,代码来源:Thread.c

示例6: CreateCycBuffer

/**
* @brief   create the Cyc Buffer, malloc memory
*
* call SetBufferSize fuction to set cyc buffer size before call this function
* @author hankejia
* @date 2012-07-05
* @param[in] pthis   the pointer point to the CCycBuffer.
* @return T_S32
* @retval if return 0, create cyc buffer success, otherwise failed
*/
static T_S32 CreateCycBuffer( T_pVOID pthis )
{
    CCycBuffer *this = ( CCycBuffer * )pthis;
    CycBuffer_handle * handle = (CycBuffer_handle *)this->handle;
    T_S32 ret = 0;

    Condition_Lock( handle->mDataCon );

    if ( handle->mCycBuffer != NULL )
        DestroyCycBuffer( this );

    handle->mCycBuffer = (T_CHR *)malloc( handle->mBufferSize );
    if ( handle->mCycBuffer == NULL )
    {
        loge( "memory alloc error![%s::%s]\n", __FILE__, __LINE__ );
        ret = -1;
        goto End;
    }

    memset( handle->mCycBuffer, 0, handle->mBufferSize );

    handle->mRead = handle->mWrite = handle->mCycBuffer;

End:
    Condition_Unlock( handle->mDataCon );
    return ret;
}
开发者ID:gurkamalsingh88,项目名称:Lamobo-D1,代码行数:37,代码来源:CycBuffer.c

示例7: ReportServerUDP

/*
 * ReportServerUDP will generate a report of the UDP
 * statistics as reported by the server on the client
 * side.
 */
void ReportServerUDP( thread_Settings *agent, server_hdr *server ) {
    if ( (ntohl(server->flags) & HEADER_VERSION1) != 0 &&
         isServerReport( agent ) ) {
        /*
         * Create in one big chunk
         */
        ReportHeader *reporthdr = (ReportHeader *) malloc( sizeof(ReportHeader) );
        Transfer_Info *stats = &reporthdr->report.info;

        if ( reporthdr != NULL ) {
            stats->transferID = agent->mSock;
            stats->groupID = (agent->multihdr != NULL ? agent->multihdr->groupID
                                                      : -1);
            reporthdr->agentindex = -1;
            reporthdr->reporterindex = -1;

            reporthdr->report.type = SERVER_RELAY_REPORT;
            reporthdr->report.mode = agent->mReportMode;
            stats->mFormat = agent->mFormat;
            stats->jitter = ntohl( server->jitter1 );
            stats->jitter += ntohl( server->jitter2 ) / (double)rMillion;
#ifdef HAVE_INT64_T
            stats->TotalLen = (((max_size_t) ntohl( server->total_len1 )) << 32) +
                                  ntohl( server->total_len2 );
#else
            stats->TotalLen = ntohl( server->total_len2 );
#endif
            stats->startTime = 0;
            stats->endTime = ntohl( server->stop_sec );
            stats->endTime += ntohl( server->stop_usec ) / (double)rMillion;
            stats->cntError = ntohl( server->error_cnt );
            stats->cntOutofOrder = ntohl( server->outorder_cnt );
            stats->cntDatagrams = ntohl( server->datagrams );
            stats->mUDP = (char)kMode_Server;
            reporthdr->report.connection.peer = agent->local;
            reporthdr->report.connection.size_peer = agent->size_local;
            reporthdr->report.connection.local = agent->peer;
            reporthdr->report.connection.size_local = agent->size_peer;

#ifdef HAVE_THREAD
            /*
             * Update the ReportRoot to include this report.
             */
            Condition_Lock( ReportCond );
            reporthdr->next = ReportRoot;
            ReportRoot = reporthdr;
            Condition_Signal( &ReportCond );
            Condition_Unlock( ReportCond );
#else
            /*
             * Process the report in this thread
             */
            reporthdr->next = NULL;
            process_report ( reporthdr );
#endif
        } else {
            FAIL(1, "Out of Memory!!\n", agent);
        }
    }
}
开发者ID:katakk,项目名称:iperf,代码行数:65,代码来源:Reporter.cpp

示例8: thread_joinall

/* -------------------------------------------------------------------
 * Wait for all thread object's execution to complete. Depends on the
 * thread count being accurate and the threads sending a condition
 * signal when they terminate.
 * ------------------------------------------------------------------- */
void thread_joinall( void ) {
    Condition_Lock( thread_sNum_cond );
    while ( thread_sNum > 0 ) {
        Condition_Wait( &thread_sNum_cond );
    }
    Condition_Unlock( thread_sNum_cond );
} // end Joinall
开发者ID:AnupBansod,项目名称:andro-iperf,代码行数:12,代码来源:Thread.c

示例9: photograph

int photograph( void *pbuf, int size)
{

	unsigned long outsize;
	int ret;

	VideoStream_Enc_Reset();
	
	//printf("%d\n", h_eid);
	void * buf;
	if( 2 == index_file )
		ret = frame_encode(h_eid , pbuf+(parse.width*parse.height*3/2), &buf, &outsize);
	else
		ret = frame_encode(h_eid, pbuf, &buf, &outsize);

	if(ret == 0)
	{
		Condition_Lock( g_conMangerPh );
		g_phsize = outsize;
		Condition_Signal( &g_conMangerPh );
		Condition_Unlock( g_conMangerPh );
	}

	VideoStream_Enc_Reset();
	
	return 0;
}
开发者ID:119-org,项目名称:lamobo-d1,代码行数:27,代码来源:photograph.c

示例10: thread_unsetignore

/* -------------------------------------------------------------------
 * unset a thread from being ignorable, so joinall will wait on it
 * this simply increments the thread count that joinall uses.
 * This is utilized by the reporter thread which knows when it
 * is ok to quit (aka no pending reports).
 * ------------------------------------------------------------------- */
void thread_unsetignore( void ) {
    Condition_Lock( thread_sNum_cond );
    IPERF_DEBUGF( THREAD_DEBUG | IPERF_DBG_TRACE, ( "Unsetting ignorable thread.\r\n" ) );
    thread_sNum++;
    IPERF_DEBUGF( CONDITION_DEBUG | IPERF_DBG_TRACE, ( "Signaling thread_sNum_cond condition.\r\n" ) );
    Condition_Signal( &thread_sNum_cond );
    Condition_Unlock( thread_sNum_cond );
} // end thread_unsetignore
开发者ID:flyleaf91,项目名称:USB-Wireless-LAN-Driver-for-STM32F4xx,代码行数:14,代码来源:Thread_iperf.c

示例11: thread_start

/* -------------------------------------------------------------------
 * Start the specified object's thread execution. Increments thread
 * count, spawns new thread, and stores thread ID.
 * ------------------------------------------------------------------- */
void thread_start( struct thread_Settings* thread ) {
    // Make sure this object has not been started already
    if ( thread_equalid( thread->mTID, thread_zeroid() ) ) {
        // Check if we need to start another thread before this one
        if ( thread->runNow != NULL ) {
            thread_start( thread->runNow );
        }

        // increment thread count
        Condition_Lock( thread_sNum_cond );
        IPERF_DEBUGF( THREAD_DEBUG | IPERF_DBG_TRACE, ( "Incrementing thread count from %d to %d.\r\n", thread_sNum, (thread_sNum + 1) ) );
        thread_sNum++;
        Condition_Unlock( thread_sNum_cond );

        IPERF_DEBUGF( THREAD_DEBUG | IPERF_DBG_TRACE | IPERF_DBG_STATE, ( "Spawning %s thread.\r\n", thread_names[thread->mThreadMode] ) );
#if   defined( HAVE_POSIX_THREAD )
        // pthreads -- spawn new thread
        if ( pthread_create( &thread->mTID, NULL, thread_run_wrapper, thread ) != 0 ) {
            WARN( 1, ( "pthread_create failed!\r\n" ) );

            // decrement thread count
            Condition_Lock( thread_sNum_cond );
            IPERF_DEBUGF( THREAD_DEBUG | IPERF_DBG_TRACE, ( "Decrementing thread count from %d to %d.\r\n", thread_sNum, (thread_sNum - 1) ) );
            thread_sNum--;
            Condition_Unlock( thread_sNum_cond );
        }
#elif defined( HAVE_WIN32_THREAD )
        // Win32 threads -- spawn new thread
        // Win32 has a thread handle in addition to the thread ID
        thread->mHandle = CreateThread( NULL, 0, thread_run_wrapper, thread, 0, &thread->mTID );
        if ( thread->mHandle == NULL ) {
            WARN( 1, ( "CreateThread failed!\r\n" ) );

            // decrement thread count
            Condition_Lock( thread_sNum_cond );
            IPERF_DEBUGF( THREAD_DEBUG | IPERF_DBG_TRACE, ( "Decrementing thread count from %d to %d.\r\n", thread_sNum, (thread_sNum - 1) ) );
            thread_sNum--;
            Condition_Unlock( thread_sNum_cond );
        }
#else
        // single-threaded -- call Run_Wrapper in this thread
        thread_run_wrapper( thread );
#endif /* HAVE_POSIX_THREAD */
    }
} // end thread_start
开发者ID:flyleaf91,项目名称:USB-Wireless-LAN-Driver-for-STM32F4xx,代码行数:49,代码来源:Thread_iperf.c

示例12: thread_release_nonterm

/* -------------------------------------------------------------------
 * this function releases all non-terminating threads from the list
 * of active threads, so that when all terminating threads quit
 * the joinall will complete. This is called on a Ctrl-C input. It is
 * also used by the -P usage on the server side
 * ------------------------------------------------------------------- */
int thread_release_nonterm( int interrupt ) {
    Condition_Lock( thread_sNum_cond );
    thread_sNum -= nonterminating_num;
    if ( thread_sNum > 1 && nonterminating_num > 0 && interrupt != 0 ) {
        fprintf( stderr,"%s", wait_server_threads );
    }
    nonterminating_num = 0;
    Condition_Signal( &thread_sNum_cond );
    Condition_Unlock( thread_sNum_cond );
    return thread_sNum;
}
开发者ID:AnupBansod,项目名称:andro-iperf,代码行数:17,代码来源:Thread.c

示例13: ResumeForceQuitState

/**
* @brief   call this function to resume the force quit state. If you call
* ForceQuit before, and then you want to push or pop again, please
* call this function first.
*
* @author hankejia
* @date 2012-07-05
* @param[in] pthis		the pointer point to the CCycBuffer.
* @return T_S32
* @retval return 0 for success, otherwise for failed
*/
static T_S32 ResumeForceQuitState( T_pVOID pthis )
{
    CCycBuffer *this = ( CCycBuffer * )pthis;
    CycBuffer_handle * handle = (CycBuffer_handle *)this->handle;

    Condition_Lock( handle->mDataCon );
    handle->mForceQuit = AK_FALSE;
    Condition_Unlock( handle->mDataCon );

    return 0;
}
开发者ID:gurkamalsingh88,项目名称:Lamobo-D1,代码行数:22,代码来源:CycBuffer.c

示例14: thread_unregister_nonterm

/* -------------------------------------------------------------------
 * unset a thread from being non-terminating, so if you cancel through
 * Ctrl-C they can be ignored by the joinall.
 * ------------------------------------------------------------------- */
void thread_unregister_nonterm( void ) {
    Condition_Lock( thread_sNum_cond );
    if ( nonterminating_num == 0 ) {
        // nonterminating has been released with release_nonterm
        // Add back to the threads to wait on
        thread_sNum++;
    } else {
        nonterminating_num--; 
    }
    Condition_Unlock( thread_sNum_cond );
}
开发者ID:AnupBansod,项目名称:andro-iperf,代码行数:15,代码来源:Thread.c

示例15: thread_unregister_nonterm

/* -------------------------------------------------------------------
 * unset a thread from being non-terminating, so if you cancel through
 * Ctrl-C they can be ignored by the joinall.
 * ------------------------------------------------------------------- */
void thread_unregister_nonterm( void ) {
    Condition_Lock( thread_sNum_cond );
    IPERF_DEBUGF( THREAD_DEBUG | IPERF_DBG_TRACE, ( "Unregistering non-terminating thread.\r\n" ) );
    if ( nonterminating_num == 0 ) {
        // nonterminating has been released with release_nonterm
        // Add back to the threads to wait on
        thread_sNum++;
    } else {
        nonterminating_num--; 
    }
    Condition_Unlock( thread_sNum_cond );
} // end thread_unregister_nonterm
开发者ID:flyleaf91,项目名称:USB-Wireless-LAN-Driver-for-STM32F4xx,代码行数:16,代码来源:Thread_iperf.c


注:本文中的Condition_Lock函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。