Subversion Repositories shark

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

/*
 * Copyright 1995, Brown University, Providence, RI
 *
 * Permission to use and modify this software and its documentation for
 * any purpose other than its incorporation into a commercial product is
 * hereby granted without fee.  Permission to copy and distribute this
 * software and its documentation only for non-commercial use is also
 * granted without fee, provided, however, that the above copyright notice
 * appear in all copies, that both that copyright notice and this permission
 * notice appear in supporting documentation, that the name of Brown
 * University not be used in advertising or publicity pertaining to
 * distribution of the software without specific, written prior permission,
 * and that the person doing the distribution notify Brown University of
 * such distributions outside of his or her organization. Brown University
 * makes no representations about the suitability of this software for
 * any purpose.  It is provided "as is" without express or implied warranty.
 * Brown University requests notification of any modifications to this
 * software or its documentation.
 *
 * Send the following redistribution information:
 *
 *      Name:
 *      Organization:
 *      Address (postal and/or electronic):
 *
 * To:
 *      Software Librarian
 *      Computer Science Department, Box 1910
 *      Brown University
 *      Providence, RI 02912
 *
 *              or
 *
 *      brusd@cs.brown.edu
 *
 * We will acknowledge all electronic notifications.
 */


/* -------------------------------------------------------------------------
                       Public THREAD include file
   ------------------------------------------------------------------------- */


// Original code by Tom Meyer
// Altered by Loring Holden to work with MPEGmovie object

/* $Id: thread_m.h,v 1.1.1.1 2002-03-29 14:12:59 pj Exp $ */

#ifndef THREAD_MP_HAS_BEEN_INCLUDED
#define THREAD_MP_HAS_BEEN_INCLUDED

#if defined(sol)

#ifdef CPLPLTHREADS
#include "/pro/threadtools/C++_mon/include/c++thread.h"
#else
#include <unistd.h>
#include <thread.h>
#endif
#include <string.h>

#elif defined(hp)
     // No multithreading on the HPs
#elif defined(sgi)
#include <stdio.h>
#include <ulocks.h>
#include <sys/types.h>
#include <sys/resource.h>
#include <sys/prctl.h>
#endif
#include "queue_int.H"

#if defined(sgi)
void THREADprocessor_startup_func(void *proc);
#endif
#if defined(sol)
#ifndef CPLPLTHREADS
void *THREADprocessor_startup_func(void *proc);
#endif
#endif

#if defined(sol)
#if CPLPLTHREADS
class THREAD_processor : public Thread {
#else
class THREAD_processor {
#endif
#else
class THREAD_processor {
#endif
 private:
   void *(*_start_routine)(void *, void *);
   void *_arg, *_arg2;
 protected:
#if defined(sol)
#if CPLPLTHREADS
   Semaphore *sema,*semaDone;
#else
   thread_t thr;
   sema_t sema,semaDone;
#endif
#elif defined(sgi)
   pid_t pid;
   usema_t *_sema,*semaDone;
#else
#endif
  public:
   void startup();
#if defined(sol)
#ifndef CPLPLTHREADS
   virtual void startup_func();
   THREAD_processor();
#endif
#endif
   THREAD_processor(char *name = "", char *thrname = "");
   virtual ~THREAD_processor() {}

   virtual void start_execute(void *(*start_routine)(void *, void *),
                              void *arg, void *arg2);
   virtual int wait_for_done();
   virtual int still_running();
   int running;
};

class THREAD_mp_manager {
 protected:
   int num_procs() const;
   THREAD_mp_manager(int _procs = 0);
};


class THREADprocessor : public THREAD_processor {
 protected:
 public:
   THREADprocessor(char *name = "", char *thrname = "")
   : THREAD_processor(name, thrname) {};
   virtual ~THREADprocessor() {}
};

class THREADmp_manager : public THREAD_mp_manager {
   THREADprocessor **procs;
   int _num_procs;
   void THREADmp_initproc(int i);
   static int procNum;  // just for test
   QUEUEint queue;
 public:
   THREADmp_manager(int _procs = 0);
   virtual ~THREADmp_manager();
   void enqThread(int threadNumber);
   int deqThread();
   
   int num_processes() const { return _num_procs; }
   THREADprocessor *processor(int i) const { return procs[i]; }
   void THREADmp_newproc();
};

#endif