pthread_cond_timedwait.S 16 KB

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