| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef MOJO_PUBLIC_CPP_SYSTEM_CORE_H_ | 5 #ifndef MOJO_PUBLIC_CPP_SYSTEM_CORE_H_ |
| 6 #define MOJO_PUBLIC_CPP_SYSTEM_CORE_H_ | 6 #define MOJO_PUBLIC_CPP_SYSTEM_CORE_H_ |
| 7 | 7 |
| 8 #include <assert.h> | 8 #include <assert.h> |
| 9 #include <stddef.h> | 9 #include <stddef.h> |
| 10 | 10 |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 // will be used). | 397 // will be used). |
| 398 shared_buffer->reset(handle); | 398 shared_buffer->reset(handle); |
| 399 return rv; | 399 return rv; |
| 400 } | 400 } |
| 401 | 401 |
| 402 // TODO(vtl): This (and also the functions below) are templatized to allow for | 402 // TODO(vtl): This (and also the functions below) are templatized to allow for |
| 403 // future/other buffer types. A bit "safer" would be to overload this function | 403 // future/other buffer types. A bit "safer" would be to overload this function |
| 404 // manually. (The template enforces that the in and out handles to be of the | 404 // manually. (The template enforces that the in and out handles to be of the |
| 405 // same type.) | 405 // same type.) |
| 406 template <class BufferHandleType> | 406 template <class BufferHandleType> |
| 407 inline MojoResult DuplicatedBuffer( | 407 inline MojoResult DuplicateBuffer( |
| 408 BufferHandleType buffer, | 408 BufferHandleType buffer, |
| 409 const MojoDuplicateBufferHandleOptions* options, | 409 const MojoDuplicateBufferHandleOptions* options, |
| 410 ScopedHandleBase<BufferHandleType>* new_buffer) { | 410 ScopedHandleBase<BufferHandleType>* new_buffer) { |
| 411 assert(new_buffer); | 411 assert(new_buffer); |
| 412 BufferHandleType handle; | 412 BufferHandleType handle; |
| 413 MojoResult rv = MojoDuplicateSharedBuffer(buffer.value(), options, | 413 MojoResult rv = MojoDuplicateBufferHandle( |
| 414 handle.mutable_value()); | 414 buffer.value(), options, handle.mutable_value()); |
| 415 // Reset even on failure (reduces the chances that a "stale"/incorrect handle | 415 // Reset even on failure (reduces the chances that a "stale"/incorrect handle |
| 416 // will be used). | 416 // will be used). |
| 417 new_buffer->reset(handle); | 417 new_buffer->reset(handle); |
| 418 return rv; | 418 return rv; |
| 419 } | 419 } |
| 420 | 420 |
| 421 template <class BufferHandleType> | 421 template <class BufferHandleType> |
| 422 inline MojoResult MapBuffer(BufferHandleType buffer, | 422 inline MojoResult MapBuffer(BufferHandleType buffer, |
| 423 uint64_t offset, | 423 uint64_t offset, |
| 424 uint64_t num_bytes, | 424 uint64_t num_bytes, |
| 425 void** pointer, | 425 void** pointer, |
| 426 MojoMapBufferFlags flags) { | 426 MojoMapBufferFlags flags) { |
| 427 assert(buffer); | 427 assert(buffer.is_valid()); |
| 428 return MojoMapBuffer(buffer.value(), offset, num_bytes, pointer, flags); | 428 return MojoMapBuffer(buffer.value(), offset, num_bytes, pointer, flags); |
| 429 } | 429 } |
| 430 | 430 |
| 431 inline MojoResult UnmapBuffer(void* pointer) { | 431 inline MojoResult UnmapBuffer(void* pointer) { |
| 432 assert(pointer); | 432 assert(pointer); |
| 433 return MojoUnmapBuffer(pointer); | 433 return MojoUnmapBuffer(pointer); |
| 434 } | 434 } |
| 435 | 435 |
| 436 // A wrapper class that automatically creates a shared buffer and owns the | 436 // A wrapper class that automatically creates a shared buffer and owns the |
| 437 // handle. | 437 // handle. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 458 CreateSharedBuffer(&options, num_bytes, &handle); | 458 CreateSharedBuffer(&options, num_bytes, &handle); |
| 459 assert(result == MOJO_RESULT_OK); | 459 assert(result == MOJO_RESULT_OK); |
| 460 } | 460 } |
| 461 | 461 |
| 462 inline SharedBuffer::~SharedBuffer() { | 462 inline SharedBuffer::~SharedBuffer() { |
| 463 } | 463 } |
| 464 | 464 |
| 465 } // namespace mojo | 465 } // namespace mojo |
| 466 | 466 |
| 467 #endif // MOJO_PUBLIC_CPP_SYSTEM_CORE_H_ | 467 #endif // MOJO_PUBLIC_CPP_SYSTEM_CORE_H_ |
| OLD | NEW |