Skip to content

Commit

Permalink
Pass threadData using OpenModelica.threadData() in external function …
Browse files Browse the repository at this point in the history
…calls

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@17986 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Nov 3, 2013
1 parent d5b507d commit a908468
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 47 deletions.
1 change: 1 addition & 0 deletions Compiler/FrontEnd/InstUtil.mo
Original file line number Diff line number Diff line change
Expand Up @@ -5898,6 +5898,7 @@ algorithm
list<Absyn.Exp> rest;
Env.Cache cache;
Prefix.Prefix pre;
DAE.ComponentRef cr;
case (cache,_,{},impl,st,_,_) then (cache,{},{},st);
case (cache,env,(e :: rest),impl,st,pre,_)
equation
Expand Down
10 changes: 10 additions & 0 deletions Compiler/FrontEnd/ModelicaBuiltin.mo
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,16 @@ type VariableNames "An array of variable names, e.g. {a.b,a[1].b[3].c}, or a sin

end $Code;

function threadData
output ThreadData threadData;
protected
record ThreadData
end ThreadData;
external "builtin" annotation(Documentation(info="<html>
<p>Used to access thread-specific data in external functions.</p>
</html>"));
end threadData;

package Internal "Contains internal implementations, e.g. overloaded builtin functions"

type BuiltinType "Integer,Real,String,enumeration or array of some kind"
Expand Down
7 changes: 5 additions & 2 deletions Compiler/Template/CodegenC.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -5163,6 +5163,7 @@ template functionBodyExternalFunction(Function fn, Boolean inFunc)
match fn
case efn as EXTERNAL_FUNCTION(__) then
let()= System.tmpTickReset(1)
let()= System.tmpTickResetIndex(0,1) /* Boxed array indices */
let fname = underscorePath(name)
let retType = if outVars then '<%fname%>_rettype' else "void"
let &preExp = buffer "" /*BUFD*/
Expand All @@ -5176,8 +5177,7 @@ case efn as EXTERNAL_FUNCTION(__) then
varInit(var, retVar, i1, &varDecls /*BUFD*/, &outputAlloc /*BUFC*/, &varFrees /*BUFF*/)
; empty /* increase the counter! */
)


let &varDecls += addRootsTempArray()
let boxedFn = if acceptMetaModelicaGrammar() then functionBodyBoxed(fn)
let fnBody = <<
<%retType%> omc_<%fname%>(threadData_t *threadData<%funArgs |> arg => ', <%
Expand Down Expand Up @@ -8303,6 +8303,9 @@ template daeExpCall(Exp call, Context context, Text &preExp /*BUFP*/, Text &varD
let argStr = daeExp(s1, context, &preExp, &varDecls)
unboxRecord(argStr, ty, &preExp, &varDecls)

case CALL(path=IDENT(name = "threadData")) then
"threadData"

case exp as CALL(attr=attr as CALL_ATTR(tailCall=tail as TAIL(__))) then
let &postExp = buffer ""
let tail = daeExpTailCall(expLst,tail.vars,context,&preExp,&postExp,&varDecls)
Expand Down
44 changes: 14 additions & 30 deletions Compiler/Util/Print.mo
Original file line number Diff line number Diff line change
Expand Up @@ -43,102 +43,86 @@ encapsulated package Print

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"
output Integer handle;
external "C" handle = Print_saveAndClearBuf() annotation(Library = "omcruntime");
external "C" handle = Print_saveAndClearBuf(OpenModelica.threadData()) annotation(Library = "omcruntime");
end saveAndClearBuf;

public function restoreBuf
input Integer handle;
external "C" Print_restoreBuf(handle) annotation(Library = "omcruntime");
external "C" Print_restoreBuf(OpenModelica.threadData(),handle) annotation(Library = "omcruntime");
end restoreBuf;

/* TODO: Implement an external C function for bootstrapped omc or remove me. DO NOT SIMPLY REMOVE THIS COMMENT
public function setBufSize
input Integer newSize;
external "C" Print_setBufSize(newSize) annotation(Library = "omcruntime");
end setBufSize;*/

/* TODO: Implement an external C function for bootstrapped omc or remove me. DO NOT SIMPLY REMOVE THIS COMMENT
public function unSetBufSize
input Integer newSize "not used, this is a debuging func";
external "C" Print_unSetBufSize(newSize) annotation(Library = "omcruntime");
end unSetBufSize;*/

public function printErrorBuf
input String inString;

external "C" Print_printErrorBuf(inString) annotation(Library = "omcruntime");
external "C" Print_printErrorBuf(OpenModelica.threadData(),inString) annotation(Library = "omcruntime");
end printErrorBuf;

public function clearErrorBuf

external "C" Print_clearErrorBuf() annotation(Library = "omcruntime");
external "C" Print_clearErrorBuf(OpenModelica.threadData()) annotation(Library = "omcruntime");
end clearErrorBuf;

public function getErrorString
output String outString;

external "C" outString = Print_getErrorString() annotation(Library = "omcruntime");
external "C" outString = Print_getErrorString(OpenModelica.threadData()) annotation(Library = "omcruntime");
end getErrorString;

public function printBuf
input String inString;

external "C" Print_printBuf(inString) annotation(Library = "omcruntime");
external "C" Print_printBuf(OpenModelica.threadData(),inString) annotation(Library = "omcruntime");
end printBuf;

public function clearBuf

external "C" Print_clearBuf() annotation(Library = "omcruntime");
external "C" Print_clearBuf(OpenModelica.threadData()) annotation(Library = "omcruntime");
end clearBuf;

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

external "C" outString = Print_getString() annotation(Library = "omcruntime");
external "C" outString = Print_getString(OpenModelica.threadData()) annotation(Library = "omcruntime");
end getString;

public function writeBuf
input String inString;

external "C" Print_writeBuf(inString) annotation(Library = "omcruntime");
external "C" Print_writeBuf(OpenModelica.threadData(),inString) annotation(Library = "omcruntime");
end writeBuf;

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

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

external "C" outBufFilledLength = Print_getBufLength() annotation(Library = "omcruntime");
external "C" outBufFilledLength = Print_getBufLength(OpenModelica.threadData()) annotation(Library = "omcruntime");
end getBufLength;

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

external "C" Print_printBufSpace(inNumOfSpaces) annotation(Library = "omcruntime");
external "C" Print_printBufSpace(OpenModelica.threadData(),inNumOfSpaces) annotation(Library = "omcruntime");
end printBufSpace;

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

external "C" Print_printBufNewLine() annotation(Library = "omcruntime");
external "C" Print_printBufNewLine(OpenModelica.threadData()) annotation(Library = "omcruntime");
end printBufNewLine;

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

external "C" outHasNewLineAtEnd = Print_hasBufNewLineAtEnd() annotation(Library = "omcruntime");
external "C" outHasNewLineAtEnd = Print_hasBufNewLineAtEnd(OpenModelica.threadData()) annotation(Library = "omcruntime");
end hasBufNewLineAtEnd;

end Print;


28 changes: 14 additions & 14 deletions Compiler/runtime/Print_omc.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,43 +35,43 @@
#include "printimpl.c"
#include "ModelicaUtilities.h"

extern int Print_saveAndClearBuf()
extern int Print_saveAndClearBuf(threadData_t *threadData)
{
int handle = PrintImpl__saveAndClearBuf();
if (handle < 0) MMC_THROW();
return handle;
}

extern void Print_restoreBuf(int handle)
extern void Print_restoreBuf(threadData_t *threadData,int handle)
{
if (PrintImpl__restoreBuf(handle))
MMC_THROW();
}

extern void Print_printErrorBuf(const char* str)
extern void Print_printErrorBuf(threadData_t *threadData,const char* str)
{
if (PrintImpl__printErrorBuf(str))
MMC_THROW();
}

extern void Print_printBuf(const char* str)
extern void Print_printBuf(threadData_t *threadData,const char* str)
{
// fprintf(stderr, "Print_printBuf: %s\n", str);
if (PrintImpl__printBuf(str))
MMC_THROW();
}

extern int Print_hasBufNewLineAtEnd(void)
extern int Print_hasBufNewLineAtEnd(threadData_t *threadData)
{
return PrintImpl__hasBufNewLineAtEnd();
}

extern int Print_getBufLength(void)
extern int Print_getBufLength(threadData_t *threadData)
{
return PrintImpl__getBufLength();
}

extern const char* Print_getString(void)
extern const char* Print_getString(threadData_t *threadData)
{
const char* res = PrintImpl__getString();
if (res == NULL)
Expand All @@ -80,44 +80,44 @@ extern const char* Print_getString(void)
return strcpy(ModelicaAllocateString(strlen(res)), res);
}

extern const char* Print_getErrorString(void)
extern const char* Print_getErrorString(threadData_t *threadData)
{
const char* res = PrintImpl__getErrorString();
if (res == NULL)
MMC_THROW();
return strcpy(ModelicaAllocateString(strlen(res)), res);
}

extern void Print_clearErrorBuf(void)
extern void Print_clearErrorBuf(threadData_t *threadData)
{
PrintImpl__clearErrorBuf();
}

extern void Print_clearBuf(void)
extern void Print_clearBuf(threadData_t *threadData)
{
// fprintf(stderr, "Print_clearBuf\n");
PrintImpl__clearBuf();
}

extern void Print_printBufSpace(int numSpace)
extern void Print_printBufSpace(threadData_t *threadData,int numSpace)
{
if (PrintImpl__printBufSpace(numSpace))
MMC_THROW();
}

extern void Print_printBufNewLine(void)
extern void Print_printBufNewLine(threadData_t *threadData)
{
if (PrintImpl__printBufNewLine())
MMC_THROW();
}

extern void Print_writeBuf(const char* filename)
extern void Print_writeBuf(threadData_t *threadData,const char* filename)
{
if (PrintImpl__writeBuf(filename))
MMC_THROW();
}

extern void Print_writeBufConvertLines(const char* filename)
extern void Print_writeBufConvertLines(threadData_t *threadData,const char* filename)
{
if (PrintImpl__writeBufConvertLines(filename))
MMC_THROW();
Expand Down
2 changes: 1 addition & 1 deletion Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ docs: mkbuilddirs
rm -f $(builddir_doc)/omc/testmodels/CMake*.txt
cp -p ./SimulationRuntime/interactive/README.txt $(builddir_doc)/omc/OpenModelica-InteractiveSimulation-README.txt
# man pages
(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)
(cd doc/manpages/ && for f in *.1; do cp -p $$f ../../$(builddir_man)/man1/ && gzip -f ../../$(builddir_man)/man1/$$f ; done)

GC_HEADERS=gc.h gc_allocator.h gc_amiga_redirects.h gc_backptr.h gc_config_macros.h gc_gcj.h
libgc-dev: /usr/include/gc/gc_inline.h
Expand Down
1 change: 1 addition & 0 deletions SimulationRuntime/c/openmodelica.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ typedef struct {

extern omc_alloc_interface_t omc_alloc_interface;
extern omc_alloc_interface_t omc_alloc_interface_pooled;
typedef threadData_t* OpenModelica_threadData_ThreadData;

#if defined(__cplusplus)
} /* end extern "C" */
Expand Down

0 comments on commit a908468

Please sign in to comment.