[m-rev.] diff: updates to extras/concurrency
Peter Ross
pro at missioncriticalit.com
Sat Mar 1 02:23:05 AEDT 2003
Hi,
===================================================================
Estimated hours taken: 1
Branches: main, release
Update associated files so that extras/concurrency directory compiles
in the il grade.
extras/concurrency/global.m:
Make global(T) a foreign_type. Add a C# class ME_Global which
is used to store the global variable in and add C# foreign
procs to access ME_Global.
extras/concurrency/philo2.m:
extras/concurrency/philo3.m:
Add a C# version of rand_sleep.
Index: global.m
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/concurrency/global.m,v
retrieving revision 1.2
diff -u -r1.2 global.m
--- global.m 5 Dec 2000 02:07:12 -0000 1.2
+++ global.m 28 Feb 2003 15:07:58 -0000
@@ -20,6 +20,8 @@
:- import_module io.
:- type global(T).
+:- pragma foreign_type(c, global(T), "MR_Word").
+:- pragma foreign_type(il, global(T), "class [global__csharp_code]ME_Global").
% new(Thing, Key, IO0, IO) binds `Key' to an abstract key refering
% to the object `Thing'.
@@ -41,8 +43,13 @@
:- import_module std_util.
-:- type global(T)
- ---> global(c_pointer).
+:- type global(T).
+
+:- pragma foreign_decl("C#", "
+ public class ME_Global {
+ public object val;
+ }
+").
:- pragma c_code(global__new(Thing::in, Glob::out, IO0::di, IO::uo),
will_not_call_mercury, "{
@@ -52,16 +59,28 @@
Glob = (MR_Word) tmp;
IO = IO0;
}").
+:- pragma foreign_proc("C#", new(Thing::in, Glob::out, _IO0::di, _IO::uo),
+ [will_not_call_mercury, thread_safe, promise_pure], "
+ Glob = new ME_Global();
+ Glob.val = Thing;
+").
:- pragma c_code(global__get(Glob::in, Thing::out, IO0::di, IO::uo),
will_not_call_mercury, "{
Thing = * (MR_Word *) Glob;
IO = IO0;
}").
+:- pragma foreign_proc("C#", get(Glob::in, Thing::out, _IO0::di, _IO::uo),
+ [will_not_call_mercury, thread_safe, promise_pure], "
+ Thing = Glob.val;
+").
:- pragma c_code(global__set(Glob::in, Thing::in, IO0::di, IO::uo),
will_not_call_mercury, "{
* ((MR_Word *) Glob) = Thing;
IO = IO0;
}").
-
+:- pragma foreign_proc("C#", set(Glob::in, Thing::in, _IO0::di, _IO::uo),
+ [will_not_call_mercury, thread_safe, promise_pure], "
+ Glob.val = Thing;
+").
Index: philo2.m
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/concurrency/philo2.m,v
retrieving revision 1.5
diff -u -r1.5 philo2.m
--- philo2.m 28 Feb 2003 14:42:37 -0000 1.5
+++ philo2.m 28 Feb 2003 15:07:58 -0000
@@ -1,5 +1,5 @@
%---------------------------------------------------------------------------%
-% Copyright (C) 2000-2002 The University of Melbourne.
+% Copyright (C) 2000-2003 The University of Melbourne.
% This file may only be copied under the terms of the GNU Library General
% Public License - see the file COPYING.LIB in the Mercury distribution.
%---------------------------------------------------------------------------%
@@ -98,4 +98,8 @@
sleep((rand() % Int));
#endif
IO = IO0;
+}").
+:- pragma foreign_proc("C#", rand_sleep(Int::in, _IO0::di, _IO::uo),
+ [thread_safe, will_not_call_mercury, promise_pure], "{
+ System.Threading.Thread.Sleep((new System.Random()).Next(Int) * 1000);
}").
Index: philo3.m
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/concurrency/philo3.m,v
retrieving revision 1.2
diff -u -r1.2 philo3.m
--- philo3.m 30 Oct 2002 15:58:48 -0000 1.2
+++ philo3.m 28 Feb 2003 15:07:58 -0000
@@ -86,6 +86,10 @@
#endif
IO = IO0;
}").
+:- pragma foreign_proc("C#", rand_sleep(Int::in, _IO0::di, _IO::uo),
+ [thread_safe, will_not_call_mercury, promise_pure], "{
+ System.Threading.Thread.Sleep((new System.Random()).Next(Int) * 1000);
+}").
%------------------------------------------------------------------------------%
%------------------------------------------------------------------------------%
--------------------------------------------------------------------------
mercury-reviews mailing list
post: mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the reviews
mailing list