mod to omnithread for NT.
Matthew Newhook
matthew_newhook@stratos.ca
Thu, 3 Jul 1997 15:46:43 -0230
Hi,
What follows is a change to the omnithread library to allow an arbitrary
thread-wrapper function to be setup. The function of this is to
allow some per-thread stuff to be setup for each thread that is
created. We use this to create objectstore thread handles under NT.
This implementation is ONLY for NT also. If you use
omni_thread::set_thread_wrapper under something other that NT you
will get undefined symbols.
Here is a sample that uses this new API:
#include "corba/compat.h"
#include "corba/cap/ostore.h"
#include <omnithread.h>
#include <ostore/ostore.hh>
static void*
thr_ret(void *arg)
{
struct thread_arg* thr_arg = (struct thread_arg*)arg;
void* (*fn)(void*) = thr_arg->fn;
void* the_arg = thr_arg->arg;
delete thr_arg;
void* rc;
OS_ESTABLISH_FAULT_HANDLER
rc = (*fn)(the_arg);
OS_END_FAULT_HANDLER
return rc;
}
/*static*/ void
c_ostore_handler::ostore_init()
{
omni_thread::set_thread_wrapper(thr_ret);
}
----
diffs follow
----
--- /pub/corba/omniORB_2.2.0/include/omnithread.h Tue May 6 13:26:59 1997
+++ include/omnithread.h Thu Jul 3 12:37:26 1997
@@ -242,6 +242,11 @@
//
///////////////////////////////////////////////////////////////////////////
+struct thread_arg
+{
+ void* (*fn)(void*);
+ void* arg;
+};
class _OMNITHREAD_NTDLL_ omni_thread {
public:
@@ -260,6 +265,10 @@
// been reclaimed (i.e. waiting to be joined).
};
+ static void set_thread_wrapper(void* (*fn)(void* arg));
+ // set a up wrapper function that is called *before*
+ // the thread specific function is called.
+
//
// Constructors set up the thread object but the thread won't start until
// start() is called. The create method can be used to construct and start
@@ -364,6 +373,8 @@
static omni_mutex* next_id_mutex;
static int next_id;
int _id;
+
+ static void *(*fn_wrapper)(void* arg);
void (*fn_void)(void*);
void* (*fn_ret)(void*);
--- /pub/corba/omniORB_2.2.0/src/lib/omnithread/nt.cc Tue May 6 13:12:54 1997
+++ src/lib/omnithread/nt.cc Thu Jul 3 12:42:49 1997
@@ -406,6 +406,8 @@
// Wrapper for thread creation.
//
+/*static*/ void *(*omni_thread::fn_wrapper)(void *(*fn_ret)(void*)) = 0;
+
extern "C" {
//
@@ -501,8 +503,19 @@
thread_arg = arg;
detached = det; // may be altered in start_undetached()
- handle = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)wrapper,
+ if (fn_wrapper == 0)
+ {
+ handle = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)wrapper,
(LPVOID)this, CREATE_SUSPENDED, &nt_id);
+ }
+ else
+ {
+ struct thread_arg* thr_arg = new struct thread_arg;
+ thr_arg->fn = (void*(*)(void*))wrapper;
+ thr_arg->arg = this;
+ handle = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)fn_wrapper,
+ (LPVOID)thr_arg, CREATE_SUSPENDED, &nt_id);
+ }
if (handle == NULL) {
cerr << "omni_thread::common_constructor: CreateThread error "
@@ -822,6 +835,11 @@
}
}
+/*static*/ void
+omni_thread::set_thread_wrapper(void *(*fn)(void *))
+{
+ fn_wrapper = fn;
+}
static void get_time_now(unsigned long* abs_sec, unsigned long* abs_nsec)
{
Matthew
--
Matthew Newhook. matthew_newhook@stratos.ca, http://www.engr.mun.ca/~matthew
Software Designer, Stratos Network Research.
w: (709) 364-5950, h: (709)-745-4346