| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "nacl_io/ossocket.h" |
| 6 #ifdef PROVIDES_SOCKET_API |
| 7 |
| 8 #include <errno.h> |
| 9 |
| 10 #include "nacl_io/mount_node_socket.h" |
| 11 #include "nacl_io/mount_stream.h" |
| 12 |
| 13 namespace nacl_io { |
| 14 |
| 15 |
| 16 void DispatchStart(void* work_ptr, int32_t val) { |
| 17 MountStream::Work* work = static_cast<MountStream::Work*>(work_ptr); |
| 18 |
| 19 // Delete if it fails to Start, Run will never get called. |
| 20 if (!work->Start(val)) |
| 21 delete work; |
| 22 } |
| 23 |
| 24 void DispatchRun(void* work_ptr, int32_t val) { |
| 25 MountStream::Work* work = static_cast<MountStream::Work*>(work_ptr); |
| 26 |
| 27 work->Run(val); |
| 28 delete work; |
| 29 } |
| 30 |
| 31 void* MountStream::StreamThreadThunk(void* mount_ptr) { |
| 32 MountStream* mount = static_cast<MountStream*>(mount_ptr); |
| 33 mount->StreamThread(); |
| 34 return NULL; |
| 35 } |
| 36 |
| 37 // All work is done via completions callbacks from posted work. |
| 38 void MountStream::StreamThread() { |
| 39 { |
| 40 AUTO_LOCK(message_lock_) |
| 41 message_loop_ = |
| 42 ppapi_->GetMessageLoopInterface()->Create(ppapi()->GetInstance()); |
| 43 ppapi_->GetMessageLoopInterface()->AttachToCurrentThread(message_loop_); |
| 44 pthread_cond_broadcast(&message_cond_); |
| 45 } |
| 46 |
| 47 // Run loop until Quit is posted. |
| 48 ppapi_->GetMessageLoopInterface()->Run(message_loop_); |
| 49 } |
| 50 |
| 51 PP_CompletionCallback MountStream::GetStartCompletion(Work* work) { |
| 52 return PP_MakeCompletionCallback(DispatchStart, work); |
| 53 } |
| 54 |
| 55 PP_CompletionCallback MountStream::GetRunCompletion(Work* work) { |
| 56 return PP_MakeCompletionCallback(DispatchRun, work); |
| 57 } |
| 58 |
| 59 // Place enqueue onto the socket thread. |
| 60 void MountStream::EnqueueWork(Work* work) { |
| 61 if (message_loop_ == 0) { |
| 62 AUTO_LOCK(message_lock_); |
| 63 |
| 64 if (message_loop_ == 0) { |
| 65 pthread_t thread; |
| 66 pthread_create(&thread, NULL, StreamThreadThunk, this); |
| 67 } |
| 68 |
| 69 while (message_loop_ == 0) |
| 70 pthread_cond_wait(&message_cond_, message_lock_.mutex()); |
| 71 } |
| 72 |
| 73 PP_CompletionCallback cb = PP_MakeCompletionCallback(DispatchStart, work); |
| 74 ppapi_->GetMessageLoopInterface()->PostWork(message_loop_, cb, 0); |
| 75 } |
| 76 |
| 77 |
| 78 MountStream::MountStream() |
| 79 : message_loop_(0) { |
| 80 pthread_cond_init(&message_cond_, NULL); |
| 81 } |
| 82 |
| 83 MountStream::~MountStream() { |
| 84 if (message_loop_) { |
| 85 ppapi_->GetMessageLoopInterface()->PostQuit(message_loop_, PP_TRUE); |
| 86 ppapi_->ReleaseResource(message_loop_); |
| 87 } |
| 88 pthread_cond_destroy(&message_cond_); |
| 89 } |
| 90 |
| 91 Error MountStream::Access(const Path& path, int a_mode) { return EACCES; } |
| 92 Error MountStream::Open(const Path& path, |
| 93 int o_flags, |
| 94 ScopedMountNode* out_node) { return EACCES; } |
| 95 |
| 96 Error MountStream::Unlink(const Path& path) { return EACCES; } |
| 97 Error MountStream::Mkdir(const Path& path, int permissions) { return EACCES; } |
| 98 Error MountStream::Rmdir(const Path& path) { return EACCES; } |
| 99 Error MountStream::Remove(const Path& path) { return EACCES; } |
| 100 |
| 101 } // namespace nacl_io |
| 102 #endif // PROVIDES_SOCKET_API |
| OLD | NEW |