Example #1
0
 inline
 int my_RecordBuffer::pushFront(
                      const bsl::shared_ptr<ball::Record>& handle)
 {
     bslmt::LockGuard<bslmt::RecursiveMutex> guard(&d_mutex);
     d_buffer.insert(d_buffer.begin(), handle);
     return 0;
 }
 // MANIPULATORS
 int pushBack(const TYPE& value)
     // Append the specified 'value' to this thread-enabled vector and
     // return the index of the new element.
 {
     bslmt::LockGuard<bslmt::Mutex> guard(&d_mutex);
     d_elements.push_back(value);
     return static_cast<int>(d_elements.size()) - 1;
 }
Example #3
0
// PRIVATE ACCESSORS
bool
bdlc::IndexClerk::areInvariantsPreserved(const bsl::vector<int>& unusedStack,
                                         int                     nextNewIndex)
{
    int         indicesInvalid   = 0;
    int         indicesNotUnique = 0;
    bsl::size_t size             = unusedStack.size();

    bsl::vector<char> bin(nextNewIndex, 0);

    // Optimizing for the valid case.

    for (bsl::size_t i = 0; i < size; ++i) {
        indicesInvalid |= ((unsigned int) unusedStack[i] >=
                                                  (unsigned int) nextNewIndex);

        if (BSLS_PERFORMANCEHINT_PREDICT_LIKELY(!indicesInvalid)) {
            indicesNotUnique |= ++bin[unusedStack[i]];
        }
    }

    if (indicesInvalid || (indicesNotUnique & 0x2)) {
        return false;                                                 // RETURN
    }

    return true;
}
static inline
bool validIndex(const bsl::vector<TYPE>& vector, int index)
    // Return 'true' if the specified 'index' is within the range of valid
    // indices of the specified 'vector', and 'false' otherwise.
{
    return 0 <= index && (unsigned int) index < vector.size();
}
Example #5
0
 inline
 int my_RecordBuffer::pushBack(
                      const bsl::shared_ptr<ball::Record>& handle)
 {
     bslmt::LockGuard<bslmt::RecursiveMutex> guard(&d_mutex);
     d_buffer.push_back(handle);
     return 0;
 }
double PeriodDayCountUtil::yearsDiff(
                                 const bdlt::Date&              beginDate,
                                 const bdlt::Date&              endDate,
                                 const bsl::vector<bdlt::Date>& periodDate,
                                 double                         periodYearDiff,
                                 DayCountConvention::Enum       convention)
{
    BSLS_ASSERT(periodDate.size() >= 2);
    BSLS_ASSERT(periodDate.front() <= beginDate);
    BSLS_ASSERT(                      beginDate <= periodDate.back());
    BSLS_ASSERT(periodDate.front() <= endDate);
    BSLS_ASSERT(                      endDate   <= periodDate.back());

    BSLS_ASSERT_SAFE(isSortedAndUnique(periodDate.begin(), periodDate.end()));

    double numYears;

    switch (convention) {
      case DayCountConvention::e_PERIOD_ICMA_ACTUAL_ACTUAL: {
        numYears = bbldc::PeriodIcmaActualActual::yearsDiff(beginDate,
                                                            endDate,
                                                            periodDate,
                                                            periodYearDiff);
      } break;
      default: {
        BSLS_ASSERT_OPT(0 && "Unrecognized convention");
        numYears = 0.0;
      } break;
    }

    return numYears;
}
Example #7
0
// MANIPULATORS
void my_Logger::logMessage(const bsl::string& message, Severity severity)
{
    archive.push_back(message);
    switch (severity) {
      case TRACE: {
        // Do nothing beyond archiving the message.
      } break;
      case WARN: {
        ball::Context context(ball::Transmission::e_PASSTHROUGH, 0, 1);
        publish(message, context);
      } break;
      case ERROR: {
        int index  = 0;
        int length = (int)archive.size();
        ball::Context context(ball::Transmission::e_TRIGGER, index, length);
        while (length--) {
            publish(archive[length], context);
            context.setRecordIndexRaw(++index);
        }
        archive.clear();  // flush archive
      } break;
    }
}
static
int loadLocalTimeDescriptors(
                bsl::vector<baltzo::LocalTimeDescriptor> *descriptors,
                const bsl::vector<RawLocalTimeType>&      localTimeDescriptors,
                const bsl::vector<char>&                  abbreviationBuffer)
    // Load the specified 'descriptors' with the sequence of local time
    // descriptors described by the specified 'localTimeDescriptors' holding
    // raw information read from the file, and referring to null-terminated
    // abbreviations in the specified 'abbreviationBuffer'.  Return 0 on
    // success, and a non-zero value otherwise.
{
    BALL_LOG_SET_CATEGORY(LOG_CATEGORY);

    for (bsl::size_t i = 0; i < localTimeDescriptors.size(); ++i) {
        if (!validIndex(abbreviationBuffer,
                        localTimeDescriptors[i].d_abbreviationIndex)) {
            BALL_LOG_ERROR << "Invalid abbreviation buffer index "
                           << (int)localTimeDescriptors[i].d_abbreviationIndex
                           << " found in Zoneinfo file.  Expecting [0 .. "
                           << abbreviationBuffer.size() - 1
                           << "]."
                           << BALL_LOG_END;
            return -20;                                               // RETURN
        }

        const int utcOffset = decode32(localTimeDescriptors[i].d_offset);

        if (!baltzo::LocalTimeDescriptor::isValidUtcOffsetInSeconds(
                                                                  utcOffset)) {
            BALL_LOG_ERROR << "Invalid UTC offset "
                           << utcOffset
                           << " found in Zoneinfo file.  Expecting "
                           << "[-86399 .. 86399]."
                           << BALL_LOG_END;

            return -21;                                               // RETURN
        }
        const bool isDst = localTimeDescriptors[i].d_isDst;

        // Passing the address of the first character pointed by the index (C
        // string).

        const char *description =
              &abbreviationBuffer[localTimeDescriptors[i].d_abbreviationIndex];

        // Check if 'description' is null-terminated.

        const int maxLength = abbreviationBuffer.size()
                              - localTimeDescriptors[i].d_abbreviationIndex
                              - 1;
        if (maxLength < bdlb::String::strnlen(description, maxLength + 1)) {
            BALL_LOG_ERROR << "Abbreviation string is not null-terminated."
                           << BALL_LOG_END;
            return -22;                                               // RETURN
        }

        descriptors->push_back(baltzo::LocalTimeDescriptor(utcOffset,
                                                          isDst,
                                                          description));
    }

    return 0;
}
 int length() const
     // Return the number of elements in this thread-enabled vector.
 {
     bslmt::LockGuard<bslmt::Mutex> guard(&d_mutex);
     return static_cast<int>(d_elements.size());
 }
