için bir iş parçacığı güvenli C++ sarmalayıcısı yazmak için çaba harcamamıştım. API, kendiliğinden iş parçacığı için güvenli DEĞİL ise, C API 'thread-safe' C++ sarmalayıcı yazıyorum. RAII'yi kullanmaya çalıştım.C API
Bilmek istiyorum, uygulamam doğru mu? ve iş parçacığı güvenli olsun. Kodumdaki tüm yorumları takdir ediyorum. Şimdiden teşekkürler! aşağıdaki gibi
C API'sıdır sarılacak olan aşağıdaki şekilde sargının
/* an data structure which represents a connection proxy to the logger: */
struct cLog_Logger;
/* connect the logger, and returns a handle to it: */
cLog_Logger* cLog_connect();
/* appends a zero terminated string to the log: */
void cLog_write(cLog_Logger* logger, const char* message);
/* closes the connection with the logger: */
void cLog_close(cLog_Logger* logger);
Benim uygulamasıdır:
class LoggerWrapper{
public:
LoggerWrapper(){ //constructor
cLog= cLog_connect();
}
void log(const std::string &message){ //entry point
cLog_write(cLog, message);
cLog_close(cLog);
}
~LoggerWrapper(){ //destructor
delete cLog;
}
protected:
cLog_Logger *cLog;
}
Teşekkür! Bu veriyor
class LoggerWrapper{
public:
LoggerWrapper(){ //constructor
cLog= cLog_connect();
}
void log(const std::string &message){ //entry point
cLog_write(cLog, message);
}
~LoggerWrapper(){ //destructor
cLog_close(cLog);
delete cLog;
}
protected:
cLog_Logger *cLog;
} ;
böyle kod yazmak:
Konular nerededir? – Ajay
@Ajay, Threads'ın dışındaki her yer sarıcı :) – user2807083