| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 ASSERT(buffer->size() >= m_readPosition); | 47 ASSERT(buffer->size() >= m_readPosition); |
| 48 Vector<RefPtr<SharedBuffer> > newBufferQueue; | 48 Vector<RefPtr<SharedBuffer> > newBufferQueue; |
| 49 | 49 |
| 50 const char* segment = 0; | 50 const char* segment = 0; |
| 51 while (size_t length = buffer->getSomeData(segment, m_readPosition)) { | 51 while (size_t length = buffer->getSomeData(segment, m_readPosition)) { |
| 52 m_readPosition += length; | 52 m_readPosition += length; |
| 53 newBufferQueue.append(SharedBuffer::create(segment, length)); | 53 newBufferQueue.append(SharedBuffer::create(segment, length)); |
| 54 } | 54 } |
| 55 | 55 |
| 56 MutexLocker locker(m_mutex); | 56 MutexLocker locker(m_mutex); |
| 57 m_newBufferQueue.append(newBufferQueue); | 57 m_newBufferQueue.appendVector(newBufferQueue); |
| 58 m_allDataReceived = allDataReceived; | 58 m_allDataReceived = allDataReceived; |
| 59 } | 59 } |
| 60 | 60 |
| 61 void ThreadSafeDataTransport::data(SharedBuffer** buffer, bool* allDataReceived) | 61 void ThreadSafeDataTransport::data(SharedBuffer** buffer, bool* allDataReceived) |
| 62 { | 62 { |
| 63 Vector<RefPtr<SharedBuffer> > newBufferQueue; | 63 Vector<RefPtr<SharedBuffer> > newBufferQueue; |
| 64 { | 64 { |
| 65 MutexLocker lock(m_mutex); | 65 MutexLocker lock(m_mutex); |
| 66 m_newBufferQueue.swap(newBufferQueue); | 66 m_newBufferQueue.swap(newBufferQueue); |
| 67 } | 67 } |
| 68 for (size_t i = 0; i < newBufferQueue.size(); ++i) | 68 for (size_t i = 0; i < newBufferQueue.size(); ++i) |
| 69 m_readBuffer->append(newBufferQueue[i].get()); | 69 m_readBuffer->append(newBufferQueue[i].get()); |
| 70 ASSERT(buffer); | 70 ASSERT(buffer); |
| 71 ASSERT(allDataReceived); | 71 ASSERT(allDataReceived); |
| 72 *buffer = m_readBuffer.get(); | 72 *buffer = m_readBuffer.get(); |
| 73 *allDataReceived = m_allDataReceived; | 73 *allDataReceived = m_allDataReceived; |
| 74 } | 74 } |
| 75 | 75 |
| 76 bool ThreadSafeDataTransport::hasNewData() | 76 bool ThreadSafeDataTransport::hasNewData() |
| 77 { | 77 { |
| 78 MutexLocker lock(m_mutex); | 78 MutexLocker lock(m_mutex); |
| 79 return !m_newBufferQueue.isEmpty(); | 79 return !m_newBufferQueue.isEmpty(); |
| 80 } | 80 } |
| 81 | 81 |
| 82 } // namespace WebCore | 82 } // namespace WebCore |
| OLD | NEW |