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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [exec/] [score/] [src/] [coresemseize.c] - Blame information for rev 30

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 unneback
/*
2
 *  CORE Semaphore Handler
3
 *
4
 *  DESCRIPTION:
5
 *
6
 *  This package is the implementation of the CORE Semaphore Handler.
7
 *  This core object utilizes standard Dijkstra counting semaphores to provide
8
 *  synchronization and mutual exclusion capabilities.
9
 *
10
 *  COPYRIGHT (c) 1989-1999.
11
 *  On-Line Applications Research Corporation (OAR).
12
 *
13
 *  The license and distribution terms for this file may be
14
 *  found in the file LICENSE in this distribution or at
15
 *  http://www.OARcorp.com/rtems/license.html.
16
 *
17
 *  $Id: coresemseize.c,v 1.2 2001-09-27 11:59:34 chris Exp $
18
 */
19
 
20
#include <rtems/system.h>
21
#include <rtems/score/isr.h>
22
#include <rtems/score/coresem.h>
23
#include <rtems/score/states.h>
24
#include <rtems/score/thread.h>
25
#include <rtems/score/threadq.h>
26
#if defined(RTEMS_MULTIPROCESSING)
27
#include <rtems/score/mpci.h>
28
#endif
29
 
30
/*PAGE
31
 *
32
 *  _CORE_semaphore_Seize
33
 *
34
 *  This routine attempts to allocate a core semaphore to the calling thread.
35
 *
36
 *  Input parameters:
37
 *    the_semaphore - pointer to semaphore control block
38
 *    id            - id of object to wait on
39
 *    wait          - TRUE if wait is allowed, FALSE otherwise
40
 *    timeout       - number of ticks to wait (0 means forever)
41
 *
42
 *  Output parameters:  NONE
43
 *
44
 *  INTERRUPT LATENCY:
45
 *    available
46
 *    wait
47
 */
48
 
49
void _CORE_semaphore_Seize(
50
  CORE_semaphore_Control  *the_semaphore,
51
  Objects_Id               id,
52
  boolean                  wait,
53
  Watchdog_Interval        timeout
54
)
55
{
56
  Thread_Control *executing;
57
  ISR_Level       level;
58
 
59
  executing = _Thread_Executing;
60
  executing->Wait.return_code = CORE_SEMAPHORE_STATUS_SUCCESSFUL;
61
  _ISR_Disable( level );
62
  if ( the_semaphore->count != 0 ) {
63
    the_semaphore->count -= 1;
64
    _ISR_Enable( level );
65
    return;
66
  }
67
 
68
  if ( !wait ) {
69
    _ISR_Enable( level );
70
    executing->Wait.return_code = CORE_SEMAPHORE_STATUS_UNSATISFIED_NOWAIT;
71
    return;
72
  }
73
 
74
  _Thread_queue_Enter_critical_section( &the_semaphore->Wait_queue );
75
  executing->Wait.queue          = &the_semaphore->Wait_queue;
76
  executing->Wait.id             = id;
77
  _ISR_Enable( level );
78
 
79
  _Thread_queue_Enqueue( &the_semaphore->Wait_queue, timeout );
80
}

powered by: WebSVN 2.1.0

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