static inline int dispatchCallbacks(bsl::vector<struct ::pollfd>  *tmp,
                                    bsl::vector<struct ::pollfd>&  pollFds,
                                    CallbackMap                   *callbacks)
{
    BSLS_ASSERT(tmp);
    BSLS_ASSERT(0 == tmp->size()); // Internal invariant

    int numCallbacks = 0;

    // Implementation note: We need to make a local copy of signaled the
    // sockets because an invoked callback can potentially modify 'pollFds'
    // array thereby corrupting the iteration order.  In the worst case, a
    // full copy of 'pollFds' is made.

    typedef bsl::vector<struct ::pollfd>::size_type size_type;

    size_type numSockets = pollFds.size();
    for (size_type i = 0; i < numSockets; ++i) {
        const struct ::pollfd& data = pollFds[i];
        if (0 != data.revents) {
            tmp->push_back(data);
        }
    }

    numSockets = tmp->size();
    for (size_type i = 0; i < numSockets; ++i) {
        const struct ::pollfd& currData = (*tmp)[i];

        // READ/ACCEPT.

        enum { DEFAULT_MASK = POLLERR | POLLHUP | POLLNVAL };

        if (currData.revents & (POLLIN | DEFAULT_MASK)) {
            CallbackMap::iterator callbackIt, cbEnd = callbacks->end();

            if (cbEnd != (callbackIt = callbacks->find(
                                                     Event(currData.fd,
                                                           EventType::e_READ)))
             || cbEnd != (callbackIt = callbacks->find(
                                         Event(currData.fd,
                                               btlso::EventType::e_ACCEPT)))) {
                (callbackIt->second)();
                ++numCallbacks;
            }
        }

        // WRITE/CONNECT.

        if (currData.revents & (POLLOUT | DEFAULT_MASK)) {
            CallbackMap::iterator callbackIt, cbEnd = callbacks->end();

            if (cbEnd != (callbackIt = callbacks->find(
                                                    Event(currData.fd,
                                                          EventType::e_WRITE)))
             || cbEnd != (callbackIt = callbacks->find(
                                               Event(currData.fd,
                                                     EventType::e_CONNECT)))) {
                (callbackIt->second)();
                ++numCallbacks;
            }
        }
    }
    tmp->clear();
    return numCallbacks;
}
Example #11
0
 inline
 int my_RecordBuffer::length() const
 {
     bslmt::LockGuard<bslmt::RecursiveMutex> guard(&d_mutex);
     return d_buffer.size();
 }
Example #12
0
 inline
 const bsl::shared_ptr<ball::Record>& my_RecordBuffer::front() const
 {
     bslmt::LockGuard<bslmt::RecursiveMutex> guard(&d_mutex);
     return d_buffer.front();
 }
Example #13
0
 inline
 void my_RecordBuffer::removeAll()
 {
     bslmt::LockGuard<bslmt::RecursiveMutex> guard(&d_mutex);
     d_buffer.clear();
 }
Example #14
0
 inline
 void my_RecordBuffer::popFront()
 {
     bslmt::LockGuard<bslmt::RecursiveMutex> guard(&d_mutex);
     d_buffer.erase(d_buffer.begin());
 }
Example #15
0
 inline
 void my_RecordBuffer::popBack()
 {
     bslmt::LockGuard<bslmt::RecursiveMutex> guard(&d_mutex);
     d_buffer.pop_back();
 }