std::pair<ReplicationExecutor::WorkItem, ReplicationExecutor::CallbackHandle>
 ReplicationExecutor::getWork() {
     boost::unique_lock<boost::mutex> lk(_mutex);
     while (true) {
         const Date_t now = _networkInterface->now();
         Date_t nextWakeupDate = scheduleReadySleepers_inlock(now);
         if (!_readyQueue.empty()) {
             break;
         }
         else if (_inShutdown) {
             return std::make_pair(WorkItem(), CallbackHandle());
         }
         lk.unlock();
         if (nextWakeupDate == Date_t(~0ULL)) {
             _networkInterface->waitForWork();
         }
         else {
             _networkInterface->waitForWorkUntil(nextWakeupDate);
         }
         lk.lock();
     }
     const CallbackHandle cbHandle(_readyQueue.begin());
     const WorkItem work = *cbHandle._iter;
     _readyQueue.begin()->callback = CallbackFn();
     _freeQueue.splice(_freeQueue.begin(), _readyQueue, _readyQueue.begin());
     return std::make_pair(work, cbHandle);
 }
 WorkItem terminate_processor( const processor_handle & processor )
 {
   return WorkItem(
     bind( &processor_container::terminate_processor_impl, this,
       processor ),
     Allocator() );
 }
Exemple #3
0
WorkItem::WorkItem(const WorkItem& item) : _buf(NULL), _rpcmsg(0), _pipe(NULL), _sst(0) {

    k5_ipc_stream    _buf = NULL;
    krb5int_ipc_stream_new(&_buf);
    krb5int_ipc_stream_write(_buf,
                     krb5int_ipc_stream_data(item.payload()),
                     krb5int_ipc_stream_size(item.payload()) );
    WorkItem(_buf, item._pipe, item._rpcmsg, item._sst);
    }
    WorkItem queue_event(
      const processor_handle & processor, const event_ptr_type & pEvent )
    {
      BOOST_ASSERT( pEvent.get() != 0 );

      return WorkItem(
        bind( &processor_container::queue_event_impl, this, processor,
          pEvent ),
        Allocator() );
    }
 WorkItem create_processor( processor_handle & handle, Scheduler & scheduler )
 {
   processor_holder_ptr_type pProcessor = make_processor_holder();
   handle = pProcessor;
   typedef void ( processor_container::*impl_fun_ptr )(
     const processor_holder_ptr_type &, const processor_context & );
   impl_fun_ptr pImpl =
     &processor_container::template create_processor_impl0< Processor >;
   return WorkItem(
     bind( pImpl, this, pProcessor,
       processor_context( scheduler, handle ) ),
     Allocator() );
 }
 WorkItem create_processor(
   processor_handle & handle, Scheduler & scheduler,
   Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5, Arg6 arg6 )
 {
   processor_holder_ptr_type pProcessor = make_processor_holder();
   handle = pProcessor;
   typedef void ( processor_container::*impl_fun_ptr )(
     const processor_holder_ptr_type &,
     const processor_context &,
     Arg1, Arg2, Arg3, Arg4, Arg5, Arg6 );
   impl_fun_ptr pImpl =
     &processor_container::template create_processor_impl6<
       Processor, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6 >;
   return WorkItem(
     bind( pImpl, this, pProcessor, processor_context( scheduler, handle ),
       arg1, arg2, arg3, arg4, arg5, arg6 ),
     Allocator() );
 }
    StatusWith<ReplicationExecutor::CallbackHandle> ReplicationExecutor::enqueueWork_inlock(
            WorkQueue* queue, const CallbackFn& callback) {

        invariant(callback);
        StatusWith<EventHandle> event = makeEvent_inlock();
        if (!event.isOK())
            return StatusWith<CallbackHandle>(event.getStatus());

        if (_freeQueue.empty())
            _freeQueue.push_front(WorkItem());
        const WorkQueue::iterator iter = _freeQueue.begin();
        iter->generation++;
        iter->callback = callback;
        iter->finishedEvent = event.getValue();
        iter->readyDate = Date_t();
        iter->isCanceled = false;
        queue->splice(queue->end(), _freeQueue, iter);
        return StatusWith<CallbackHandle>(CallbackHandle(iter));
    }
    void threadFunc()
    {
        ContextT context(matcher_->createContext());
        //single character size
        size_t char_w = matcher_->cellWidth();

        WorkItem wi = WorkItem();
        while (queue_.wait_pop(wi)) {
            //processed image region size
            size_t roi_w = wi.imgv.width();
            size_t roi_h = wi.imgv.height();
            size_t x = 0, c = 0;
            for (; x + char_w <= roi_w; x += char_w, ++c) {
                wi.outp[c] = matcher_->match(context, subimage_view(wi.imgv, x, 0, char_w, roi_h));
            }
            if (x < roi_w) {
                size_t dx = roi_w - x;
                wi.outp[c] = matcher_->match(context, subimage_view(wi.imgv, x, 0, dx, roi_h));
            }
            queue_.done();
        }
    }
 WorkItem destroy_processor( const processor_handle & processor )
 {
   return WorkItem(
     bind( &processor_container::destroy_processor_impl, this, processor ),
     Allocator() );
 }