Subversion Repositories HelenOS

Rev

Rev 2726 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2726 Rev 3478
1
/*++
1
/*++
2
 
2
 
3
Copyright (c) 1998  Intel Corporation
3
Copyright (c) 1998  Intel Corporation
4
 
4
 
5
Module Name:
5
Module Name:
6
 
6
 
7
    lock.c
7
    lock.c
8
 
8
 
9
Abstract:
9
Abstract:
10
 
10
 
11
    Implements FLOCK
11
    Implements FLOCK
12
 
12
 
13
 
13
 
14
 
14
 
15
Revision History
15
Revision History
16
 
16
 
17
--*/
17
--*/
18
 
18
 
19
 
19
 
20
#include "lib.h"
20
#include "lib.h"
21
 
21
 
22
 
22
 
23
 
23
 
24
#pragma RUNTIME_CODE(RtAcquireLock)
24
#pragma RUNTIME_CODE(RtAcquireLock)
25
VOID
25
VOID
26
RtAcquireLock (
26
RtAcquireLock (
27
    IN FLOCK    *Lock
27
    IN FLOCK    *Lock
28
    )
28
    )
29
/*++
29
/*++
30
 
30
 
31
Routine Description:
31
Routine Description:
32
 
32
 
33
    Raising to the task priority level of the mutual exclusion
33
    Raising to the task priority level of the mutual exclusion
34
    lock, and then acquires ownership of the lock.
34
    lock, and then acquires ownership of the lock.
35
   
35
   
36
Arguments:
36
Arguments:
37
 
37
 
38
    Lock        - The lock to acquire
38
    Lock        - The lock to acquire
39
   
39
   
40
Returns:
40
Returns:
41
 
41
 
42
    Lock owned
42
    Lock owned
43
 
43
 
44
--*/
44
--*/
45
{
45
{
46
    if (BS) {
46
    if (BS) {
47
        if (BS->RaiseTPL != NULL) {
47
        if (BS->RaiseTPL != NULL) {
48
            Lock->OwnerTpl = BS->RaiseTPL(Lock->Tpl);
48
            Lock->OwnerTpl = BS->RaiseTPL(Lock->Tpl);
49
        }
49
        }
50
    }
50
    }
51
    else {
51
    else {
52
        if (LibRuntimeRaiseTPL != NULL) {
52
        if (LibRuntimeRaiseTPL != NULL) {
53
            Lock->OwnerTpl = LibRuntimeRaiseTPL(Lock->Tpl);
53
            Lock->OwnerTpl = LibRuntimeRaiseTPL(Lock->Tpl);
54
        }
54
        }
55
    }
55
    }
56
    Lock->Lock += 1;
56
    Lock->Lock += 1;
57
    ASSERT (Lock->Lock == 1);
57
    ASSERT (Lock->Lock == 1);
58
}
58
}
59
 
59
 
60
 
60
 
61
#pragma RUNTIME_CODE(RtAcquireLock)
61
#pragma RUNTIME_CODE(RtAcquireLock)
62
VOID
62
VOID
63
RtReleaseLock (
63
RtReleaseLock (
64
    IN FLOCK    *Lock
64
    IN FLOCK    *Lock
65
    )
65
    )
66
/*++
66
/*++
67
 
67
 
68
Routine Description:
68
Routine Description:
69
 
69
 
70
    Releases ownership of the mutual exclusion lock, and
70
    Releases ownership of the mutual exclusion lock, and
71
    restores the previous task priority level.
71
    restores the previous task priority level.
72
   
72
   
73
Arguments:
73
Arguments:
74
 
74
 
75
    Lock        - The lock to release
75
    Lock        - The lock to release
76
   
76
   
77
Returns:
77
Returns:
78
 
78
 
79
    Lock unowned
79
    Lock unowned
80
 
80
 
81
--*/
81
--*/
82
{
82
{
83
    EFI_TPL     Tpl;
83
    EFI_TPL     Tpl;
84
 
84
 
85
    Tpl = Lock->OwnerTpl;
85
    Tpl = Lock->OwnerTpl;
86
    ASSERT(Lock->Lock == 1);
86
    ASSERT(Lock->Lock == 1);
87
    Lock->Lock -= 1;
87
    Lock->Lock -= 1;
88
    if (BS) {
88
    if (BS) {
89
        if (BS->RestoreTPL != NULL) {
89
        if (BS->RestoreTPL != NULL) {
90
            BS->RestoreTPL (Tpl);
90
            BS->RestoreTPL (Tpl);
91
        }
91
        }
92
    }
92
    }
93
    else {
93
    else {
94
        if (LibRuntimeRestoreTPL != NULL) {
94
        if (LibRuntimeRestoreTPL != NULL) {
95
            LibRuntimeRestoreTPL(Tpl);
95
            LibRuntimeRestoreTPL(Tpl);
96
        }
96
        }
97
    }
97
    }
98
}
98
}
99
 
99