[haiku-commits] r34489 - in haiku/trunk/src/libs/compat/freebsd_network: . compat/sys

  • From: coling@xxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Fri, 4 Dec 2009 14:10:23 +0100 (CET)

Author: colin
Date: 2009-12-04 14:10:23 +0100 (Fri, 04 Dec 2009)
New Revision: 34489
Changeset: http://dev.haiku-os.org/changeset/34489/haiku

Modified:
   haiku/trunk/src/libs/compat/freebsd_network/Condvar.cpp
   haiku/trunk/src/libs/compat/freebsd_network/Condvar.h
   haiku/trunk/src/libs/compat/freebsd_network/Jamfile
   haiku/trunk/src/libs/compat/freebsd_network/compat/sys/condvar.h
Log:
Making use of the C++ structures in C only code feature introduced with
r34441. This allows to completely stick to FreeBSD's conditional cv_* function
semantics as 'struct cv' variables are freed automatically now.
This also gets rid of the dynamically de-/allocating of ConditionalVariables.
Thank you Ingo for helping me through this.


Modified: haiku/trunk/src/libs/compat/freebsd_network/Condvar.cpp
===================================================================
--- haiku/trunk/src/libs/compat/freebsd_network/Condvar.cpp     2009-12-04 
12:13:11 UTC (rev 34488)
+++ haiku/trunk/src/libs/compat/freebsd_network/Condvar.cpp     2009-12-04 
13:10:23 UTC (rev 34489)
@@ -11,8 +11,6 @@
 
 #include <new>
 
-#include <condition_variable.h>
-
 #include "Condvar.h"
 #include "device.h"
 
@@ -23,8 +21,7 @@
 void
 conditionInit(struct cv* variable, const char* description)
 {
-       variable->condition = new(std::nothrow) ConditionVariable();
-       variable->condition->Init(variable, description);
+       variable->condition.Init(variable, description);
 }
 
 
@@ -32,23 +29,21 @@
 conditionPublish(struct cv* variable, const void* waitChannel, 
        const char* description)
 {
-       variable->condition = new(std::nothrow) ConditionVariable();
-       variable->condition->Publish(waitChannel, description);
+       variable->condition.Publish(waitChannel, description);
 }
 
 
 void
-conditionUnpublish(const struct cv* variable)
+conditionUnpublish(struct cv* variable)
 {
-       variable->condition->Unpublish();
-       delete variable->condition;
+       variable->condition.Unpublish();
 }
 
 
 int
-conditionTimedWait(const struct cv* variable, const int timeout)
+conditionTimedWait(struct cv* variable, const int timeout)
 {
-       status_t status = variable->condition->Wait(B_RELATIVE_TIMEOUT,
+       status_t status = variable->condition.Wait(B_RELATIVE_TIMEOUT,
                ticks_to_usecs(timeout));
 
        if (status != B_OK)
@@ -58,16 +53,16 @@
 
 
 void
-conditionWait(const struct cv* variable)
+conditionWait(struct cv* variable)
 {
-       variable->condition->Wait();
+       variable->condition.Wait();
 }
 
 
 void
-conditionNotifyOne(const struct cv* variable)
+conditionNotifyOne(struct cv* variable)
 {
-       variable->condition->NotifyOne();
+       variable->condition.NotifyOne();
 }
 
 

Modified: haiku/trunk/src/libs/compat/freebsd_network/Condvar.h
===================================================================
--- haiku/trunk/src/libs/compat/freebsd_network/Condvar.h       2009-12-04 
12:13:11 UTC (rev 34488)
+++ haiku/trunk/src/libs/compat/freebsd_network/Condvar.h       2009-12-04 
13:10:23 UTC (rev 34489)
@@ -12,10 +12,10 @@
 
 void conditionInit(struct cv*, const char*);
 void conditionPublish(struct cv*, const void*, const char*);
-void conditionUnpublish(const struct cv*);
-int conditionTimedWait(const struct cv*, const int);
-void conditionWait(const struct cv*);
-void conditionNotifyOne(const struct cv*);
+void conditionUnpublish(struct cv*);
+int conditionTimedWait(struct cv*, const int);
+void conditionWait(struct cv*);
+void conditionNotifyOne(struct cv*);
 int publishedConditionTimedWait(const void*, const int);
 void publishedConditionNotifyAll(const void*);
 

Modified: haiku/trunk/src/libs/compat/freebsd_network/Jamfile
===================================================================
--- haiku/trunk/src/libs/compat/freebsd_network/Jamfile 2009-12-04 12:13:11 UTC 
(rev 34488)
+++ haiku/trunk/src/libs/compat/freebsd_network/Jamfile 2009-12-04 13:10:23 UTC 
(rev 34489)
@@ -6,6 +6,10 @@
 UsePrivateKernelHeaders ;
 UseHeaders $(HAIKU_PRIVATE_KERNEL_HEADERS) : true ;
 
+# Enabling C++ structures in C only code
+Includes [ FGristFiles kernel_c++_structs.h ]
+       : <src!system!kernel>kernel_c++_struct_sizes.h ;
+
 SubDirCcFlags [ FDefines _KERNEL=1 ] ;
 
 KernelStaticLibrary libfreebsd_network.a :

Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/condvar.h
===================================================================
--- haiku/trunk/src/libs/compat/freebsd_network/compat/sys/condvar.h    
2009-12-04 12:13:11 UTC (rev 34488)
+++ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/condvar.h    
2009-12-04 13:10:23 UTC (rev 34489)
@@ -8,9 +8,17 @@
 
 #include <sys/queue.h>
 
+#ifdef __cplusplus
+} /* extern "C" */
+#include <kernel_c++_structs.h>
+extern "C" {
+#else
+#include <kernel_c++_structs.h>
+#endif
 
+
 struct cv {
-       struct ConditionVariable* condition;
+       struct ConditionVariable condition;
 };
 
 


Other related posts:

  • » [haiku-commits] r34489 - in haiku/trunk/src/libs/compat/freebsd_network: . compat/sys - coling