source: trunk/kernel/libk/barrier.c @ 156

Last change on this file since 156 was 16, checked in by alain, 7 years ago

mprove the HAL for interrupt, exception, syscall handling.

File size: 1.6 KB
RevLine 
[14]1/*
2 * barrier.c - kernel barrier implementaion
3 *
4 * Author   Alain Greiner (2016)
5 *
6 * Copyright (c) UPMC Sorbonne Universites
7 *
8 * This file is part of ALMOS-MKH.
9 *
10 * ALMOS-MKH is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; version 2.0 of the License.
13 *
14 * ALMOS-MKH is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with ALMOS-MKH; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24#include <hal_types.h>
25#include <hal_remote.h>
[16]26#include <hal_atomic.h>
[14]27#include <barrier.h>
28
29//////////////////////////////////////////////
30inline void barrier_wait( barrier_t * barrier,
31                          uint32_t    count ) 
32{
33    uint32_t  expected;
34
35    // get barrier sense value
36    uint32_t sense = barrier->sense;
37
38        // compute expected value
39    if ( sense == 0 ) expected = 1;
40    else              expected = 0;
41
42    // atomically increment current
43    uint32_t current = hal_atomic_add( &barrier->current , 1 );
44
45    // last task reset current and toggle sense
46    if( current == (count-1) ) 
47    {
48        barrier->current = 0; 
49        barrier->sense   = expected; 
50    }
51    else   // other tasks poll sense
52    {
53        while( barrier->sense != expected ) asm volatile ("nop");
54    }
55}
56
57
Note: See TracBrowser for help on using the repository browser.