OpenCores
URL https://opencores.org/ocsvn/an-fpga-implementation-of-low-latency-noc-based-mpsoc/an-fpga-implementation-of-low-latency-noc-based-mpsoc/trunk

Subversion Repositories an-fpga-implementation-of-low-latency-noc-based-mpsoc

[/] [an-fpga-implementation-of-low-latency-noc-based-mpsoc/] [trunk/] [mpsoc/] [src_processor/] [aeMB/] [sw/] [aemb/] [semaphore.hh] - Rev 48

Compare with Previous | Blame | View Log

/* $Id: semaphore.hh,v 1.1 2008-04-28 20:29:15 sybreon Exp $
** 
** AEMB2 HI-PERFORMANCE CPU 
** Copyright (C) 2004-2007 Shawn Tan Ser Ngiap <shawn.tan@aeste.net>
**  
** This file is part of AEMB.
**
** AEMB is free software: you can redistribute it and/or modify it
** under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** AEMB 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 General Public
** License for more details.
**
** You should have received a copy of the GNU General Public License
** along with AEMB.  If not, see <http://www.gnu.org/licenses/>.
*/

/**
   General semaphore library
   @file semaphore.hh  
 */

#include "thread.hh"

#ifndef _AEMB_SEMAPHORE_HH
#define _AEMB_SEMAPHORE_HH

#ifdef __cplusplus
extern "C" {
#endif

  // TODO: Extend this library to include threading mechanisms such as
  // semaphores, mutexes and such.

  /**
     Semaphore struct.     
     Presently implemented as software solution but a hardware one may be
     required as the threads are hardware.
  */
  
  typedef int semaphore;

  /**
     Software Semaphore Signal.

     Increment the semaphore and run. This is a software mechanism.
  */
  static inline void aembSignal(volatile semaphore _sem) 
  { 
    _aembLockMTX();
    _sem++; 
    _aembFreeMTX();
  }
    
  /**
     Software Semaphore Wait.

     Decrement the semaphore and block if < 0. This is a software
     mechanism.
  */
  static inline void aembWait(volatile semaphore _sem) 
  {
    _aembLockMTX();
    _sem--; 
    _aembFreeMTX();
    while (_sem < 0); 
  }

  

  /**
     Implements a simple rendezvous mechanism
   */
  /*
  static inline void aembRendezvous()
  {
    if (isThread1())
      {
        wait(__mutex_rendezvous0);
        signal(__mutex_rendezvous1);
      }
    else
      {
        signal(__mutex_rendezvous0);
        wait(__mutex_rendezvous1);
      }
  }
  */

#ifdef __cplusplus
}
#endif

#endif

/*
$log$
*/

Compare with Previous | Blame | View Log

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.