Lines Matching full:lock
2 * kmp_lock.h -- lock header file
49 // intel archs. It allocates at least 8 bytes for nested lock (more on
67 // lock flags
72 // When a lock table is used, the indices are of kmp_lock_index_t
75 // When memory allocated for locks are on the lock pool (free list),
87 // There are 5 lock implementations:
95 // and 3 lock purposes:
104 // Lock implementations.
108 // Non-nested test and set locks differ from the other lock kinds (except
109 // futex) in that we use the memory allocated by the compiler for the lock,
113 // bytes, so we have to use a lock table for nested locks, and avoid accessing
116 // Information normally available to the tools, such as lock location, lock
117 // usage (normal lock vs. critical section), etc. is not available with test and
145 // Static initializer for test and set lock variables. Usage:
147 #define KMP_TAS_LOCK_INITIALIZER(lock) \
178 // Like non-nested test and set lock, non-nested futex locks use the memory
179 // allocated by the compiler for the lock, rather than a pointer to it.
181 // Information normally available to the tools, such as lock location, lock
182 // usage (normal lock vs. critical section), etc. is not available with test and
183 // set locks. With non-nested futex locks, the lock owner is not even available.
204 // Static initializer for futex lock variables. Usage:
206 #define KMP_FUTEX_LOCK_INITIALIZER(lock) \
237 // `initialized' must be the first entry in the lock data structure!
239 volatile union kmp_ticket_lock *self; // points to the lock union
243 std::atomic_uint now_serving; // ticket number for thread which holds the lock
246 kmp_lock_flags_t flags; // lock specifics, e.g. critical section lock
250 // `initialized' must be the first entry in the lock data structure!
252 volatile union kmp_ticket_lock *self; // points to the lock union
257 now_serving; // ticket number for thread which holds the lock
260 kmp_lock_flags_t flags; // lock specifics, e.g. critical section lock
282 // Static initializer for simple ticket lock variables. Usage:
285 #define KMP_TICKET_LOCK_INITIALIZER(lock) \
287 { true, &(lock), NULL, 0U, 0U, 0, -1 } \
343 just affects our decision about whether to try speculation on the lock). */
346 /* Parameters of the lock. */
359 // `initialized' must be the first entry in the lock data structure!
361 *initialized; // Points to the lock union if in initialized state.
373 // bakery-style lock
377 now_serving; // ticket number for thread which holds the lock
381 kmp_lock_flags_t flags; // lock specifics, e.g. critical section lock
421 adaptive; // Information for the speculative adaptive lock
442 // initializing or reconfiguring the lock. These are relatively rare
444 // the cache of each thread trying to acquire the lock.
446 // initialized must be the first entry in the lock data structure!
450 *initialized; // points to the lock union if in initialized state
464 // now_serving is used to store our ticket value while we hold the lock. It
471 // as it is invalidated at every lock acquire.
474 // only written by the thread owning the lock, so they are put in this cache
480 kmp_lock_flags_t flags; // lock specifics, e.g. critical section lock
510 // Lock purposes.
517 // They could also be implemented as test and set lock, but cannot be
518 // implemented with other lock kinds as they require gtids which are not
523 #define KMP_BOOTSTRAP_LOCK_INITIALIZER(lock) KMP_TICKET_LOCK_INITIALIZER((lock))
524 #define KMP_BOOTSTRAP_LOCK_INIT(lock) \
525 kmp_bootstrap_lock_t lock = KMP_TICKET_LOCK_INITIALIZER(lock)
551 // FIXME - We should go through and figure out which lock kind works best for
552 // each internal lock, and use the type declaration and function calls for
553 // that explicit lock kind (and get rid of this section).
557 #define KMP_LOCK_INIT(lock) kmp_lock_t lock = KMP_TICKET_LOCK_INITIALIZER(lock)
731 // We need a non-checking version of destroy lock for when the RTL is
732 // doing the cleanup as it can't always tell if the lock is nested or not.
862 // user lock functions which do not necessarily exist for all lock kinds.
914 // Macros for binding user lock functions.
929 #define KMP_BIND_USER_LOCK(kind) KMP_BIND_USER_LOCK_TEMPLATE(_, kind, lock)
933 KMP_BIND_USER_LOCK_TEMPLATE(_nested_, kind, lock)
937 // User lock table & lock allocation
939 for lock variable, which is not enough to store a pointer, so we have to use
940 lock indexes instead of pointers and maintain lock table to map indexes to
944 Note: The first element of the table is not a pointer to lock! It is a
949 if ( OMP_LOCK_T_SIZE < sizeof( <lock> ) ) { // or OMP_NEST_LOCK_T_SIZE
950 Lock table is fully utilized. User locks are indexes, so table is used on
951 user lock operation.
952 Note: it may be the case (lin_32) that we don't need to use a lock
956 Lock table initialized but not actually used.
963 kmp_user_lock_p *table; // Lock table.
1007 // KMP_USE_DYNAMIC_LOCK enables dynamic dispatch of lock functions without
1010 // hinted user lock and critical section which will be part of OMP 4.5 soon.
1012 // Lock type can be decided at creation time (i.e., lock initialization), and
1013 // subsequent lock function call on the created lock object requires type
1015 // information is stored in two different ways depending on the size of the lock
1016 // object, and we differentiate lock types by this size requirement - direct and
1020 // A direct lock object fits into the space created by the compiler for an
1021 // omp_lock_t object, and TAS/Futex lock falls into this category. We use low
1022 // one byte of the lock object as the storage for the lock type, and appropriate
1023 // bit operation is required to access the data meaningful to the lock
1024 // algorithms. Also, to differentiate direct lock from indirect lock, 1 is
1025 // written to LSB of the lock object. The newly introduced "hle" lock is also a
1026 // direct lock.
1029 // An indirect lock object requires more space than the compiler-generated
1031 // compiler-generated space for the lock (i.e., size of omp_lock_t), this
1033 // lock (void * fits in the object) or an index to the indirect lock table entry
1034 // that holds the address. Ticket/Queuing/DRDPA/Adaptive lock falls into this
1035 // category, and the newly introduced "rtm" lock is also an indirect lock which
1036 // was implemented on top of the Queuing lock. When the omp_lock_t object holds
1037 // an index (not lock address), 0 is written to LSB to differentiate the lock
1038 // from a direct lock, and the remaining part is the actual index to the
1039 // indirect lock table.
1048 // List of lock definitions; all nested locks are indirect locks.
1049 // hle lock is xchg lock prefixed with XACQUIRE/XRELEASE.
1050 // All nested locks are indirect lock types.
1089 (locktag_nested_drdpa + 1) // number of indirect lock types
1094 // Lock sequence that enumerates all lock kinds. Always make this enumeration
1103 // Enumerates indirect lock tags.
1110 // Utility macros that extract information from lock sequences.
1118 // Enumerates direct lock tags starting from indirect tag.
1125 // Indirect lock type
1127 kmp_user_lock_p lock;
1147 // Extracts direct lock tag from a user lock pointer
1153 // Extracts indirect lock index from a user lock pointer
1157 // Returns function pointer to the direct lock function with l (kmp_dyna_lock_t
1161 // Returns function pointer to the indirect lock function with l
1166 // Initializes a direct lock with the given lock pointer and lock sequence.
1170 // Initializes an indirect lock with the given lock pointer and lock sequence.
1174 // Returns "free" lock value for the given lock type.
1177 // Returns "busy" lock value for the given lock teyp.
1180 // Returns lock value after removing (shifting) lock tag.
1187 // Allocates and returns an indirect lock with the given indirect lock tag.
1194 // Default user lock sequence when not using hinted locks.
1197 // Jump table for "set lock location", available only for indirect locks.
1203 __kmp_indirect_set_location[(lck)->type]((lck)->lock, loc); \
1206 // Jump table for "set lock flags", available only for indirect locks.
1212 __kmp_indirect_set_flags[(lck)->type]((lck)->lock, flag); \
1215 // Jump table for "get lock location", available only for indirect locks.
1220 ? __kmp_indirect_get_location[(lck)->type]((lck)->lock) \
1223 // Jump table for "get lock flags", available only for indirect locks.
1228 ? __kmp_indirect_get_flags[(lck)->type]((lck)->lock) \
1235 // number of row entries in the initial lock table
1238 // Lock table for indirect locks.
1242 kmp_lock_index_t next; // index to the next lock to be allocated
1248 // Returns the indirect lock associated with the given index.
1249 // Returns nullptr if no lock at given index
1267 // Number of locks in a lock block, which is fixed to "1" now.
1268 // TODO: No lock block implementation now. If we do support, we need to manage
1269 // lock block data structure for each indirect lock type.
1272 // Fast lock table lookup without consistency checking