OpenCores
URL https://opencores.org/ocsvn/aemb/aemb/trunk

Subversion Repositories aemb

[/] [aemb/] [trunk/] [sw/] [cc/] [aemb/] [semaphore.hh] - Blame information for rev 191

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 151 sybreon
/* $Id: semaphore.hh,v 1.1 2008-04-28 20:29:15 sybreon Exp $
2
**
3
** AEMB2 HI-PERFORMANCE CPU
4
** Copyright (C) 2004-2007 Shawn Tan Ser Ngiap 
5
**
6
** This file is part of AEMB.
7
**
8
** AEMB is free software: you can redistribute it and/or modify it
9
** under the terms of the GNU General Public License as published by
10
** the Free Software Foundation, either version 3 of the License, or
11
** (at your option) any later version.
12
**
13
** AEMB is distributed in the hope that it will be useful, but WITHOUT
14
** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15
** or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
16
** License for more details.
17
**
18
** You should have received a copy of the GNU General Public License
19
** along with AEMB.  If not, see .
20
*/
21
 
22
/**
23
   General semaphore library
24
   @file semaphore.hh
25
 */
26
 
27
#include "aemb/thread.hh"
28
 
29
#ifndef _AEMB_SEMAPHORE_HH
30
#define _AEMB_SEMAPHORE_HH
31
 
32
#ifdef __cplusplus
33
extern "C" {
34
#endif
35
 
36
  // TODO: Extend this library to include threading mechanisms such as
37
  // semaphores, mutexes and such.
38
 
39
  /**
40
     Semaphore struct.
41
     Presently implemented as software solution but a hardware one may be
42
     required as the threads are hardware.
43
  */
44
 
45
  typedef int semaphore;
46
 
47
  /**
48
     Software Semaphore Signal.
49
 
50
     Increment the semaphore and run. This is a software mechanism.
51
  */
52
  inline void aembSignal(volatile semaphore _sem)
53
  {
54
    _aembLockMTX();
55
    _sem++;
56
    _aembFreeMTX();
57
  }
58
 
59
  /**
60
     Software Semaphore Wait.
61
 
62
     Decrement the semaphore and block if < 0. This is a software
63
     mechanism.
64
  */
65
  inline void aembWait(volatile semaphore _sem)
66
  {
67
    _aembLockMTX();
68
    _sem--;
69
    _aembFreeMTX();
70
    while (_sem < 0);
71
  }
72
 
73
  semaphore __mutex_rendezvous0 = 0; ///< internal rendezvous mutex
74
  semaphore __mutex_rendezvous1 = 1; ///< internal rendezvous mutex
75
 
76
  /**
77
     Implements a simple rendezvous mechanism
78
   */
79
  /*
80
  inline void aembRendezvous()
81
  {
82
    if (isThread1())
83
      {
84
        wait(__mutex_rendezvous0);
85
        signal(__mutex_rendezvous1);
86
      }
87
    else
88
      {
89
        signal(__mutex_rendezvous0);
90
        wait(__mutex_rendezvous1);
91
      }
92
  }
93
  */
94
 
95
#ifdef __cplusplus
96
}
97
#endif
98
 
99
#endif
100
 
101
/*
102
$log$
103
*/

powered by: WebSVN 2.1.0

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