Logo Search packages:      
Sourcecode: u++ version File versions

uSystemTask.cc

//                              -*- Mode: C++ -*- 
// 
// uC++ Version 5.0.1, Copyright (C) Peter A. Buhr 1998
// 
// uSystemTask.cc -- 
// 
// Author           : Peter A. Buhr
// Created On       : Mon Jun 22 15:25:53 1998
// Last Modified By : Peter A. Buhr
// Last Modified On : Sat Aug  7 11:15:12 2004
// Update Count     : 90
//
// This  library is free  software; you  can redistribute  it and/or  modify it
// under the terms of the GNU Lesser General Public License as published by the
// Free Software  Foundation; either  version 2.1 of  the License, or  (at your
// option) any later version.
// 
// This library is distributed in the  hope that it will be useful, but WITHOUT
// ANY  WARRANTY;  without even  the  implied  warranty  of MERCHANTABILITY  or
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
// for more details.
// 
// You should  have received a  copy of the  GNU Lesser General  Public License
// along  with this library.
// 


#define __U_KERNEL__
#include <uC++.h>
#include <uSystemTask.h>

#include <cstdio>                         // fprintf

//#include <uDebug.h>


volatile bool uSystemTask::pthreadDetach = false;


void uSystemTask::pthreadCheck() {
    if ( pthreadDetachCnt != 0 ) {
      uWait detached;
    } // if
} // uSystemTask::pthreadCheck


void uSystemTask::pthreadDetachStart() {
    pthreadDetach = true;
    // Do the increment here because of potential recursive entry from "reaper"
    // creating another pthread.
    pthreadDetachCnt += 1;
} // uSystemTask::pthreadDetachStart


void uSystemTask::pthreadDetachEnd( uBaseTask &victim ) {
    uSystemTask::victim = &victim;
    pthreadDetachCnt -= 1;
} // uSystemTask::pthreadDetachEnd


void uSystemTask::main() {
    for ( ;; ) {
      uAccept( ~uSystemTask ) {
          break;
      } uOr uAccept( reaper ) {
          delete victim;
      } uOr uAccept( pthreadCheck ) {
      } uOr uAccept( pthreadDetachStart ) {
      } uOr uAccept( pthreadDetachEnd ) {
          delete victim;
          if ( pthreadDetachCnt == 0 ) {
            uSignalBlock detached;
          } // if
      } uOr uTimeout( uDuration( 1 ) ) {        // 1 second
      } // uAccept

#if __U_LOCALDEBUGGER_H__
      // check for debugger attach request

      if ( uKernelModule::uAttaching != 0 ) {
#ifdef __U_DEBUG_H__
          uDebugPrt( "(uSystemTask &)0x%p.main, attaching\n", this );
#endif // __U_DEBUG_H__ 
          int port = uKernelModule::uAttaching;
          uKernelModule::uAttaching = 0;        // reset flag so don't do this again
          uLocalDebugger::uLocalDebuggerInstance = new uLocalDebugger( port );
#ifdef __U_DEBUG_H__
          uDebugPrt( "(uSystemTask &)0x%p.main, local debugger started\n", this );
#endif // __U_DEBUG_H__
      } // if

#if 0 // moved to uProcessor kernel because of problems, but may ultimately need to be here for KDB
#ifndef __U_MULTI__
      if ( uKernelModule::uDeadlock ) {
          fprintf( stderr, "Clusters and tasks present at deadlock:\n" );
          uSeqGen<uClusterDL> ci;
          uClusterDL *cr;
          for ( ci.uOver( *uKernelModule::uGlobalClusters ); ci >> cr; ) {
            uCluster *cluster = &cr->uGet();
            fprintf( stderr, "%.256s (0x%p)\n", cluster->uGetName(), cluster );

            fprintf( stderr, "\ttasks:\n" );
            uBaseTaskDL *bt;
            for ( uSeqGen<uBaseTaskDL> tgen( cluster->uTasksOnCluster ); tgen >> bt; ) {
                uBaseTask *task = &bt->uGet();
                fprintf( stderr, "\t\t %.256s (0x%p)\n", task->uGetName(), task );
            } // for
          } // for
          uAbort( ": no ready or pending tasks.\n"
                "Possible cause is tasks in a synchronization or mutual exclusion deadlock.", this );
      } // if
#endif // ! __U_MULTI__
#endif

#endif // __U_LOCALDEBUGGER_H__
    } // for
} // uSystemTask::main


uSystemTask::uSystemTask() : uBaseTask( *uKernelModule::uSystemCluster ) {
    pthreadDetachCnt = 0;
} // uSystemTask::uSystemTask


uSystemTask::~uSystemTask() {
} // uSystemTask::~uSystemTask


void uSystemTask::reaper( uBaseTask &victim ) {
    uSystemTask::victim = &victim;
} // uSystemTask::reaper


// Local Variables: //
// compile-command: "gmake install" //
// End: //

Generated by  Doxygen 1.6.0   Back to index