Chromium Code Reviews| 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 MountStreamWork* work = static_cast<MountStreamWork*>(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 MountStreamWork* work = static_cast<MountStreamWork*>(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 while(1) | |
|
binji
2013/09/15 22:18:58
no way to exit the loop?
noelallen1
2013/09/17 21:21:54
Done.
| |
| 48 ppapi_->GetMessageLoopInterface()->Run(message_loop_); | |
| 49 } | |
| 50 | |
| 51 PP_CompletionCallback MountStream::GetStartCompletion(MountStreamWork* work) { | |
| 52 return PP_MakeCompletionCallback(DispatchStart, work); | |
| 53 } | |
| 54 | |
| 55 PP_CompletionCallback MountStream::GetRunCompletion(MountStreamWork* work) { | |
| 56 return PP_MakeCompletionCallback(DispatchRun, work); | |
| 57 } | |
| 58 | |
| 59 // Place enqueue onto the socket thread. | |
| 60 void MountStream::EnqueueWork(MountStreamWork* work) { | |
| 61 if (message_loop_ == 0) { | |
|
binji
2013/09/15 22:18:58
looks racy. What happens if two threads enqueue wo
noelallen1
2013/09/17 21:21:54
Done.
binji
2013/09/19 00:48:54
Probably should use pthread_once_t instead of doub
noelallen1
2013/09/19 21:29:27
The once init routine doesn't take a parameter, so
| |
| 62 AUTO_LOCK(message_lock_); | |
| 63 pthread_t thread; | |
| 64 pthread_create(&thread, NULL, StreamThreadThunk, this); | |
| 65 | |
| 66 while (message_loop_ == 0) | |
| 67 pthread_cond_wait(&message_cond_, message_lock_.mutex()); | |
| 68 } | |
| 69 | |
| 70 PP_CompletionCallback cb = PP_MakeCompletionCallback(DispatchStart, work); | |
| 71 ppapi_->GetMessageLoopInterface()->PostWork(message_loop_, cb, 0); | |
| 72 } | |
| 73 | |
| 74 | |
| 75 MountStream::MountStream() | |
| 76 : message_loop_(0) { | |
| 77 } | |
| 78 | |
| 79 Error MountStream::Access(const Path& path, int a_mode) { return EACCES; } | |
| 80 Error MountStream::Open(const Path& path, | |
| 81 int o_flags, | |
| 82 ScopedMountNode* out_node) { return EACCES; } | |
| 83 | |
| 84 Error MountStream::Unlink(const Path& path) { return EACCES; } | |
| 85 Error MountStream::Mkdir(const Path& path, int permissions) { return EACCES; } | |
| 86 Error MountStream::Rmdir(const Path& path) { return EACCES; } | |
| 87 Error MountStream::Remove(const Path& path) { return EACCES; } | |
| 88 | |
| 89 } // namespace nacl_io | |
| 90 #endif // PROVIDES_SOCKET_API | |
| OLD | NEW |