lock-impl.c

来自「kaffe是一个java虚拟机的源代码。里面包含了一些java例程和标准的jav」· C语言 代码 · 共 55 行

C
55
字号
/* * lock-impl.c - pthread-based LockInterface implementation (Posix style) * * Copyright (c) 1998 *      Transvirtual Technologies, Inc.  All rights reserved. * * See the file "license.terms" for information on usage and redistribution * of this file. */#include <pthread.h>#include "config.h"#include "config-std.h"#include "gtypes.h"#include "thread.h"#include "lock-impl.h"/* * Wait on the condvar with a given relative timeout in ms (which we * have to convert into a absolute timespec now) */jbooleanjcondvar_wait ( jcondvar* cv, jmutex *mux, jlong timeout ){  nativeThread    *cur = GET_CURRENT_THREAD(&cur);  int             stat;  struct timespec abst;  struct timeval  now;  //CHECK_LOCK( cur,lk);  cur->stackCur  = (void*)&cur;  if ( timeout == 0 ) {	/* we handle this as "wait forever"	*/	cur->blockState |= BS_CV;	stat = pthread_cond_wait( cv, mux );	cur->blockState &= ~BS_CV;  }  else {	/* timeout is in millisecs, timeval in microsecs, and timespec in nanosecs */	gettimeofday( &now, 0);	abst.tv_sec = now.tv_sec + (timeout / 1000);	abst.tv_nsec = (now.tv_usec * 1000) + (timeout % 1000) * 1000000; 	cur->blockState |= BS_CV_TO;	stat = pthread_cond_timedwait( cv, mux, &abst);	cur->blockState &= ~BS_CV_TO;  }    return (stat == 0);}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?