Skip to content

Commit a908468

Browse files
committed
Pass threadData using OpenModelica.threadData() in external function calls
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@17986 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent d5b507d commit a908468

File tree

7 files changed

+46
-47
lines changed

7 files changed

+46
-47
lines changed

Compiler/FrontEnd/InstUtil.mo

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5898,6 +5898,7 @@ algorithm
58985898
list<Absyn.Exp> rest;
58995899
Env.Cache cache;
59005900
Prefix.Prefix pre;
5901+
DAE.ComponentRef cr;
59015902
case (cache,_,{},impl,st,_,_) then (cache,{},{},st);
59025903
case (cache,env,(e :: rest),impl,st,pre,_)
59035904
equation

Compiler/FrontEnd/ModelicaBuiltin.mo

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,16 @@ type VariableNames "An array of variable names, e.g. {a.b,a[1].b[3].c}, or a sin
723723

724724
end $Code;
725725

726+
function threadData
727+
output ThreadData threadData;
728+
protected
729+
record ThreadData
730+
end ThreadData;
731+
external "builtin" annotation(Documentation(info="<html>
732+
<p>Used to access thread-specific data in external functions.</p>
733+
</html>"));
734+
end threadData;
735+
726736
package Internal "Contains internal implementations, e.g. overloaded builtin functions"
727737

728738
type BuiltinType "Integer,Real,String,enumeration or array of some kind"

Compiler/Template/CodegenC.tpl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5163,6 +5163,7 @@ template functionBodyExternalFunction(Function fn, Boolean inFunc)
51635163
match fn
51645164
case efn as EXTERNAL_FUNCTION(__) then
51655165
let()= System.tmpTickReset(1)
5166+
let()= System.tmpTickResetIndex(0,1) /* Boxed array indices */
51665167
let fname = underscorePath(name)
51675168
let retType = if outVars then '<%fname%>_rettype' else "void"
51685169
let &preExp = buffer "" /*BUFD*/
@@ -5176,8 +5177,7 @@ case efn as EXTERNAL_FUNCTION(__) then
51765177
varInit(var, retVar, i1, &varDecls /*BUFD*/, &outputAlloc /*BUFC*/, &varFrees /*BUFF*/)
51775178
; empty /* increase the counter! */
51785179
)
5179-
5180-
5180+
let &varDecls += addRootsTempArray()
51815181
let boxedFn = if acceptMetaModelicaGrammar() then functionBodyBoxed(fn)
51825182
let fnBody = <<
51835183
<%retType%> omc_<%fname%>(threadData_t *threadData<%funArgs |> arg => ', <%
@@ -8303,6 +8303,9 @@ template daeExpCall(Exp call, Context context, Text &preExp /*BUFP*/, Text &varD
83038303
let argStr = daeExp(s1, context, &preExp, &varDecls)
83048304
unboxRecord(argStr, ty, &preExp, &varDecls)
83058305

8306+
case CALL(path=IDENT(name = "threadData")) then
8307+
"threadData"
8308+
83068309
case exp as CALL(attr=attr as CALL_ATTR(tailCall=tail as TAIL(__))) then
83078310
let &postExp = buffer ""
83088311
let tail = daeExpTailCall(expLst,tail.vars,context,&preExp,&postExp,&varDecls)

Compiler/Util/Print.mo

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -43,102 +43,86 @@ encapsulated package Print
4343

4444
public function saveAndClearBuf "saves and clears content of buffer and return a handle to the saved buffer so it can be restored by restorBuf later on"
4545
output Integer handle;
46-
external "C" handle = Print_saveAndClearBuf() annotation(Library = "omcruntime");
46+
external "C" handle = Print_saveAndClearBuf(OpenModelica.threadData()) annotation(Library = "omcruntime");
4747
end saveAndClearBuf;
4848

4949
public function restoreBuf
5050
input Integer handle;
51-
external "C" Print_restoreBuf(handle) annotation(Library = "omcruntime");
51+
external "C" Print_restoreBuf(OpenModelica.threadData(),handle) annotation(Library = "omcruntime");
5252
end restoreBuf;
5353

54-
/* TODO: Implement an external C function for bootstrapped omc or remove me. DO NOT SIMPLY REMOVE THIS COMMENT
55-
public function setBufSize
56-
input Integer newSize;
57-
58-
external "C" Print_setBufSize(newSize) annotation(Library = "omcruntime");
59-
end setBufSize;*/
60-
61-
/* TODO: Implement an external C function for bootstrapped omc or remove me. DO NOT SIMPLY REMOVE THIS COMMENT
62-
public function unSetBufSize
63-
input Integer newSize "not used, this is a debuging func";
64-
65-
external "C" Print_unSetBufSize(newSize) annotation(Library = "omcruntime");
66-
end unSetBufSize;*/
67-
6854
public function printErrorBuf
6955
input String inString;
7056

71-
external "C" Print_printErrorBuf(inString) annotation(Library = "omcruntime");
57+
external "C" Print_printErrorBuf(OpenModelica.threadData(),inString) annotation(Library = "omcruntime");
7258
end printErrorBuf;
7359

7460
public function clearErrorBuf
7561

76-
external "C" Print_clearErrorBuf() annotation(Library = "omcruntime");
62+
external "C" Print_clearErrorBuf(OpenModelica.threadData()) annotation(Library = "omcruntime");
7763
end clearErrorBuf;
7864

7965
public function getErrorString
8066
output String outString;
8167

82-
external "C" outString = Print_getErrorString() annotation(Library = "omcruntime");
68+
external "C" outString = Print_getErrorString(OpenModelica.threadData()) annotation(Library = "omcruntime");
8369
end getErrorString;
8470

8571
public function printBuf
8672
input String inString;
8773

88-
external "C" Print_printBuf(inString) annotation(Library = "omcruntime");
74+
external "C" Print_printBuf(OpenModelica.threadData(),inString) annotation(Library = "omcruntime");
8975
end printBuf;
9076

9177
public function clearBuf
9278

93-
external "C" Print_clearBuf() annotation(Library = "omcruntime");
79+
external "C" Print_clearBuf(OpenModelica.threadData()) annotation(Library = "omcruntime");
9480
end clearBuf;
9581

9682
public function getString "Does not clear the buffer"
9783
output String outString;
9884

99-
external "C" outString = Print_getString() annotation(Library = "omcruntime");
85+
external "C" outString = Print_getString(OpenModelica.threadData()) annotation(Library = "omcruntime");
10086
end getString;
10187

10288
public function writeBuf
10389
input String inString;
10490

105-
external "C" Print_writeBuf(inString) annotation(Library = "omcruntime");
91+
external "C" Print_writeBuf(OpenModelica.threadData(),inString) annotation(Library = "omcruntime");
10692
end writeBuf;
10793

10894
public function writeBufConvertLines
10995
"Writes the print buffer to the filename, with /*#modelicaLine...*/ directives converted to #line C preprocessor macros"
11096
input String filename;
111-
external "C" Print_writeBufConvertLines(filename) annotation(Library = "omcruntime");
97+
external "C" Print_writeBufConvertLines(OpenModelica.threadData(),filename) annotation(Library = "omcruntime");
11298
end writeBufConvertLines;
11399

114100
public function getBufLength
115101
"Gets the actual length of the filled space in the print buffer."
116102
output Integer outBufFilledLength;
117103

118-
external "C" outBufFilledLength = Print_getBufLength() annotation(Library = "omcruntime");
104+
external "C" outBufFilledLength = Print_getBufLength(OpenModelica.threadData()) annotation(Library = "omcruntime");
119105
end getBufLength;
120106

121107
public function printBufSpace
122108
"Prints the given number of spaces to the print buffer."
123109
input Integer inNumOfSpaces;
124110

125-
external "C" Print_printBufSpace(inNumOfSpaces) annotation(Library = "omcruntime");
111+
external "C" Print_printBufSpace(OpenModelica.threadData(),inNumOfSpaces) annotation(Library = "omcruntime");
126112
end printBufSpace;
127113

128114
public function printBufNewLine
129115
"Prints one new line character to the print buffer."
130116

131-
external "C" Print_printBufNewLine() annotation(Library = "omcruntime");
117+
external "C" Print_printBufNewLine(OpenModelica.threadData()) annotation(Library = "omcruntime");
132118
end printBufNewLine;
133119

134120
public function hasBufNewLineAtEnd
135121
"Tests if the last outputted character in the print buffer is a new line.
136122
It is a (temporary) workaround to stringLength()'s O(n) cost."
137123
output Boolean outHasNewLineAtEnd ;
138124

139-
external "C" outHasNewLineAtEnd = Print_hasBufNewLineAtEnd() annotation(Library = "omcruntime");
125+
external "C" outHasNewLineAtEnd = Print_hasBufNewLineAtEnd(OpenModelica.threadData()) annotation(Library = "omcruntime");
140126
end hasBufNewLineAtEnd;
141127

142128
end Print;
143-
144-

Compiler/runtime/Print_omc.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,43 +35,43 @@
3535
#include "printimpl.c"
3636
#include "ModelicaUtilities.h"
3737

38-
extern int Print_saveAndClearBuf()
38+
extern int Print_saveAndClearBuf(threadData_t *threadData)
3939
{
4040
int handle = PrintImpl__saveAndClearBuf();
4141
if (handle < 0) MMC_THROW();
4242
return handle;
4343
}
4444

45-
extern void Print_restoreBuf(int handle)
45+
extern void Print_restoreBuf(threadData_t *threadData,int handle)
4646
{
4747
if (PrintImpl__restoreBuf(handle))
4848
MMC_THROW();
4949
}
5050

51-
extern void Print_printErrorBuf(const char* str)
51+
extern void Print_printErrorBuf(threadData_t *threadData,const char* str)
5252
{
5353
if (PrintImpl__printErrorBuf(str))
5454
MMC_THROW();
5555
}
5656

57-
extern void Print_printBuf(const char* str)
57+
extern void Print_printBuf(threadData_t *threadData,const char* str)
5858
{
5959
// fprintf(stderr, "Print_printBuf: %s\n", str);
6060
if (PrintImpl__printBuf(str))
6161
MMC_THROW();
6262
}
6363

64-
extern int Print_hasBufNewLineAtEnd(void)
64+
extern int Print_hasBufNewLineAtEnd(threadData_t *threadData)
6565
{
6666
return PrintImpl__hasBufNewLineAtEnd();
6767
}
6868

69-
extern int Print_getBufLength(void)
69+
extern int Print_getBufLength(threadData_t *threadData)
7070
{
7171
return PrintImpl__getBufLength();
7272
}
7373

74-
extern const char* Print_getString(void)
74+
extern const char* Print_getString(threadData_t *threadData)
7575
{
7676
const char* res = PrintImpl__getString();
7777
if (res == NULL)
@@ -80,44 +80,44 @@ extern const char* Print_getString(void)
8080
return strcpy(ModelicaAllocateString(strlen(res)), res);
8181
}
8282

83-
extern const char* Print_getErrorString(void)
83+
extern const char* Print_getErrorString(threadData_t *threadData)
8484
{
8585
const char* res = PrintImpl__getErrorString();
8686
if (res == NULL)
8787
MMC_THROW();
8888
return strcpy(ModelicaAllocateString(strlen(res)), res);
8989
}
9090

91-
extern void Print_clearErrorBuf(void)
91+
extern void Print_clearErrorBuf(threadData_t *threadData)
9292
{
9393
PrintImpl__clearErrorBuf();
9494
}
9595

96-
extern void Print_clearBuf(void)
96+
extern void Print_clearBuf(threadData_t *threadData)
9797
{
9898
// fprintf(stderr, "Print_clearBuf\n");
9999
PrintImpl__clearBuf();
100100
}
101101

102-
extern void Print_printBufSpace(int numSpace)
102+
extern void Print_printBufSpace(threadData_t *threadData,int numSpace)
103103
{
104104
if (PrintImpl__printBufSpace(numSpace))
105105
MMC_THROW();
106106
}
107107

108-
extern void Print_printBufNewLine(void)
108+
extern void Print_printBufNewLine(threadData_t *threadData)
109109
{
110110
if (PrintImpl__printBufNewLine())
111111
MMC_THROW();
112112
}
113113

114-
extern void Print_writeBuf(const char* filename)
114+
extern void Print_writeBuf(threadData_t *threadData,const char* filename)
115115
{
116116
if (PrintImpl__writeBuf(filename))
117117
MMC_THROW();
118118
}
119119

120-
extern void Print_writeBufConvertLines(const char* filename)
120+
extern void Print_writeBufConvertLines(threadData_t *threadData,const char* filename)
121121
{
122122
if (PrintImpl__writeBufConvertLines(filename))
123123
MMC_THROW();

Makefile.common

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ docs: mkbuilddirs
5858
rm -f $(builddir_doc)/omc/testmodels/CMake*.txt
5959
cp -p ./SimulationRuntime/interactive/README.txt $(builddir_doc)/omc/OpenModelica-InteractiveSimulation-README.txt
6060
# man pages
61-
(cd doc/manpages/ && for f in *.1; do gzip $$f -c > ../../$(builddir_man)/man1/$$f.gz && touch -r $$f ../../$(builddir_man)/man1/$$f.gz; done)
61+
(cd doc/manpages/ && for f in *.1; do cp -p $$f ../../$(builddir_man)/man1/ && gzip -f ../../$(builddir_man)/man1/$$f ; done)
6262

6363
GC_HEADERS=gc.h gc_allocator.h gc_amiga_redirects.h gc_backptr.h gc_config_macros.h gc_gcj.h
6464
libgc-dev: /usr/include/gc/gc_inline.h

SimulationRuntime/c/openmodelica.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ typedef struct {
268268

269269
extern omc_alloc_interface_t omc_alloc_interface;
270270
extern omc_alloc_interface_t omc_alloc_interface_pooled;
271+
typedef threadData_t* OpenModelica_threadData_ThreadData;
271272

272273
#if defined(__cplusplus)
273274
} /* end extern "C" */

0 commit comments

Comments
 (0)