1 /*********************************************************************** 2 * * 3 * This software is part of the ast package * 4 * Copyright (c) 1985-2013 AT&T Intellectual Property * 5 * and is licensed under the * 6 * Eclipse Public License, Version 1.0 * 7 * by AT&T Intellectual Property * 8 * * 9 * A copy of the License is available at * 10 * http://www.eclipse.org/org/documents/epl-v10.html * 11 * (with md5 checksum b35adb5213ca9657e911e9befb180842) * 12 * * 13 * Information and Software Systems Research * 14 * AT&T Research * 15 * Florham Park NJ * 16 * * 17 * Glenn Fowler <glenn.s.fowler@gmail.com> * 18 * David Korn <dgkorn@gmail.com> * 19 * Phong Vo <phongvo@gmail.com> * 20 * * 21 ***********************************************************************/ 22 #include "config_ast.h" // IWYU pragma: keep 23 24 #include <pthread.h> 25 26 #include "ast_aso.h" 27 #include "cdt.h" 28 #include "cdtlib.h" 29 30 /* Perform various functions on the user's behalf. 31 ** 32 ** Written by Kiem-Phong Vo, phongvo@gmail.com (01/05/2012) 33 */ 34 35 // Lock dt->data->user.lock. dtuserlock(Dt_t * dt)36int dtuserlock(Dt_t *dt) { return pthread_mutex_lock(&dt->data->user.lock); } 37 38 // Unlock dt->data->user.lock. dtuserunlock(Dt_t * dt)39int dtuserunlock(Dt_t *dt) { return pthread_mutex_unlock(&dt->data->user.lock); } 40 41 /* managing the user data slot dt->data->user.data */ dtuserdata(Dt_t * dt,void * data,int set)42void *dtuserdata(Dt_t *dt, void *data, int set) { 43 if (set == 0) return asogetptr(&dt->data->user.data); // just return current value 44 while (1) { 45 void *current = dt->data->user.data; 46 if (asocasptr(&dt->data->user.data, current, data) == current) return current; 47 } 48 } 49