3.1-rc3 (revision d9ca08bb)
OTF2_OpenMP_Locks.h
Go to the documentation of this file.
1 /*
2  * This file is part of the Score-P software (http://www.score-p.org)
3  *
4  * Copyright (c) 2014,
5  * Technische Universitaet Dresden, Germany
6  *
7  * This software may be modified and distributed under the terms of
8  * a BSD-style license. See the COPYING file in the package base
9  * directory for details.
10  *
11  */
12 
13 
14 
23 #ifndef OTF2_OPENMP_LOCKS_H
24 #define OTF2_OPENMP_LOCKS_H
25 
26 
27 #include <stdlib.h>
28 
29 
30 #include <otf2/otf2.h>
31 
32 
33 #include <omp.h>
34 
35 
44 static OTF2_ErrorCode
46 
47 
56 static OTF2_ErrorCode
58 
59 
67 struct OTF2_LockObject
68 {
69  omp_lock_t lock;
70 };
71 
72 
73 static OTF2_CallbackCode
74 otf2_openmp_lock_create( void* userData,
75  OTF2_Lock* lock )
76 {
77  if ( !lock )
78  {
79  return OTF2_CALLBACK_ERROR;
80  }
81 
82  *lock = ( OTF2_Lock )malloc( sizeof( **lock ) );
83  if ( !*lock )
84  {
85  return OTF2_CALLBACK_ERROR;
86  }
87 
88  omp_init_lock( &( *lock )->lock );
89 
90  return OTF2_CALLBACK_SUCCESS;
91 }
92 
93 
94 static OTF2_CallbackCode
95 otf2_openmp_lock_destroy( void* userData,
96  OTF2_Lock lock )
97 {
98  if ( !lock )
99  {
100  return OTF2_CALLBACK_ERROR;
101  }
102 
103  omp_destroy_lock( &lock->lock );
104 
105  return OTF2_CALLBACK_SUCCESS;
106 }
107 
108 
109 static OTF2_CallbackCode
110 otf2_openmp_lock_lock( void* userData,
111  OTF2_Lock lock )
112 {
113  if ( !lock )
114  {
115  return OTF2_CALLBACK_ERROR;
116  }
117 
118  omp_set_lock( &lock->lock );
119 
120  return OTF2_CALLBACK_SUCCESS;
121 }
122 
123 
124 static OTF2_CallbackCode
125 otf2_openmp_lock_unlock( void* userData,
126  OTF2_Lock lock )
127 {
128  if ( !lock )
129  {
130  return OTF2_CALLBACK_ERROR;
131  }
132 
133  omp_unset_lock( &lock->lock );
134 
135  return OTF2_CALLBACK_SUCCESS;
136 }
137 
138 
139 static const OTF2_LockingCallbacks otf2_openmp_locking_callbacks =
140 {
141  NULL,
142  otf2_openmp_lock_create,
143  otf2_openmp_lock_destroy,
144  otf2_openmp_lock_lock,
145  otf2_openmp_lock_unlock
146 };
147 
148 
149 static OTF2_ErrorCode
151 {
153 
154  if ( !archive )
155  {
157  }
158 
159  return OTF2_Archive_SetLockingCallbacks( archive,
160  &otf2_openmp_locking_callbacks,
161  NULL );
162 }
163 
164 
165 static OTF2_ErrorCode
167 {
169 
170  if ( !reader )
171  {
173  }
174 
175  return OTF2_Reader_SetLockingCallbacks( reader,
176  &otf2_openmp_locking_callbacks,
177  NULL );
178 }
179 
180 
186 #endif /* OTF2_OPENMP_LOCKS_H */
static OTF2_ErrorCode OTF2_OpenMP_Reader_SetLockingCallbacks(OTF2_Reader *reader)
Register callbacks to use OpenMP locks for an OTF2 reader.
Record reading can continue.
Definition: OTF2_GeneralDefinitions.h:352
OTF2_ErrorCode OTF2_Archive_SetLockingCallbacks(OTF2_Archive *archive, const OTF2_LockingCallbacks *lockingCallbacks, void *lockingData)
Set the locking callbacks for the archive.
Main include file for applications using OTF2.
Definition: OTF2_ErrorCodes.h:230
OTF2_ErrorCode
Definition: OTF2_ErrorCodes.h:53
OTF2_CallbackCode
Return value to indicate that the record reading should be interrupted.
Definition: OTF2_GeneralDefinitions.h:349
struct OTF2_LockObject * OTF2_Lock
Opaque type for a locking object.
Definition: OTF2_Callbacks.h:552
Signaling an error in the callback.
Definition: OTF2_GeneralDefinitions.h:363
struct OTF2_Archive_struct OTF2_Archive
Keeps all meta-data for an OTF2 archive.
Definition: OTF2_Archive.h:220
struct OTF2_Reader_struct OTF2_Reader
Keeps all necessary information for the reader.
Definition: OTF2_Reader.h:193
Struct which holds all locking callbacks.
Definition: OTF2_Callbacks.h:643
static OTF2_ErrorCode OTF2_OpenMP_Archive_SetLockingCallbacks(OTF2_Archive *archive)
Register callbacks to use OpenMP locks for an OTF2 archive.
OTF2_ErrorCode OTF2_Reader_SetLockingCallbacks(OTF2_Reader *reader, const OTF2_LockingCallbacks *lockingCallbacks, void *lockingData)
Set the locking callbacks for the reader.