Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(49)

Unified Diff: third_party/grpc/src/compiler/csharp_plugin.cc

Issue 1932353002: Initial checkin of gRPC to third_party/ Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/grpc/src/compiler/csharp_plugin.cc
diff --git a/third_party/WebKit/Source/wtf/SpinLock.h b/third_party/grpc/src/compiler/csharp_plugin.cc
similarity index 54%
copy from third_party/WebKit/Source/wtf/SpinLock.h
copy to third_party/grpc/src/compiler/csharp_plugin.cc
index 9146bd52281e0070165592438c3154a3b1be5cfc..8b9395f9e2b21af8c5af6e255e27724d14bbbff0 100644
--- a/third_party/WebKit/Source/wtf/SpinLock.h
+++ b/third_party/grpc/src/compiler/csharp_plugin.cc
@@ -1,5 +1,7 @@
/*
- * Copyright (C) 2013 Google Inc. All rights reserved.
+ *
+ * Copyright 2015, Google Inc.
+ * All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -26,53 +28,45 @@
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
*/
-#ifndef WTF_SpinLock_h
-#define WTF_SpinLock_h
+// Generates C# gRPC service interface out of Protobuf IDL.
-#include "wtf/Compiler.h"
-#include "wtf/WTFExport.h"
-#include <atomic>
#include <memory>
-#include <mutex>
-// DESCRIPTION
-// Spinlock is a simple spinlock class based on the standard CPU primitive of
-// atomic increment and decrement of an int at a given memory address. These are
-// intended only for very short duration locks and assume a system with multiple
-// cores. For any potentially longer wait you should be using a real lock.
+#include "src/compiler/config.h"
+#include "src/compiler/csharp_generator.h"
+#include "src/compiler/csharp_generator_helpers.h"
-namespace WTF {
+class CSharpGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
+ public:
+ CSharpGrpcGenerator() {}
+ ~CSharpGrpcGenerator() {}
-class SpinLock {
-public:
- using Guard = std::lock_guard<SpinLock>;
-
- ALWAYS_INLINE void lock()
- {
- static_assert(sizeof(m_lock) == sizeof(int), "int and m_lock are different sizes");
- if (LIKELY(!m_lock.exchange(true, std::memory_order_acquire)))
- return;
- lockSlow();
+ bool Generate(const grpc::protobuf::FileDescriptor *file,
+ const grpc::string &parameter,
+ grpc::protobuf::compiler::GeneratorContext *context,
+ grpc::string *error) const {
+ grpc::string code = grpc_csharp_generator::GetServices(file);
+ if (code.size() == 0) {
+ return true; // don't generate a file if there are no services
}
- ALWAYS_INLINE void unlock()
- {
- m_lock.store(false, std::memory_order_release);
+ // Get output file name.
+ grpc::string file_name;
+ if (!grpc_csharp_generator::ServicesFilename(file, &file_name)) {
+ return false;
}
-
-private:
- // This is called if the initial attempt to acquire the lock fails. It's
- // slower, but has a much better scheduling and power consumption behavior.
- WTF_EXPORT void lockSlow();
-
- std::atomic_int m_lock;
+ std::unique_ptr<grpc::protobuf::io::ZeroCopyOutputStream> output(
+ context->Open(file_name));
+ grpc::protobuf::io::CodedOutputStream coded_out(output.get());
+ coded_out.WriteRaw(code.data(), code.size());
+ return true;
+ }
};
-
-} // namespace WTF
-
-using WTF::SpinLock;
-
-#endif // WTF_SpinLock_h
+int main(int argc, char *argv[]) {
+ CSharpGrpcGenerator generator;
+ return grpc::protobuf::compiler::PluginMain(argc, argv, &generator);
+}
« no previous file with comments | « third_party/grpc/src/compiler/csharp_generator_helpers.h ('k') | third_party/grpc/src/compiler/generator_helpers.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698