pthread_cond_timedwait.S 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803
  1. /* Copyright (C) 2002-2005, 2007, 2009 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, write to the Free
  14. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA. */
  16. #include <sysdep.h>
  17. #include <lowlevellock.h>
  18. #include <lowlevelcond.h>
  19. #include <pthread-pi-defines.h>
  20. #include <pthread-errnos.h>
  21. #include <bits/kernel-features.h>
  22. /* For the calculation see asm/vsyscall.h. */
  23. #define VSYSCALL_ADDR_vgettimeofday 0xffffffffff600000
  24. .text
  25. /* int pthread_cond_timedwait (pthread_cond_t *cond, pthread_mutex_t *mutex,
  26. const struct timespec *abstime) */
  27. .globl __pthread_cond_timedwait
  28. .type __pthread_cond_timedwait, @function
  29. .align 16
  30. __pthread_cond_timedwait:
  31. .LSTARTCODE:
  32. cfi_startproc
  33. pushq %r12
  34. cfi_adjust_cfa_offset(8)
  35. cfi_rel_offset(%r12, 0)
  36. pushq %r13
  37. cfi_adjust_cfa_offset(8)
  38. cfi_rel_offset(%r13, 0)
  39. pushq %r14
  40. cfi_adjust_cfa_offset(8)
  41. cfi_rel_offset(%r14, 0)
  42. pushq %r15
  43. cfi_adjust_cfa_offset(8)
  44. cfi_rel_offset(%r15, 0)
  45. #ifdef __ASSUME_FUTEX_CLOCK_REALTIME
  46. # define FRAME_SIZE 32
  47. #else
  48. # define FRAME_SIZE 48
  49. #endif
  50. subq $FRAME_SIZE, %rsp
  51. cfi_adjust_cfa_offset(FRAME_SIZE)
  52. cfi_remember_state
  53. cmpq $1000000000, 8(%rdx)
  54. movl $EINVAL, %eax
  55. jae 48f
  56. /* Stack frame:
  57. rsp + 48
  58. +--------------------------+
  59. rsp + 32 | timeout value |
  60. +--------------------------+
  61. rsp + 24 | old wake_seq value |
  62. +--------------------------+
  63. rsp + 16 | mutex pointer |
  64. +--------------------------+
  65. rsp + 8 | condvar pointer |
  66. +--------------------------+
  67. rsp + 4 | old broadcast_seq value |
  68. +--------------------------+
  69. rsp + 0 | old cancellation mode |
  70. +--------------------------+
  71. */
  72. cmpq $-1, dep_mutex(%rdi)
  73. /* Prepare structure passed to cancellation handler. */
  74. movq %rdi, 8(%rsp)
  75. movq %rsi, 16(%rsp)
  76. movq %rdx, %r13
  77. je 22f
  78. movq %rsi, dep_mutex(%rdi)
  79. 22:
  80. #ifndef __ASSUME_FUTEX_CLOCK_REALTIME
  81. # ifdef PIC
  82. cmpl $0, __have_futex_clock_realtime(%rip)
  83. # else
  84. cmpl $0, __have_futex_clock_realtime
  85. # endif
  86. je .Lreltmo
  87. #endif
  88. /* Get internal lock. */
  89. movl $1, %esi
  90. xorl %eax, %eax
  91. LOCK
  92. #if cond_lock == 0
  93. cmpxchgl %esi, (%rdi)
  94. #else
  95. cmpxchgl %esi, cond_lock(%rdi)
  96. #endif
  97. jnz 31f
  98. /* Unlock the mutex. */
  99. 32: movq 16(%rsp), %rdi
  100. xorl %esi, %esi
  101. callq __pthread_mutex_unlock_usercnt
  102. testl %eax, %eax
  103. jne 46f
  104. movq 8(%rsp), %rdi
  105. incq total_seq(%rdi)
  106. incl cond_futex(%rdi)
  107. addl $(1 << nwaiters_shift), cond_nwaiters(%rdi)
  108. /* Get and store current wakeup_seq value. */
  109. movq 8(%rsp), %rdi
  110. movq wakeup_seq(%rdi), %r9
  111. movl broadcast_seq(%rdi), %edx
  112. movq %r9, 24(%rsp)
  113. movl %edx, 4(%rsp)
  114. 38: movl cond_futex(%rdi), %r12d
  115. /* Unlock. */
  116. LOCK
  117. #if cond_lock == 0
  118. decl (%rdi)
  119. #else
  120. decl cond_lock(%rdi)
  121. #endif
  122. jne 33f
  123. .LcleanupSTART1:
  124. 34: callq __pthread_enable_asynccancel
  125. movl %eax, (%rsp)
  126. movq %r13, %r10
  127. movl $FUTEX_WAIT_BITSET, %esi
  128. cmpq $-1, dep_mutex(%rdi)
  129. je 60f
  130. movq dep_mutex(%rdi), %r8
  131. /* Requeue to a non-robust PI mutex if the PI bit is set and
  132. the robust bit is not set. */
  133. movl MUTEX_KIND(%r8), %eax
  134. andl $(ROBUST_BIT|PI_BIT), %eax
  135. cmpl $PI_BIT, %eax
  136. jne 61f
  137. movl $(FUTEX_WAIT_REQUEUE_PI|FUTEX_PRIVATE_FLAG), %esi
  138. xorl %eax, %eax
  139. /* The following only works like this because we only support
  140. two clocks, represented using a single bit. */
  141. testl $1, cond_nwaiters(%rdi)
  142. movl $FUTEX_CLOCK_REALTIME, %edx
  143. cmove %edx, %eax
  144. orl %eax, %esi
  145. movq %r12, %rdx
  146. addq $cond_futex, %rdi
  147. movl $SYS_futex, %eax
  148. syscall
  149. movl $1, %r15d
  150. #ifdef __ASSUME_REQUEUE_PI
  151. jmp 62f
  152. #else
  153. cmpq $-4095, %rax
  154. jnae 62f
  155. subq $cond_futex, %rdi
  156. #endif
  157. 61: movl $(FUTEX_WAIT_BITSET|FUTEX_PRIVATE_FLAG), %esi
  158. 60: xorl %r15d, %r15d
  159. xorl %eax, %eax
  160. /* The following only works like this because we only support
  161. two clocks, represented using a single bit. */
  162. testl $1, cond_nwaiters(%rdi)
  163. movl $FUTEX_CLOCK_REALTIME, %edx
  164. movl $0xffffffff, %r9d
  165. cmove %edx, %eax
  166. orl %eax, %esi
  167. movq %r12, %rdx
  168. addq $cond_futex, %rdi
  169. movl $SYS_futex, %eax
  170. syscall
  171. 62: movq %rax, %r14
  172. movl (%rsp), %edi
  173. callq __pthread_disable_asynccancel
  174. .LcleanupEND1:
  175. /* Lock. */
  176. movq 8(%rsp), %rdi
  177. movl $1, %esi
  178. xorl %eax, %eax
  179. LOCK
  180. #if cond_lock == 0
  181. cmpxchgl %esi, (%rdi)
  182. #else
  183. cmpxchgl %esi, cond_lock(%rdi)
  184. #endif
  185. jne 35f
  186. 36: movl broadcast_seq(%rdi), %edx
  187. movq woken_seq(%rdi), %rax
  188. movq wakeup_seq(%rdi), %r9
  189. cmpl 4(%rsp), %edx
  190. jne 53f
  191. cmpq 24(%rsp), %r9
  192. jbe 45f
  193. cmpq %rax, %r9
  194. ja 39f
  195. 45: cmpq $-ETIMEDOUT, %r14
  196. jne 38b
  197. 99: incq wakeup_seq(%rdi)
  198. incl cond_futex(%rdi)
  199. movl $ETIMEDOUT, %r14d
  200. jmp 44f
  201. 53: xorq %r14, %r14
  202. jmp 54f
  203. 39: xorq %r14, %r14
  204. 44: incq woken_seq(%rdi)
  205. 54: subl $(1 << nwaiters_shift), cond_nwaiters(%rdi)
  206. /* Wake up a thread which wants to destroy the condvar object. */
  207. cmpq $0xffffffffffffffff, total_seq(%rdi)
  208. jne 55f
  209. movl cond_nwaiters(%rdi), %eax
  210. andl $~((1 << nwaiters_shift) - 1), %eax
  211. jne 55f
  212. addq $cond_nwaiters, %rdi
  213. cmpq $-1, dep_mutex-cond_nwaiters(%rdi)
  214. movl $1, %edx
  215. #ifdef __ASSUME_PRIVATE_FUTEX
  216. movl $FUTEX_WAKE, %eax
  217. movl $(FUTEX_WAKE|FUTEX_PRIVATE_FLAG), %esi
  218. cmove %eax, %esi
  219. #else
  220. movl $0, %eax
  221. movl %fs:PRIVATE_FUTEX, %esi
  222. cmove %eax, %esi
  223. orl $FUTEX_WAKE, %esi
  224. #endif
  225. movl $SYS_futex, %eax
  226. syscall
  227. subq $cond_nwaiters, %rdi
  228. 55: LOCK
  229. #if cond_lock == 0
  230. decl (%rdi)
  231. #else
  232. decl cond_lock(%rdi)
  233. #endif
  234. jne 40f
  235. /* If requeue_pi is used the kernel performs the locking of the
  236. mutex. */
  237. 41: movq 16(%rsp), %rdi
  238. testl %r15d, %r15d
  239. jnz 64f
  240. callq __pthread_mutex_cond_lock
  241. 63: testq %rax, %rax
  242. cmoveq %r14, %rax
  243. 48: addq $FRAME_SIZE, %rsp
  244. cfi_adjust_cfa_offset(-FRAME_SIZE)
  245. popq %r15
  246. cfi_adjust_cfa_offset(-8)
  247. cfi_restore(%r15)
  248. popq %r14
  249. cfi_adjust_cfa_offset(-8)
  250. cfi_restore(%r14)
  251. popq %r13
  252. cfi_adjust_cfa_offset(-8)
  253. cfi_restore(%r13)
  254. popq %r12
  255. cfi_adjust_cfa_offset(-8)
  256. cfi_restore(%r12)
  257. retq
  258. cfi_restore_state
  259. 64: callq __pthread_mutex_cond_lock_adjust
  260. movq %r14, %rax
  261. jmp 48b
  262. /* Initial locking failed. */
  263. 31:
  264. #if cond_lock != 0
  265. addq $cond_lock, %rdi
  266. #endif
  267. cmpq $-1, dep_mutex-cond_lock(%rdi)
  268. movl $LLL_PRIVATE, %eax
  269. movl $LLL_SHARED, %esi
  270. cmovne %eax, %esi
  271. callq __lll_lock_wait
  272. jmp 32b
  273. /* Unlock in loop requires wakeup. */
  274. 33:
  275. #if cond_lock != 0
  276. addq $cond_lock, %rdi
  277. #endif
  278. cmpq $-1, dep_mutex-cond_lock(%rdi)
  279. movl $LLL_PRIVATE, %eax
  280. movl $LLL_SHARED, %esi
  281. cmovne %eax, %esi
  282. callq __lll_unlock_wake
  283. jmp 34b
  284. /* Locking in loop failed. */
  285. 35:
  286. #if cond_lock != 0
  287. addq $cond_lock, %rdi
  288. #endif
  289. cmpq $-1, dep_mutex-cond_lock(%rdi)
  290. movl $LLL_PRIVATE, %eax
  291. movl $LLL_SHARED, %esi
  292. cmovne %eax, %esi
  293. callq __lll_lock_wait
  294. #if cond_lock != 0
  295. subq $cond_lock, %rdi
  296. #endif
  297. jmp 36b
  298. /* Unlock after loop requires wakeup. */
  299. 40:
  300. #if cond_lock != 0
  301. addq $cond_lock, %rdi
  302. #endif
  303. cmpq $-1, dep_mutex-cond_lock(%rdi)
  304. movl $LLL_PRIVATE, %eax
  305. movl $LLL_SHARED, %esi
  306. cmovne %eax, %esi
  307. callq __lll_unlock_wake
  308. jmp 41b
  309. /* The initial unlocking of the mutex failed. */
  310. 46: movq 8(%rsp), %rdi
  311. movq %rax, (%rsp)
  312. LOCK
  313. #if cond_lock == 0
  314. decl (%rdi)
  315. #else
  316. decl cond_lock(%rdi)
  317. #endif
  318. jne 47f
  319. #if cond_lock != 0
  320. addq $cond_lock, %rdi
  321. #endif
  322. cmpq $-1, dep_mutex-cond_lock(%rdi)
  323. movl $LLL_PRIVATE, %eax
  324. movl $LLL_SHARED, %esi
  325. cmovne %eax, %esi
  326. callq __lll_unlock_wake
  327. 47: movq (%rsp), %rax
  328. jmp 48b
  329. #ifndef __ASSUME_FUTEX_CLOCK_REALTIME
  330. .Lreltmo:
  331. xorl %r15d, %r15d
  332. /* Get internal lock. */
  333. movl $1, %esi
  334. xorl %eax, %eax
  335. LOCK
  336. # if cond_lock == 0
  337. cmpxchgl %esi, (%rdi)
  338. # else
  339. cmpxchgl %esi, cond_lock(%rdi)
  340. # endif
  341. jnz 1f
  342. /* Unlock the mutex. */
  343. 2: movq 16(%rsp), %rdi
  344. xorl %esi, %esi
  345. callq __pthread_mutex_unlock_usercnt
  346. testl %eax, %eax
  347. jne 46b
  348. movq 8(%rsp), %rdi
  349. incq total_seq(%rdi)
  350. incl cond_futex(%rdi)
  351. addl $(1 << nwaiters_shift), cond_nwaiters(%rdi)
  352. /* Get and store current wakeup_seq value. */
  353. movq 8(%rsp), %rdi
  354. movq wakeup_seq(%rdi), %r9
  355. movl broadcast_seq(%rdi), %edx
  356. movq %r9, 24(%rsp)
  357. movl %edx, 4(%rsp)
  358. /* Get the current time. */
  359. 8:
  360. # ifdef __NR_clock_gettime
  361. /* Get the clock number. Note that the field in the condvar
  362. structure stores the number minus 1. */
  363. movq 8(%rsp), %rdi
  364. movl cond_nwaiters(%rdi), %edi
  365. andl $((1 << nwaiters_shift) - 1), %edi
  366. /* Only clocks 0 and 1 are allowed so far. Both are handled in the
  367. kernel. */
  368. leaq 32(%rsp), %rsi
  369. # ifdef SHARED
  370. movq __vdso_clock_gettime@GOTPCREL(%rip), %rax
  371. movq (%rax), %rax
  372. PTR_DEMANGLE (%rax)
  373. jz 26f
  374. call *%rax
  375. jmp 27f
  376. # endif
  377. 26: movl $__NR_clock_gettime, %eax
  378. syscall
  379. 27:
  380. # ifndef __ASSUME_POSIX_TIMERS
  381. cmpq $-ENOSYS, %rax
  382. je 19f
  383. # endif
  384. /* Compute relative timeout. */
  385. movq (%r13), %rcx
  386. movq 8(%r13), %rdx
  387. subq 32(%rsp), %rcx
  388. subq 40(%rsp), %rdx
  389. # else
  390. leaq 24(%rsp), %rdi
  391. xorl %esi, %esi
  392. movq $VSYSCALL_ADDR_vgettimeofday, %rax
  393. callq *%rax
  394. /* Compute relative timeout. */
  395. movq 40(%rsp), %rax
  396. movl $1000, %edx
  397. mul %rdx /* Milli seconds to nano seconds. */
  398. movq (%r13), %rcx
  399. movq 8(%r13), %rdx
  400. subq 32(%rsp), %rcx
  401. subq %rax, %rdx
  402. # endif
  403. jns 12f
  404. addq $1000000000, %rdx
  405. decq %rcx
  406. 12: testq %rcx, %rcx
  407. movq 8(%rsp), %rdi
  408. movq $-ETIMEDOUT, %r14
  409. js 6f
  410. /* Store relative timeout. */
  411. 21: movq %rcx, 32(%rsp)
  412. movq %rdx, 40(%rsp)
  413. movl cond_futex(%rdi), %r12d
  414. /* Unlock. */
  415. LOCK
  416. # if cond_lock == 0
  417. decl (%rdi)
  418. # else
  419. decl cond_lock(%rdi)
  420. # endif
  421. jne 3f
  422. .LcleanupSTART2:
  423. 4: callq __pthread_enable_asynccancel
  424. movl %eax, (%rsp)
  425. leaq 32(%rsp), %r10
  426. cmpq $-1, dep_mutex(%rdi)
  427. movq %r12, %rdx
  428. # ifdef __ASSUME_PRIVATE_FUTEX
  429. movl $FUTEX_WAIT, %eax
  430. movl $(FUTEX_WAIT|FUTEX_PRIVATE_FLAG), %esi
  431. cmove %eax, %esi
  432. # else
  433. movl $0, %eax
  434. movl %fs:PRIVATE_FUTEX, %esi
  435. cmove %eax, %esi
  436. # if FUTEX_WAIT != 0
  437. orl $FUTEX_WAIT, %esi
  438. # endif
  439. # endif
  440. addq $cond_futex, %rdi
  441. movl $SYS_futex, %eax
  442. syscall
  443. movq %rax, %r14
  444. movl (%rsp), %edi
  445. callq __pthread_disable_asynccancel
  446. .LcleanupEND2:
  447. /* Lock. */
  448. movq 8(%rsp), %rdi
  449. movl $1, %esi
  450. xorl %eax, %eax
  451. LOCK
  452. # if cond_lock == 0
  453. cmpxchgl %esi, (%rdi)
  454. # else
  455. cmpxchgl %esi, cond_lock(%rdi)
  456. # endif
  457. jne 5f
  458. 6: movl broadcast_seq(%rdi), %edx
  459. movq woken_seq(%rdi), %rax
  460. movq wakeup_seq(%rdi), %r9
  461. cmpl 4(%rsp), %edx
  462. jne 53b
  463. cmpq 24(%rsp), %r9
  464. jbe 15f
  465. cmpq %rax, %r9
  466. ja 39b
  467. 15: cmpq $-ETIMEDOUT, %r14
  468. jne 8b
  469. jmp 99b
  470. /* Initial locking failed. */
  471. 1:
  472. # if cond_lock != 0
  473. addq $cond_lock, %rdi
  474. # endif
  475. cmpq $-1, dep_mutex-cond_lock(%rdi)
  476. movl $LLL_PRIVATE, %eax
  477. movl $LLL_SHARED, %esi
  478. cmovne %eax, %esi
  479. callq __lll_lock_wait
  480. jmp 2b
  481. /* Unlock in loop requires wakeup. */
  482. 3:
  483. # if cond_lock != 0
  484. addq $cond_lock, %rdi
  485. # endif
  486. cmpq $-1, dep_mutex-cond_lock(%rdi)
  487. movl $LLL_PRIVATE, %eax
  488. movl $LLL_SHARED, %esi
  489. cmovne %eax, %esi
  490. callq __lll_unlock_wake
  491. jmp 4b
  492. /* Locking in loop failed. */
  493. 5:
  494. # if cond_lock != 0
  495. addq $cond_lock, %rdi
  496. # endif
  497. cmpq $-1, dep_mutex-cond_lock(%rdi)
  498. movl $LLL_PRIVATE, %eax
  499. movl $LLL_SHARED, %esi
  500. cmovne %eax, %esi
  501. callq __lll_lock_wait
  502. # if cond_lock != 0
  503. subq $cond_lock, %rdi
  504. # endif
  505. jmp 6b
  506. # if defined __NR_clock_gettime && !defined __ASSUME_POSIX_TIMERS
  507. /* clock_gettime not available. */
  508. 19: leaq 32(%rsp), %rdi
  509. xorl %esi, %esi
  510. movq $VSYSCALL_ADDR_vgettimeofday, %rax
  511. callq *%rax
  512. /* Compute relative timeout. */
  513. movq 40(%rsp), %rax
  514. movl $1000, %edx
  515. mul %rdx /* Milli seconds to nano seconds. */
  516. movq (%r13), %rcx
  517. movq 8(%r13), %rdx
  518. subq 32(%rsp), %rcx
  519. subq %rax, %rdx
  520. jns 20f
  521. addq $1000000000, %rdx
  522. decq %rcx
  523. 20: testq %rcx, %rcx
  524. movq 8(%rsp), %rdi
  525. movq $-ETIMEDOUT, %r14
  526. js 6b
  527. jmp 21b
  528. # endif
  529. #endif
  530. .size __pthread_cond_timedwait, .-__pthread_cond_timedwait
  531. weak_alias(__pthread_cond_timedwait, pthread_cond_timedwait)
  532. .align 16
  533. .type __condvar_cleanup2, @function
  534. __condvar_cleanup2:
  535. /* Stack frame:
  536. rsp + 72
  537. +--------------------------+
  538. rsp + 64 | %r12 |
  539. +--------------------------+
  540. rsp + 56 | %r13 |
  541. +--------------------------+
  542. rsp + 48 | %r14 |
  543. +--------------------------+
  544. rsp + 24 | unused |
  545. +--------------------------+
  546. rsp + 16 | mutex pointer |
  547. +--------------------------+
  548. rsp + 8 | condvar pointer |
  549. +--------------------------+
  550. rsp + 4 | old broadcast_seq value |
  551. +--------------------------+
  552. rsp + 0 | old cancellation mode |
  553. +--------------------------+
  554. */
  555. movq %rax, 24(%rsp)
  556. /* Get internal lock. */
  557. movq 8(%rsp), %rdi
  558. movl $1, %esi
  559. xorl %eax, %eax
  560. LOCK
  561. #if cond_lock == 0
  562. cmpxchgl %esi, (%rdi)
  563. #else
  564. cmpxchgl %esi, cond_lock(%rdi)
  565. #endif
  566. jz 1f
  567. #if cond_lock != 0
  568. addq $cond_lock, %rdi
  569. #endif
  570. cmpq $-1, dep_mutex-cond_lock(%rdi)
  571. movl $LLL_PRIVATE, %eax
  572. movl $LLL_SHARED, %esi
  573. cmovne %eax, %esi
  574. callq __lll_lock_wait
  575. #if cond_lock != 0
  576. subq $cond_lock, %rdi
  577. #endif
  578. 1: movl broadcast_seq(%rdi), %edx
  579. cmpl 4(%rsp), %edx
  580. jne 3f
  581. /* We increment the wakeup_seq counter only if it is lower than
  582. total_seq. If this is not the case the thread was woken and
  583. then canceled. In this case we ignore the signal. */
  584. movq total_seq(%rdi), %rax
  585. cmpq wakeup_seq(%rdi), %rax
  586. jbe 6f
  587. incq wakeup_seq(%rdi)
  588. incl cond_futex(%rdi)
  589. 6: incq woken_seq(%rdi)
  590. 3: subl $(1 << nwaiters_shift), cond_nwaiters(%rdi)
  591. /* Wake up a thread which wants to destroy the condvar object. */
  592. xorq %r12, %r12
  593. cmpq $0xffffffffffffffff, total_seq(%rdi)
  594. jne 4f
  595. movl cond_nwaiters(%rdi), %eax
  596. andl $~((1 << nwaiters_shift) - 1), %eax
  597. jne 4f
  598. cmpq $-1, dep_mutex(%rdi)
  599. leaq cond_nwaiters(%rdi), %rdi
  600. movl $1, %edx
  601. #ifdef __ASSUME_PRIVATE_FUTEX
  602. movl $FUTEX_WAKE, %eax
  603. movl $(FUTEX_WAKE|FUTEX_PRIVATE_FLAG), %esi
  604. cmove %eax, %esi
  605. #else
  606. movl $0, %eax
  607. movl %fs:PRIVATE_FUTEX, %esi
  608. cmove %eax, %esi
  609. orl $FUTEX_WAKE, %esi
  610. #endif
  611. movl $SYS_futex, %eax
  612. syscall
  613. subq $cond_nwaiters, %rdi
  614. movl $1, %r12d
  615. 4: LOCK
  616. #if cond_lock == 0
  617. decl (%rdi)
  618. #else
  619. decl cond_lock(%rdi)
  620. #endif
  621. je 2f
  622. #if cond_lock != 0
  623. addq $cond_lock, %rdi
  624. #endif
  625. cmpq $-1, dep_mutex-cond_lock(%rdi)
  626. movl $LLL_PRIVATE, %eax
  627. movl $LLL_SHARED, %esi
  628. cmovne %eax, %esi
  629. callq __lll_unlock_wake
  630. /* Wake up all waiters to make sure no signal gets lost. */
  631. 2: testq %r12, %r12
  632. jnz 5f
  633. addq $cond_futex, %rdi
  634. cmpq $-1, dep_mutex-cond_futex(%rdi)
  635. movl $0x7fffffff, %edx
  636. #ifdef __ASSUME_PRIVATE_FUTEX
  637. movl $FUTEX_WAKE, %eax
  638. movl $(FUTEX_WAKE|FUTEX_PRIVATE_FLAG), %esi
  639. cmove %eax, %esi
  640. #else
  641. movl $0, %eax
  642. movl %fs:PRIVATE_FUTEX, %esi
  643. cmove %eax, %esi
  644. orl $FUTEX_WAKE, %esi
  645. #endif
  646. movl $SYS_futex, %eax
  647. syscall
  648. 5: movq 16(%rsp), %rdi
  649. callq __pthread_mutex_cond_lock
  650. movq 24(%rsp), %rdi
  651. movq FRAME_SIZE(%rsp), %r15
  652. movq FRAME_SIZE+8(%rsp), %r14
  653. movq FRAME_SIZE+16(%rsp), %r13
  654. movq FRAME_SIZE+24(%rsp), %r12
  655. .LcallUR:
  656. call _Unwind_Resume@PLT
  657. hlt
  658. .LENDCODE:
  659. cfi_endproc
  660. .size __condvar_cleanup2, .-__condvar_cleanup2
  661. .section .gcc_except_table,"a",@progbits
  662. .LexceptSTART:
  663. .byte DW_EH_PE_omit # @LPStart format
  664. .byte DW_EH_PE_omit # @TType format
  665. .byte DW_EH_PE_uleb128 # call-site format
  666. .uleb128 .Lcstend-.Lcstbegin
  667. .Lcstbegin:
  668. .uleb128 .LcleanupSTART1-.LSTARTCODE
  669. .uleb128 .LcleanupEND1-.LcleanupSTART1
  670. .uleb128 __condvar_cleanup2-.LSTARTCODE
  671. .uleb128 0
  672. #ifndef __ASSUME_FUTEX_CLOCK_REALTIME
  673. .uleb128 .LcleanupSTART2-.LSTARTCODE
  674. .uleb128 .LcleanupEND2-.LcleanupSTART2
  675. .uleb128 __condvar_cleanup2-.LSTARTCODE
  676. .uleb128 0
  677. #endif
  678. .uleb128 .LcallUR-.LSTARTCODE
  679. .uleb128 .LENDCODE-.LcallUR
  680. .uleb128 0
  681. .uleb128 0
  682. .Lcstend:
  683. #ifdef SHARED
  684. .hidden DW.ref.__gcc_personality_v0
  685. .weak DW.ref.__gcc_personality_v0
  686. .section .gnu.linkonce.d.DW.ref.__gcc_personality_v0,"aw",@progbits
  687. .align 8
  688. .type DW.ref.__gcc_personality_v0, @object
  689. .size DW.ref.__gcc_personality_v0, 8
  690. DW.ref.__gcc_personality_v0:
  691. .quad __gcc_personality_v0
  692. #endif