File: a_livepatch1.cpp

package info (click to toggle)
libpulp 0.3.16-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,976 kB
  • sloc: ansic: 11,792; python: 1,216; sh: 881; makefile: 871; cpp: 582; asm: 387
file content (28 lines) | stat: -rw-r--r-- 623 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <pthread.h>
#include <stdlib.h>
#include <stdbool.h>
#include <assert.h>
#include <stdio.h>

/* Pointer to the original sum variable.  This will be initialized with the
   address of `sum` when the patch is loaded in the program, as described in
   the .dsc file.  */
volatile long *sum_ptr = NULL;

/* Pointer to the original lock.  */
pthread_mutex_t *sum_lock_ptr = NULL;

void accumulate_2(long x __attribute__((unused)))
{
  assert(sum_ptr && sum_lock_ptr);

  if (pthread_mutex_lock(sum_lock_ptr) != 0) {
    abort();
  }

  *sum_ptr = 0;

  if (pthread_mutex_unlock(sum_lock_ptr) != 0) {
    abort();
  }
}