3.0-rc2 (revision 337012f1)
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 <otf2/otf2.h>
28 
29 
30 #include <omp.h>
31 
32 
41 static OTF2_ErrorCode
43 
44 
53 static OTF2_ErrorCode
55 
56 
64 struct OTF2_LockObject
65 {
66  omp_lock_t lock;
67 };
68 
69 
70 static OTF2_CallbackCode
71 otf2_openmp_lock_create( void* userData,
72  OTF2_Lock* lock )
73 {
74  if ( !lock )
75  {
76  return OTF2_CALLBACK_ERROR;
77  }
78 
79  *lock = ( OTF2_Lock )malloc( sizeof( **lock ) );
80  if ( !*lock )
81  {
82  return OTF2_CALLBACK_ERROR;
83  }
84 
85  omp_init_lock( &( *lock )->lock );
86 
87  return OTF2_CALLBACK_SUCCESS;
88 }
89 
90 
91 static OTF2_CallbackCode
92 otf2_openmp_lock_destroy( void* userData,
93  OTF2_Lock lock )
94 {
95  if ( !lock )
96  {
97  return OTF2_CALLBACK_ERROR;
98  }
99 
100  omp_destroy_lock( &lock->lock );
101 
102  return OTF2_CALLBACK_SUCCESS;
103 }
104 
105 
106 static OTF2_CallbackCode
107 otf2_openmp_lock_lock( void* userData,
108  OTF2_Lock lock )
109 {
110  if ( !lock )
111  {
112  return OTF2_CALLBACK_ERROR;
113  }
114 
115  omp_set_lock( &lock->lock );
116 
117  return OTF2_CALLBACK_SUCCESS;
118 }
119 
120 
121 static OTF2_CallbackCode
122 otf2_openmp_lock_unlock( void* userData,
123  OTF2_Lock lock )
124 {
125  if ( !lock )
126  {
127  return OTF2_CALLBACK_ERROR;
128  }
129 
130  omp_unset_lock( &lock->lock );
131 
132  return OTF2_CALLBACK_SUCCESS;
133 }
134 
135 
136 static const OTF2_LockingCallbacks otf2_openmp_locking_callbacks =
137 {
138  NULL,
139  otf2_openmp_lock_create,
140  otf2_openmp_lock_destroy,
141  otf2_openmp_lock_lock,
142  otf2_openmp_lock_unlock
143 };
144 
145 
146 static OTF2_ErrorCode
148 {
150 
151  if ( !archive )
152  {
154  }
155 
156  return OTF2_Archive_SetLockingCallbacks( archive,
157  &otf2_openmp_locking_callbacks,
158  NULL );
159 }
160 
161 
162 static OTF2_ErrorCode
164 {
166 
167  if ( !reader )
168  {
170  }
171 
172  return OTF2_Reader_SetLockingCallbacks( reader,
173  &otf2_openmp_locking_callbacks,
174  NULL );
175 }
176 
177 
183 #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:231
OTF2_ErrorCode
Definition: OTF2_ErrorCodes.h:54
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.