[Beignet] [PATCH] add a semaphore for clang lib
Homer Hsing
homer.xing at intel.com
Mon Oct 21 01:30:47 PDT 2013
Signed-off-by: Homer Hsing <homer.xing at intel.com>
---
backend/src/backend/gen_program.cpp | 6 ++++++
backend/src/backend/gen_program.h | 3 +++
backend/src/backend/program.cpp | 6 +++++-
3 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/backend/src/backend/gen_program.cpp b/backend/src/backend/gen_program.cpp
index 33f07b2..781152d 100644
--- a/backend/src/backend/gen_program.cpp
+++ b/backend/src/backend/gen_program.cpp
@@ -160,3 +160,9 @@ void genSetupCallBacks(void)
gbe_program_new_from_llvm = gbe::genProgramNewFromLLVM;
}
+sem_t llvm_semaphore;
+
+void genSetupLLVMSemaphore(void)
+{
+ sem_init(&llvm_semaphore, 0, 1);
+}
diff --git a/backend/src/backend/gen_program.h b/backend/src/backend/gen_program.h
index 9fae2e7..a498a5d 100644
--- a/backend/src/backend/gen_program.h
+++ b/backend/src/backend/gen_program.h
@@ -29,9 +29,12 @@
#include <stdint.h>
#include <stdlib.h>
+#include <semaphore.h>
/*! This will make the compiler output Gen ISA code */
extern void genSetupCallBacks(void);
+extern sem_t llvm_semaphore;
+extern void genSetupLLVMSemaphore(void);
#endif /* __GBE_GEN_PROGRAM_H__ */
diff --git a/backend/src/backend/program.cpp b/backend/src/backend/program.cpp
index b2879a4..205f7f2 100644
--- a/backend/src/backend/program.cpp
+++ b/backend/src/backend/program.cpp
@@ -553,7 +553,10 @@ namespace gbe {
// Create an action and make the compiler instance carry it out
llvm::OwningPtr<clang::CodeGenAction> Act(new clang::EmitLLVMOnlyAction());
- if (!Clang.ExecuteAction(*Act))
+ sem_wait(&llvm_semaphore);
+ auto retVal = Clang.ExecuteAction(*Act);
+ sem_post(&llvm_semaphore);
+ if (!retVal)
return;
llvm::Module *module = Act->takeModule();
@@ -847,6 +850,7 @@ namespace gbe
gbe_get_image_base_index = gbe::getImageBaseIndex;
gbe_set_image_base_index = gbe::setImageBaseIndex;
genSetupCallBacks();
+ genSetupLLVMSemaphore();
}
};
--
1.8.3.2
More information about the Beignet
mailing list