From 3f9d203bcee816fe6c840d41f906979ee0b4f45d Mon Sep 17 00:00:00 2001
From: Glauber Costa <glommer@cloudius-systems.com>
Date: Mon, 26 May 2014 17:51:08 +0400
Subject: [PATCH] pthread: implement sem_destroy

Note that we don't allocate memory in sem_init: we are using placement new to
just construct the object over an already existing memory location. Therefore,
all we need to do is release our unique_ptr

Thanks Pawel for noticing we need to release memory of the internal semaphore

Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
---
 libc/sem.cc | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/libc/sem.cc b/libc/sem.cc
index 6801f8ef8..dcc10d885 100644
--- a/libc/sem.cc
+++ b/libc/sem.cc
@@ -29,6 +29,12 @@ int sem_init(sem_t* s, int pshared, unsigned val)
     return 0;
 }
 
+int sem_destroy(sem_t *s)
+{
+    from_libc(s).~indirect_semaphore();
+    return 0;
+}
+
 int sem_post(sem_t* s)
 {
     from_libc(s)->post();
-- 
GitLab