Changeset f807b84 in rtems


Ignore:
Timestamp:
Jun 1, 2016, 9:04:50 AM (3 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
c6556e2
Parents:
a9cc6a84
git-author:
Sebastian Huber <sebastian.huber@…> (06/01/16 09:04:50)
git-committer:
Sebastian Huber <sebastian.huber@…> (06/01/16 09:13:47)
Message:

score: Fix _Thread_Lock_acquire()

A read-modify-write operation is necessary to read the last value
written.

See for example C11 standard or Power ISA 2.07, Book II: Power ISA
Virtual Environment Architecture, Section 1.6.3 Memory Coherence
Required [Category: Memory Coherence] and Section 1.7.3 Atomic Update.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpukit/score/include/rtems/score/threadimpl.h

    ra9cc6a84 rf807b84  
    11291129
    11301130  while ( true ) {
    1131     unsigned int first_generation;
    1132     unsigned int second_generation;
     1131    unsigned int my_generation;
     1132    bool         success;
    11331133
    11341134    _ISR_lock_ISR_disable( lock_context );
    11351135
    11361136    /*
    1137      * Ensure that we read our first lock generation before we obtain our
     1137     * Ensure that we read our lock generation before we obtain our
    11381138     * current lock.  See _Thread_Lock_set_unprotected().
    11391139     */
    1140     first_generation = _Atomic_Load_uint(
     1140    my_generation = _Atomic_Load_uint(
    11411141      &the_thread->Lock.generation,
    11421142      ATOMIC_ORDER_ACQUIRE
     
    11511151
    11521152    /*
    1153      * The C11 memory model doesn't guarantee that we read the latest
    1154      * generation here.  For this a read-modify-write operation would be
    1155      * necessary.  We read at least the new generation set up by the owner of
    1156      * our current thread lock, and so on.
     1153     * We must use a read-modify-write operation to observe the last value
     1154     * written.
    11571155     */
    1158     second_generation = _Atomic_Load_uint(
     1156    success = _Atomic_Compare_exchange_uint(
    11591157      &the_thread->Lock.generation,
    1160       ATOMIC_ORDER_ACQUIRE
     1158      &my_generation,
     1159      my_generation,
     1160      ATOMIC_ORDER_RELAXED,
     1161      ATOMIC_ORDER_RELAXED
    11611162    );
    11621163
    1163     if ( first_generation == second_generation ) {
     1164    if ( success ) {
    11641165      return lock;
    11651166    }
Note: See TracChangeset for help on using the changeset viewer.