From owner-p4-projects@FreeBSD.ORG Sun Jan 16 00:56:52 2005 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 2E9FC16A4D0; Sun, 16 Jan 2005 00:56:52 +0000 (GMT) Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 030CE16A4CE for ; Sun, 16 Jan 2005 00:56:52 +0000 (GMT) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id E287643D41 for ; Sun, 16 Jan 2005 00:56:51 +0000 (GMT) (envelope-from davidxu@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.1/8.13.1) with ESMTP id j0G0upUE014498 for ; Sun, 16 Jan 2005 00:56:51 GMT (envelope-from davidxu@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.1/8.13.1/Submit) id j0G0upZc014495 for perforce@freebsd.org; Sun, 16 Jan 2005 00:56:51 GMT (envelope-from davidxu@freebsd.org) Date: Sun, 16 Jan 2005 00:56:51 GMT Message-Id: <200501160056.j0G0upZc014495@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to davidxu@freebsd.org using -f From: David Xu To: Perforce Change Reviews Subject: PERFORCE change 69095 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 16 Jan 2005 00:56:52 -0000 http://perforce.freebsd.org/chv.cgi?CH=69095 Change 69095 by davidxu@davidxu_tiger on 2005/01/16 00:56:47 Make pthread_cancel async cancellation safe. Affected files ... .. //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_cancel.c#7 edit Differences ... ==== //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_cancel.c#7 (text+ko) ==== @@ -35,15 +35,25 @@ __weak_reference(_pthread_setcanceltype, pthread_setcanceltype); __weak_reference(_pthread_testcancel, pthread_testcancel); +int _pthread_setcanceltype(int type, int *oldtype); + int _pthread_cancel(pthread_t pthread) { struct pthread *curthread = _get_curthread(); int oldval, newval = 0; + int oldtype; int ret; - if ((ret = _thr_ref_add(curthread, pthread, 0)) != 0) + /* + * POSIX says _pthread_cancel should be async cancellation safe, + * so we temporarily disable async cancellation. + */ + _pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldtype); + if ((ret = _thr_ref_add(curthread, pthread, 0)) != 0) { + _pthread_setcanceltype(oldtype, NULL); return (ret); + } do { oldval = pthread->cancelflags; @@ -56,6 +66,7 @@ thr_kill(pthread->tid, SIGCANCEL); _thr_ref_delete(curthread, pthread); + _pthread_setcanceltype(oldtype, NULL); return (0); }