123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- /*
- * Copyright Institute of Communication and Computer Systems (ICCS)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
- /**
- * @file locks.h
- * @author Ioannis Koutras (joko@microlab.ntua.gr)
- * @date September 2012
- * @brief Locking functions
- */
- #include <dmmlib/config.h>
- #ifndef LOCKS_H
- #define LOCKS_H
- #ifdef HAVE_LOCKS
- /** Enumeration of lock states */
- typedef enum locktype_en {STATE_LOCKED, STATE_UNLOCKED} locktype_t;
- /** Initializes a locktype_t variable */
- #define INIT_DEALY_LOCK(lock) lock = STATE_UNLOCKED
- /** Locks a locktype_t variable */
- #define DEALY_LOCK(lock) \
- while(__sync_bool_compare_and_swap(&lock, \
- STATE_UNLOCKED, STATE_LOCKED) != STATE_UNLOCKED){}
- /** Tries to lock a locktype_t variable */
- #define DEALY_TRYLOCK(lock) \
- ((__sync_bool_compare_and_swap(&lock, STATE_UNLOCKED, STATE_LOCKED) != \
- STATE_UNLOCKED))
- /** Unlocks a locktype_t variable */
- #define DEALY_UNLOCK(lock) lock = STATE_UNLOCKED
- /** Destroys a locktype_t */
- #define DEALY_DESTROY_LOCK(lock) lock = STATE_UNLOCKED
- #else /* HAVE_LOCKS */
- /** Does nothing. */
- #define INIT_DEALY_LOCK()
- /** Does nothing. */
- #define DEALY_LOCK()
- /** Does nothing. */
- #define DEALY_TRYLOCK(lock)
- /** Does nothing. */
- #define DEALY_UNLOCK(lock)
- /** Does nothing. */
- #define DEALY_DESTROY_LOCK(lock)
- #endif /* HAVE_LOCKS */
- #endif /* LOCKS_H */
|